silenceper / wechat

WeChat SDK for Go (微信SDK:简单、易用)
https://silenceper.com/wechat/
Apache License 2.0
4.79k stars 1.08k forks source link

小程序解密好像只能解密用户信息,不能解密手机号 #160

Closed cielu closed 5 years ago

cielu commented 5 years ago

https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html

{
    "phoneNumber": "13580006666",
    "purePhoneNumber": "13580006666",
    "countryCode": "86",
    "watermark":
    {
        "appid":"APPID",
        "timestamp": TIMESTAMP
    }
}
cielu commented 5 years ago

@silenceper 老兄,这个问题修复不?加个手机号解密的,目前小程序只能解密用户的信息

// 用户手机号
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"`
}
    mode := cipher.NewCBCDecrypter(block, ivBytes)
    mode.CryptBlocks(cipherText, cipherText)
    cipherText, err = pkcs7Unpad(cipherText, block.BlockSize())
    if err != nil {
        return nil, err
    }
    var phoneInfo PhoneInfo
    err = json.Unmarshal(cipherText, &phoneInfo)
    if err != nil {
        return nil, err
    }
    if phoneInfo.Watermark.AppID != AppId {
        return nil, errors.New("app id 不匹配")
    }
silenceper commented 5 years ago

fixed #167