微信小程序用户信息解密

文章不是很全面,只是截取了项目内容的一部分,不明白的地方可以私信。

当初之所以要去解密用户数据,只是为了拿到unionId,说来奇怪,其实微信的登录凭证校验接口(https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code)回参中有unionId,但是在实际的情况中,回参中并没有这个值,无奈只能通过解密用户数据来拿到这个值。

流程是这样的:小程序首先通过wx.login()获取临时登录凭证code,iv,encryptedData——>调用应用后台,调用微信登录凭证校验接口获取session_key——>根据iv,encryptedData,session_key解密用户数据。

https://developers.weixin.qq.com/miniprogram/dev/api/open.html(微信小程序获取用户信息接口api)

https://developers.weixin.qq.com/miniprogram/dev/api/api-login.html(微信小程序获取登录信息接口api)


猜你喜欢

转载自blog.csdn.net/u011063151/article/details/80486777
今日推荐