Home > WeChat Applet > Mini Program Development > 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

高洛峰
Release: 2018-05-11 17:08:21
Original
8502 people have browsed it


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  
    });
Copy after login

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!

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