How does the applet get the user's openid, unique, like WeChat

How does the applet get the user's openid, unique, like WeChat

 

wx.getUserInfo(OBJECT) can only get nickName, avatarUrl, gender, these

A: openid two ways.

1. Login to get the code. Exchange code for openid and a key

2.userinfo has encrypted data. Decrypt to get openid

  1.   onLoad: function () {
  2.     var that = this
  3.     wx.login({
  4.       success: function (res) {
  5.         console.log("res.code====="+res.code);
  6.         if (res.code) {
  7.           //Initiate a network request
  8.           wx.request({
  9.             url: 'https://api.weixin.qq.com/sns/jscode2session?appid=wxaasdf22we1sdffe3&secret=83ebdsdfsdfa7sdfsdf3448ff3f71&js_code=' + res.code + '&grant_type=authorization_code',
  10.             method: "POST",
  11.             success: function (res) {
  12.                
  13.               that.setData({
  14.                 openid: res.data.openid
  15.               })
  16.             }
  17.           })
  18.         } else {
  19.           console.log('Failed to get user login status!' + res.errMsg)
  20.         }
  21.       }
  22.     });
  23.   }
copy code

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326222051&siteId=291194637