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!