This article mainly introduces the relevant information about WeChat applet obtaining session_key and openid instances. I hope this article can help everyone realize such a function. Friends who need it can refer to it
Instances of WeChat applet obtaining session_key and openid
Let’s talk about the conditions for obtaining session_key and openid
1.AppID (mini program ID);
2.AppSecret (mini program key);
3. Get the code when logging in;
Note: Even if you get After arriving at the appid, you will not be able to get the code if you have not passed the payment verification.
The printout is like this.
Getting process:
1. Find the AppID (mini program ID) and AppSecret (mini program key) on the public platform;
2. Call the API in the WeChat mini program to obtain the code
wx.login({ success: function(res) { console.log(res.code)//这就是code });
3.code in exchange for session_key and openid
After the user allows login, the callback content will contain the code (valid for five minutes). The developer needs to send the code to the developer server background. Use code in exchange for session_key api, change code into openid and session_key
You can get openid and session_key by accessing the WeChat server interface in the background
The document says that openid or session_key should not be used as user identification;
I won’t bother. Just use openid as the unique identification. There is nothing wrong with it.
Of course You can also generate a session in the background according to the official documentation, using 3rd_session as the key and session_key+ opneid as the value.
##php Chinese network learning topic: php session (including pictures, texts, videos, cases)
The above is the detailed content of WeChat applet: case of obtaining session_key and openid (picture). For more information, please follow other related articles on the PHP Chinese website!