Skip to content

Instantly share code, notes, and snippets.

@xifengzhu
Created October 17, 2013 10:02
Show Gist options
  • Save xifengzhu/7022296 to your computer and use it in GitHub Desktop.
Save xifengzhu/7022296 to your computer and use it in GitHub Desktop.
过百度api定位ip位置
# encoding : utf-8
require 'net/http'
require 'json'
module IPSearch
def self.ip_query(client_ip)
params = {}
params["ak"] = "9ea9********3800845b2753fa6" #百度的key
params["ip"] = client_ip
uri = URI.parse("http://api.map.baidu.com/location/ip?")
begin
res = Net::HTTP.post_form(uri, params)
JSON.parse(res.body) || {}
rescue Exception => e
{}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment