search
HomeWeChat AppletMini Program DevelopmentOne-click login for WeChat applet development to obtain the implementation of session_key and openid

This article mainly introduces the relevant information about WeChat applet development with one-click login to obtain session_key and openid instances. Friends in need can refer to

WeChat applet development with one-click login to obtain session_key and openid instances. openid example

After thinking about it, I don’t want my WeChat applet to be a stand-alone version. I don’t know how to write the backend. Now with the help of leancloud, I can realize the one-click login function of the WeChat applet. After trying it, do Notes.

Step one: Download av-weapp.js and put it under utils.

Step two: Use const AV = require('../../utils/av -weapp.js');The path depends on the specific situation.

The third step: initialization.

AV.init({ 
 appId: 'EJx0NSfY********-gzGzoHsz', 
 appKey: 'FBVPg5G**********T97SNQj', 
 });

Step 4: Obtain the AppID (mini program ID) and AppSecret (mini program key) on the WeChat public platform


Step 5: Configure the AppID on the leancloud console ( Mini Program ID) and AppSecret (Mini Program Key)



##Step Six: User Login

<span style="font-size:24px;">AV.User.loginWithWeapp().then(user => { 
 this.globalData.user = user.toJSON(); 
}).catch(console.error);</span>

After logging in, check the user information on the platform


Get: session_key and openid


Step 7: Get current user information

const user = AV.User.current(); 
// 调用小程序 API,得到用户信息 
wx.getUserInfo({ 
 success: ({userInfo}) => { 
 // 更新当前用户的信息 
 user.set(userInfo).save().then(user => { 
  // 成功,此时可在控制台中看到更新后的用户信息 
  this.globalData.user = user.toJSON(); 
 }).catch(console.error); 
 } 
});

Note:

wx.request() needs to configure a legal domain name, otherwise an error will be reported.

The above is the entire content of this article. I hope it will be helpful to everyone's learning. For more related content, please pay attention to PHP Chinese website!

Related recommendations:

WeChat applet image selection area cropping method

WeChat applet implements city list selection

The above is the detailed content of One-click login for WeChat applet development to obtain the implementation of session_key and openid. 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.