Skip to content

Commit 50a4288

Browse files
committed
Update ip.go
1 parent 3c4392a commit 50a4288

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Diff for: sdk/pkg/ip.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,27 @@ func GetLocation(ip, key string) string {
1313
if ip == "127.0.0.1" || ip == "localhost" {
1414
return "内部IP"
1515
}
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)
1719
if err != nil {
1820
panic(err)
1921

2022
}
2123
defer resp.Body.Close()
2224
s, err := ioutil.ReadAll(resp.Body)
23-
fmt.Printf(string(s))
25+
fmt.Println(string(s))
2426

2527
m := make(map[string]string)
2628

2729
err = json.Unmarshal(s, &m)
2830
if err != nil {
2931
fmt.Println("Umarshal failed:", err)
3032
}
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"]
3537
}
3638

3739
// 获取局域网ip地址

0 commit comments

Comments
 (0)