github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/mp/base/getcallbackip.go (about) 1 package base 2 3 import ( 4 "github.com/chanxuehong/wechat/mp/core" 5 ) 6 7 // 获取微信服务器IP地址. 8 // 9 // 如果公众号基于安全等考虑,需要获知微信服务器的IP地址列表,以便进行相关限制,可以通过该接口获得微信服务器IP地址列表。 10 func GetCallbackIP(clt *core.Client) (ipList []string, err error) { 11 const incompleteURL = "https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=" 12 13 var result struct { 14 core.Error 15 List []string `json:"ip_list"` 16 } 17 if err = clt.GetJSON(incompleteURL, &result); err != nil { 18 return 19 } 20 if result.ErrCode != core.ErrCodeOK { 21 err = &result.Error 22 return 23 } 24 ipList = result.List 25 return 26 }