小程序 获取用户的openid
wx.login({ success: res => { var code = res.code; //返回code // 小程序appid var appId = 'wxd751fc845c90fbd8'; // 小程序密钥 var secret = '6af97b8d384a4c6d7028b77784de997a'; wx.request({ url: 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appId + '&secret=' + secret + '&js_code=' + code + '&grant_type=authorization_code', data: {}, header: { 'content-type': 'json' }, success: function (res) { // console.log(res) var openid = res.data.openid // console.log(openid) that.globalData.userId = openid } }) } }); 来源: https://www.cnblogs.com/dianzan/p/7797722.html