Quest Mini Program (3): Login

Login process (official icon):

 

Proceed as follows:
(1) Call the wx.login() method to obtain the gift login code, and then send the code to the applet background server
(2) The backend server of the applet calls the login credential verification interface (requires appid+appsecret+code), that is, tells WeChat who has logged in to which applet (because you have just issued a temporary login credential to the user, you are now Which temporary login credentials come to me to ask for someone I know for sure)
The interface address is
 
(3) The WeChat server returns session_key and openid to the applet background server
session_key: used for encryption and decryption of sensitive information (session key)
openid: is the user's (user unique identifier)
(4) Do not return openid and session_key directly from the applet background to the applet, you can return a custom login state (such as storing the correspondence between the custom login state and openid+sessioId in redis)
(5) When wx.request() requests, as long as you bring the key, you can query the corresponding value from the background redis, so as to decrypt or query sensitive information according to the value.
Notice:
The session_key will be invalid. WeChat does not tell you how long it will expire. You can use the wx.checkSession() method to check whether the user's current session_key is valid.
The official example is as follows:
wx.checkSession({
  success: function(){
    //session_key 未过期,并且在本生命周期一直有效
  },
  fail: function(){
    // session_key 已经失效,需要重新执行登录流程
    wx.login() //重新登录
    ....
  }
})

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325897623&siteId=291194637