小程序 获取用户的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
}
})
}
});
posted @ 2017-11-07 10:16  ThisCall  阅读(301)  评论(0编辑  收藏  举报