Talk about the conditions for obtaining session_key and openid
1.AppID (mini program ID), which needs to be authenticated through WeChat ;
2.AppSecret (mini program key);
3. Obtain code when logging in;
Note: Even if you obtain the appid, you cannot get the code without passing WeChat authentication.
The printout is like this.
Acquisition process:
1. Find the AppID (mini program ID) and AppSecret (mini program key) on the public platform;
2. Call API in WeChat applet to obtain code
wx.login({ success: function(res) { console.log(res.code) //这就是code });
3.code in exchange for session_key and openid
User permission After logging in, the callback content will contain a code (valid for five minutes). The developer needs to send the code to the developer server backend, use the code in exchange for session_key api, and replace the code with openid and session_key
Backend Access the WeChat serverInterfaceYou can get openid and session_key
The document says that openid or session_key should not be used as user ID;
I don’t It’s a hassle. Just use openid as the unique identifier. There’s nothing wrong with it.
Of course, you can also follow the official documentation and generate a session in the background, using 3rd_session as the key and session_key+ opneid as the value.
The above is the detailed content of Introduction to how to obtain the parameters openid & session_key in the mini program. For more information, please follow other related articles on the PHP Chinese website!