update service wechat

master
李光春 2 years ago
parent 1ad779f6ce
commit 94407d6ebc

@ -1,16 +1,32 @@
package wechatminiprogram package wechatminiprogram
import "fmt" import (
"encoding/json"
"fmt"
)
type GetCallBackIpResult struct { // GetCallBackIpResponse 返回参数
type GetCallBackIpResponse struct {
IpList []string `json:"ip_list"` IpList []string `json:"ip_list"`
} }
// NewGetCallBackIpResult 构造函数
func NewGetCallBackIpResult(result GetCallBackIpResponse, byte []byte, err error) *Result {
return &Result{
GetCallBackIpResponse: result,
Byte: byte,
Err: err,
}
}
// GetCallBackIp 获取微信callback IP地址 // GetCallBackIp 获取微信callback IP地址
// callback IP即微信调用开发者服务器所使用的出口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 // 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() (body []byte, err error) { func (app *App) GetCallBackIp() *Result {
// 请求 // 请求
body, err = app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=%s", app.AccessToken), map[string]interface{}{}, "GET") body, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=%s", app.AccessToken), map[string]interface{}{}, "GET")
return // 定义
var response GetCallBackIpResponse
err = json.Unmarshal(body, &response)
return NewGetCallBackIpResult(response, body, err)
} }

@ -0,0 +1,8 @@
package wechatminiprogram
// Result 接口
type Result struct {
Byte []byte // 内容
Err error // 错误
GetCallBackIpResponse // IP即微信调用开发者服务器所使用的出口IP
}

@ -1,16 +1,32 @@
package wechatoffice package wechatoffice
import "fmt" import (
"encoding/json"
"fmt"
)
type GetCallBackIpResult struct { // GetCallBackIpResponse 返回参数
type GetCallBackIpResponse struct {
IpList []string `json:"ip_list"` IpList []string `json:"ip_list"`
} }
// NewGetCallBackIpResult 构造函数
func NewGetCallBackIpResult(result GetCallBackIpResponse, byte []byte, err error) *Result {
return &Result{
GetCallBackIpResponse: result,
Byte: byte,
Err: err,
}
}
// GetCallBackIp 获取微信callback IP地址 // GetCallBackIp 获取微信callback IP地址
// callback IP即微信调用开发者服务器所使用的出口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 // 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() (body []byte, err error) { func (app *App) GetCallBackIp() *Result {
// 请求 // 请求
body, err = app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=%s", app.AccessToken), map[string]interface{}{}, "GET") body, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=%s", app.AccessToken), map[string]interface{}{}, "GET")
return // 定义
var response GetCallBackIpResponse
err = json.Unmarshal(body, &response)
return NewGetCallBackIpResult(response, body, err)
} }

@ -0,0 +1,8 @@
package wechatoffice
// Result 接口
type Result struct {
Byte []byte // 内容
Err error // 错误
GetCallBackIpResponse // IP即微信调用开发者服务器所使用的出口IP
}

@ -6,37 +6,31 @@ import (
"net/http" "net/http"
) )
type authGetAccessTokenResult struct { // AuthGetAccessTokenResponse 返回参数
Byte []byte // 内容 type AuthGetAccessTokenResponse struct {
Result authGetAccessTokenResponse // 结果 AccessToken string `json:"access_token"` // 获取到的凭证
Err error // 错误 ExpiresIn int `json:"expires_in"` // 凭证有效时间单位秒。目前是7200秒之内的值
Errcode int `json:"errcode"` // 错误码
Errmsg string `json:"errmsg"` // 错误信息
} }
// NewAuthGetAccessTokenResult 实例化 // NewAuthGetAccessTokenResult 构造函数
func NewAuthGetAccessTokenResult(byte []byte, result authGetAccessTokenResponse, err error) *authGetAccessTokenResult { func NewAuthGetAccessTokenResult(result AuthGetAccessTokenResponse, byte []byte, err error) *Result {
return &authGetAccessTokenResult{ return &Result{
Byte: byte, AuthGetAccessTokenResponse: result,
Result: result, Byte: byte,
Err: err, Err: err,
} }
} }
// AuthGetAccessToken // AuthGetAccessToken
// 接口调用凭证 // 接口调用凭证
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html // https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html
func (app *App) AuthGetAccessToken() *authGetAccessTokenResult { func (app *App) AuthGetAccessToken() *Result {
// 请求 // 请求
body, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", app.AppId, app.AppSecret), map[string]interface{}{}, http.MethodGet) body, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", app.AppId, app.AppSecret), map[string]interface{}{}, http.MethodGet)
// 定义 // 定义
var response authGetAccessTokenResponse var response AuthGetAccessTokenResponse
err = json.Unmarshal(body, &response) err = json.Unmarshal(body, &response)
return NewAuthGetAccessTokenResult(body, response, err) return NewAuthGetAccessTokenResult(response, body, err)
}
// 返回参数
type authGetAccessTokenResponse struct {
AccessToken string `json:"access_token"` // 获取到的凭证
ExpiresIn int `json:"expires_in"` // 凭证有效时间单位秒。目前是7200秒之内的值
Errcode int `json:"errcode"` // 错误码
Errmsg string `json:"errmsg"` // 错误信息
} }

@ -0,0 +1,32 @@
package wechatunion
import (
"encoding/json"
"fmt"
)
// GetCallBackIpResponse 返回参数
type GetCallBackIpResponse struct {
IpList []string `json:"ip_list"`
}
// NewGetCallBackIpResult 构造函数
func NewGetCallBackIpResult(result GetCallBackIpResponse, byte []byte, err error) *Result {
return &Result{
GetCallBackIpResponse: result,
Byte: byte,
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() *Result {
// 请求
body, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=%s", app.AccessToken), map[string]interface{}{}, "GET")
// 定义
var response GetCallBackIpResponse
err = json.Unmarshal(body, &response)
return NewGetCallBackIpResult(response, body, err)
}

@ -0,0 +1,9 @@
package wechatunion
// Result 接口
type Result struct {
Byte []byte // 内容
Err error // 错误
AuthGetAccessTokenResponse // 接口调用凭证
GetCallBackIpResponse // IP即微信调用开发者服务器所使用的出口IP
}
Loading…
Cancel
Save