dcsan / OpenMpTools

helpful tools for wechat MiniProgram development
4 stars 0 forks source link

handle login process #5

Open dcsan opened 6 years ago

dcsan commented 6 years ago
  1. App onLaunch -> wx.login Returns code (backend can return api token)

  2. 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

  1. Show button with open-type = getUserInfo a) Allows you to get user info directly from button, or allows you to call wx.getUserInfo

  2. Re-call wx.login and get code

  3. Call wx.getUserInfo and get iv, encryptedData

  4. 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

dcsan commented 6 years ago

refs https://developers.weixin.qq.com/miniprogram/dev/api/api-login.html

dcsan commented 6 years ago

Wasin blog https://mp.weixin.qq.com/s/CvekV_sd6tMjBjRfAS2hLQ

dcsan commented 6 years ago

https://mp.weixin.qq.com/s?__biz=MjM5NTE4Njc4NQ==&mid=2657615643&idx=1&sn=c29f2bf4a8d24167aed1982bcd396e8d&chksm=bd6f0e158a188703f87decbb9b5715aff511123a272d5b0e62dd4600ead361aa69c0346e5a11&mpshare=1&scene=1&srcid=0423zuCOSxjfS2irSyIhKUQG&key=e4e373453997291f91c1b3910f66692acef5375c0228f2f1fd0aa47c9cc2e3c2485b55bff7418ea2662a941d29faf91b4258acc0a8b0b23b6085190619a2110b19c9ba7b953e54587e73d9b8ecaea7b8&ascene=0&uin=MTIxNDQ3MDU0MA%3D%3D&devicetype=iMac+MacBookPro12%2C1+OSX+OSX+10.12.3+build(16D32)&version=12020810&nettype=WIFI&lang=zh_CN&fontScale=100&pass_ticket=QiNpjKr%2BL%2Bsugvu3orNxnHGm9eS4tRdjci2X%2BE%2BLN9ZrC7XGCaEb%2Bt36fg1SLYsl

dcsan commented 6 years ago

WX announcement of API change https://developers.weixin.qq.com/blogdetail?action=get_post_info&lang=zh_CN&token=&docid=000aee01f98fc0cbd4b6ce43b56c01