File tree 1 file changed +8
-6
lines changed
1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -13,25 +13,27 @@ func GetLocation(ip, key string) string {
13
13
if ip == "127.0.0.1" || ip == "localhost" {
14
14
return "内部IP"
15
15
}
16
- resp , err := http .Get ("https://restapi.amap.com/v3/ip?ip=" + ip + "&key=key" )
16
+ url := "https://restapi.amap.com/v5/ip?ip=" + ip + "&type=4&key=" + key
17
+ fmt .Println ("url" ,url )
18
+ resp , err := http .Get (url )
17
19
if err != nil {
18
20
panic (err )
19
21
20
22
}
21
23
defer resp .Body .Close ()
22
24
s , err := ioutil .ReadAll (resp .Body )
23
- fmt .Printf (string (s ))
25
+ fmt .Println (string (s ))
24
26
25
27
m := make (map [string ]string )
26
28
27
29
err = json .Unmarshal (s , & m )
28
30
if err != nil {
29
31
fmt .Println ("Umarshal failed:" , err )
30
32
}
31
- if m ["province" ] == "" {
32
- return "未知位置"
33
- }
34
- return m ["province" ] + "-" + m ["city" ]
33
+ // if m["province"] == "" {
34
+ // return "未知位置"
35
+ // }
36
+ return m ["country" ] + "-" + m [ " province" ] + "-" + m ["city" ] + "-" + m [ "district" ] + "-" + m [ "isp " ]
35
37
}
36
38
37
39
// 获取局域网ip地址
You can’t perform that action at this time.
0 commit comments