Home  >  Article  >  WeChat Applet  >  WeChat applet: case of obtaining session_key and openid (picture)

WeChat applet: case of obtaining session_key and openid (picture)

黄舟
黄舟Original
2018-05-11 14:46:307713browse

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.

WeChat applet: case of obtaining session_key and openid (picture)

Getting process:

1. Find the AppID (mini program ID) and AppSecret (mini program key) on the public platform;
WeChat applet: case of obtaining session_key and openid (picture)

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

WeChat applet: case of obtaining session_key and openid (picture)
You can get openid and session_key by accessing the WeChat server interface in the background

WeChat applet: case of obtaining session_key and openid (picture)

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.

WeChat applet: case of obtaining session_key and openid (picture)

##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!

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