-
Notifications
You must be signed in to change notification settings - Fork 3
/
getcallbackip.go
33 lines (28 loc) · 1.12 KB
/
getcallbackip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package wechatoffice
import (
"encoding/json"
"fmt"
"net/http"
)
type GetCallBackIpResponse struct {
IpList []string `json:"ip_list"`
}
type GetCallBackIpResult struct {
Result GetCallBackIpResponse // 结果
Body []byte // 内容
Err error // 错误
}
func NewGetCallBackIpResult(result GetCallBackIpResponse, body []byte, err error) *GetCallBackIpResult {
return &GetCallBackIpResult{Result: result, Body: body, Err: err}
}
// GetCallBackIp 获取微信callback IP地址
// callback IP即微信调用开发者服务器所使用的出口IP。
// https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_the_WeChat_server_IP_address.html#2.%20%E8%8E%B7%E5%8F%96%E5%BE%AE%E4%BF%A1callback%20IP%E5%9C%B0%E5%9D%80
func (app *App) GetCallBackIp() *GetCallBackIpResult {
// 请求
body, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=%s", app.AccessToken), map[string]interface{}{}, http.MethodGet)
// 定义
var response GetCallBackIpResponse
err = json.Unmarshal(body, &response)
return NewGetCallBackIpResult(response, body, err)
}