You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wechatminiprogram/wxa.business.getuserphonenu...

50 lines
2.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package wechatminiprogram
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
"net/http"
)
type WxaBusinessGetUserPhoneNumberResponse struct {
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
PhoneInfo struct {
PhoneNumber string `json:"phoneNumber"` // 用户绑定的手机号(国外手机号会有区号)
PurePhoneNumber string `json:"purePhoneNumber"` // 没有区号的手机号
CountryCode int `json:"countryCode"` // 区号
Watermark struct {
Timestamp int `json:"timestamp"` // 用户获取手机号操作的时间戳
Appid string `json:"appid"` // 小程序appid
} `json:"watermark"`
} `json:"phone_info"`
}
type WxaBusinessGetUserPhoneNumberResult struct {
Result WxaBusinessGetUserPhoneNumberResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
Err error // 错误
}
func newWxaBusinessGetUserPhoneNumberResult(result WxaBusinessGetUserPhoneNumberResponse, body []byte, http gorequest.Response, err error) *WxaBusinessGetUserPhoneNumberResult {
return &WxaBusinessGetUserPhoneNumberResult{Result: result, Body: body, Http: http, Err: err}
}
// WxaBusinessGetUserPhoneNumber code换取用户手机号。 每个code只能使用一次code的有效期为5min
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/phonenumber/phonenumber.getPhoneNumber.html
func (c *Client) WxaBusinessGetUserPhoneNumber(ctx context.Context, code string) *WxaBusinessGetUserPhoneNumberResult {
// 参数
param := gorequest.NewParams()
param.Set("code", code)
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/wxa/business/getuserphonenumber?access_token=%s", c.getAccessToken(ctx)), params, http.MethodPost)
// 定义
var response WxaBusinessGetUserPhoneNumberResponse
err = json.Unmarshal(request.ResponseBody, &response)
return newWxaBusinessGetUserPhoneNumberResult(response, request.ResponseBody, request, err)
}