Show button with open-type = getUserInfo
a) Allows you to get user info directly from button, or allows you to call wx.getUserInfo
Re-call wx.login and get code
Call wx.getUserInfo and get iv, encryptedData
Send code, iv, and encryptedData to backend to get user info with session_key from swapping the code
a) iv, encryptedData, and session_key decrypted server-side to return userInfo
Download example decryption code here: https://developers.weixin.qq.com/miniprogram/dev/demo/aes-sample.zip
App onLaunch ->
wx.login
Returns code (backend can return api token)Use code to call https://api.weixin.qq.com/sns/jscode2session?appid=${this.appId}&secret=${this.appSecret}&js_code=${code}&grant_type=authorization_code
Returns openId (unionid too) and session_key
Show button with
open-type = getUserInfo
a) Allows you to get user info directly from button, or allows you to callwx.getUserInfo
Re-call
wx.login
and get codeCall
wx.getUserInfo
and getiv, encryptedData
Send code, iv, and encryptedData to backend to get user info with session_key from swapping the code a) iv, encryptedData, and session_key decrypted server-side to return userInfo Download example decryption code here: https://developers.weixin.qq.com/miniprogram/dev/demo/aes-sample.zip