WeChat Mini Program Login Process Detailed Introduction

高洛峰
Release: 2017-02-15 11:38:50
Original
2653 people have browsed it

This article mainly introduces relevant information about the detailed introduction of the WeChat Mini Program login process. Friends who need it can refer to

WeChat Mini Program Login Process

1: What are session_key and openId? session_key

The official description is:

session_key is the key generated by the WeChat server for encrypting and signing user data

The purpose of session_key

(1) Decrypt the "ciphertext in user information" obtained through the wx.getUserInfo() interface.
(2) "Process it slightly" and use it to maintain the login state of the applet.

"A little processing" is roughly as follows:

(1) Generate a random number (officially called it 3rd_session)
(2) Treat this random number as The key of session, session_key + openid is value.

That is: session[3rd_session]=session_key+openid

openIdopenId: the user’s unique identifier

That is: each WeChat user in your mini program unique identifier.

微信小程序 登陆流程详细介绍

2: How to obtain session_key and openId. The official HTTP interface is provided:

https://api.weixin .qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code

Getting steps:

(1) Get appid, secret, js_code
(2 ) Replace the APPID, SECRET, and JSCODE of the above interface address with appid, secret, and js_code respectively. Leave the others unchanged and assemble them into a complete address.

For example:

微信小程序 登陆流程详细介绍

3: In "Open this address in the browser" or "Simulate the browser in the background" GET execute this address" can return the following JSON data (including openid, sessionkey)

WeChat applet obtains session_key and openId (encryption, decryption, signature series)

Summary: From It can be seen from steps 1, 2 and 3 that as long as the appid, secret and js_code are obtained, the session_key and openId can be obtained

微信小程序 登陆流程详细介绍

##4: Obtaining the appid and secret

appid is the mini program ID


secret is the mini program key (AppSecret)


How to obtain: mini program background login URL: https ://mp.weixin.qq.com/

After opening the mini program backend URL, registering, and logging in, you can find your AppID and AppSecret as shown in the figure below.

The WeChat mini program obtains session_key and openId (encryption, decryption, signature series)

Note: Currently, individuals cannot register for the mini program, and the scope of open registration is: enterprises, governments, media, and other organizations; of course, use This way, individuals can also register.


Portal: http://www.wxapp-union.com/forum.php?mod=viewthread&tid=495

5: How to get js_code to call wx. The login() interface can obtain the login credentials (js_code)

WeChat applet obtains session_key and openId (encryption, decryption, signature series)

微信小程序 登陆流程详细介绍

6: Summarize the entire session_key acquisition process

(1) Register the WeChat applet, log in to the background and obtain the appId and secret (key) in the settings

(2) Call wx. The login() interface obtains the login credentials js_code
(3) Calls the wx.request() interface to send the js_code to the server background
(4) In the server background, the appId, secret, and js_code

are known

Then call the following official http interface to get openId and session_key

The official http interface address is:


https://api.weixin. qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code

Thank you for reading, I hope it can help everyone, thank you for your support of this site!

For more WeChat mini programs and detailed introduction to the login process, please pay attention to the PHP Chinese website for related articles!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template