Home  >  Article  >  WeChat Applet  >  Introduction to how to obtain the parameters openid & session_key in the mini program

Introduction to how to obtain the parameters openid & session_key in the mini program

高洛峰
高洛峰Original
2018-05-11 17:08:218464browse


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.

小程序中如何获取参数openid & session_key的方法介绍

Acquisition process:
1. Find the AppID (mini program ID) and AppSecret (mini program key) on the public platform;

小程序中如何获取参数openid & session_key的方法介绍

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 小程序中如何获取参数openid & session_key的方法介绍

Backend Access the WeChat serverInterfaceYou can get openid and session_key

小程序中如何获取参数openid & 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.

小程序中如何获取参数openid & session_key的方法介绍

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!

Statement:
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