|
@@ -8,6 +8,7 @@ import (
|
|
|
"github.com/silenceper/wechat/v2/miniprogram/auth"
|
|
|
"github.com/silenceper/wechat/v2/miniprogram/config"
|
|
|
"github.com/silenceper/wechat/v2/miniprogram/encryptor"
|
|
|
+ "github.com/silenceper/wechat/v2/util"
|
|
|
)
|
|
|
|
|
|
//微信小程序配置信息
|
|
@@ -64,18 +65,44 @@ func GetDecryptInfo(sessionKey, encryptedData, iv string) (decryptData *encrypto
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//func GetCode() {
|
|
|
-// codeParms := qrcode.QRCoder{
|
|
|
-// Page: "",
|
|
|
-// Path: "",
|
|
|
-// Width: 0,
|
|
|
-// Scene: "",
|
|
|
-// AutoColor: false,
|
|
|
-// LineColor: qrcode.Color{},
|
|
|
-// IsHyaline: false,
|
|
|
-// }
|
|
|
-// //wxApp := GetWxApp()
|
|
|
-// //qrCode := wxApp.GetQRCode()
|
|
|
-// //qrCode.
|
|
|
-// //qrCode.GetWXACodeUnlimit()
|
|
|
-//}
|
|
|
+// 微信小程序新版code获取手机号
|
|
|
+const (
|
|
|
+ getPhoneNumberURL = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s"
|
|
|
+)
|
|
|
+
|
|
|
+type GetPhoneNumberResponse struct {
|
|
|
+ util.CommonError
|
|
|
+ PhoneInfo PhoneInfo `json:"phone_info"`
|
|
|
+}
|
|
|
+
|
|
|
+type PhoneInfo struct {
|
|
|
+ PhoneNumber string `json:"phoneNumber"` // 用户绑定的手机号
|
|
|
+ PurePhoneNumber string `json:"purePhoneNumber"` // 没有区号的手机号
|
|
|
+ CountryCode string `json:"countryCode"` // 区号
|
|
|
+ WaterMark struct {
|
|
|
+ Timestamp int64 `json:"timestamp"`
|
|
|
+ AppID string `json:"appid"`
|
|
|
+ } `json:"watermark"` // 数据水印
|
|
|
+}
|
|
|
+
|
|
|
+func GetPhoneNumber(code string) (result GetPhoneNumberResponse, err error) {
|
|
|
+ var response []byte
|
|
|
+ var (
|
|
|
+ at string
|
|
|
+ )
|
|
|
+ wechatClient := GetWxApp()
|
|
|
+ authClient := wechatClient.GetAuth()
|
|
|
+ if at, err = authClient.GetAccessToken(); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ body := map[string]interface{}{
|
|
|
+ "code": code,
|
|
|
+ }
|
|
|
+ if response, err = util.PostJSON(fmt.Sprintf(getPhoneNumberURL, at), body); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if err = util.DecodeWithError(response, &result, "phonenumber.getPhoneNumber"); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|