WeChat Mini Program Login

Recap

API:wx.login()

wx.login(Object object), calling this API will return the user login credentials, and the credentials are valid for 5 minutes .
It receives an object as a parameter, which contains the following properties:

  • timeout, timeout period, number type, unit is ms (milliseconds), optional.
  • success, the callback function that the interface calls successfully.
  • fail, the callback function of the failed interface call.
  • complete, the callback function for the end of the interface call (regardless of success or failure).

Timing of Mini Program Login Process

The timing sequence of the applet login process is shown in the following figure.

  1. Call the API: wx.login(), get it 临时登录凭证code, and send it to the developer's background server.
  2. The developer's background server calls the interface: https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=临时登录凭证code&grant_type=authorization_code, that is, sends a request to the WeChat server to obtain the user's unique ID openid.
    • appid, the applet ID. Log in to the WeChat public platform, Home>Development>Development Management>Development Settings, you can get the appid.
    • secret, the applet key. The secret is obtained in the same way as the appid.
    • js_code, calling the temporary login credential code returned by wx.login().

insert image description here

Related Links

[WeChat applet] WeChat login
[WeChat applet] User login
wx.login(Object object)
applet login
auth.code2Session

Guess you like

Origin blog.csdn.net/qzw752890913/article/details/126051192