Created
October 17, 2013 10:02
-
-
Save xifengzhu/7022296 to your computer and use it in GitHub Desktop.
过百度api定位ip位置
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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