近期偶然微信调试整理 2023-01-29

2023-01-28  本文已影响0人  十二找十三
小程序微信服务端大致配合如下:

1.小程序端 js_code参数获取方式 登录时获取的code,可通过wx.login获取


2.服务端获取 openid 的方式
https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code



3.服务端获取session_key
https://api.weixin.qq.com/cgi-bin/token?appid=wx3238ea2c4f25ca99&secret=ed20d80fb7b1d12f0ef1ae3eb3dbb92a&grant_type=client_credential

{
    "access_token": "65_a0fRxGZFho6GlIDeb7g8tAIyBOjYQgSdQRY5oQk25NK1t8ilnBxxbqLVSLDPxZ1OCO4uAkjNYOnrSBybzpgNsmWDILWEXsz2qMPj5_MnVT5L0nKC10NmvPLE3nMUJYgAHANCR",
    "expires_in": 7200
}

access_token 可以单例创建map cache


4.获取手机号:
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber"></button>

https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=65__kBBCv39UWkm8bIG-UUNLD7hEsyBVLFrIl0YtEbO6Fe4tcplfNVHS13qIfdh2FmK7neDXF9ncWIa0F06RsqAbS_J2MN8Mi8eLtPRuA36SM8RQClhXCpcmCgR7-UECRhAEATRG

{
    "code": "003jAn000nOSlP1Co8400To9oZ0jAn0f"
} 

{
    "errcode": 0,
    "errmsg": "ok",
    "phone_info": {
        "phoneNumber": "15904498178",
        "purePhoneNumber": "15904498178",
        "countryCode": "86",
        "watermark": {
            "timestamp": 1674901635,
            "appid": "wx3238ea2c4f25ca99"
        }
    }
}


上一篇下一篇

猜你喜欢

热点阅读