One-click login for WeChat applet development to obtain the implementation of session_key and openid

不言
Release: 2018-06-23 15:58:27
Original
7753 people have browsed it

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

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>
Copy after login

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

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!