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

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

不言
不言Original
2018-08-16 17:28:324081browse

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) {
            
          }
        })
      }
    })  
  }
})

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!

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