WeChat applet example: How to get the user's openid (with code)

不言
Release: 2018-08-16 17:28:32
Original
4080 people have browsed it

The content of this article is about the WeChat applet example: how to obtain the user's openid (with code). It has certain reference value. Friends in need can refer to it. I hope It will help you.

openid is the user’s unique identifier in the mini program. The method of obtaining it is as follows:

Mini program operation: app.js

App({
   onLaunch: function () {
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        wx.request({
          url: '后台接口',
          data: {
            code: res.code
          },
          success: function (res) {
           
          },
          fail: function (err) {
            
          }
        })
      }
    })  
  }
})
Copy after login

Background operation:

For detailed operations, please see the official documentation

Related recommendations:

WeChat Mini Program Example: How to get the nickname of the avatar through code

Detailed analysis of variables and scope of WeChat applet

The above is the detailed content of WeChat applet example: How to get the user's openid (with code). 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!