微信小程序登录流程

一、微信接口

GET https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code
文档: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html

 

二、获取openId

1. 前端通过 wx.login 接口获得临时登录凭证 code

2. 服务端调用微信code2Session接口,使用前端传入的参数jscode,后台使用配置好的appid和secret请求微信接口

3. 此时一定会拿到openId,但不一定能拿到unionId和session_key

unionId机制说明文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/union-id.html

 

 

三、获取unionId和头像昵称

1. 用户授权后,再次调用该微信接口,可以获取unionId和session_key

2. 前端传入encryData加密数据和iv,服务端使用session_key和iv,解密前端传过来的加密数据,得到头像、昵称

文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html

 

 

 

 

 

 

 

posted @ 2021-01-19 11:49  牧云文仔  阅读(713)  评论(0编辑  收藏  举报