微信小程序获取unionid必须首先由用户授权授权代码如下:
var that = this;
// 查看是否授权
wx.getSetting({
success: function (res) {
if (res.authSetting['scope.userInfo']) {
//获取用户信息
console.log("开始获取unionid");
//-----------------------------------------------
wx.login({
success: function (r) {
var code = r.code;//登录凭证
if (code) {
console.log("code"+code);
wx.request({
url: 'http://tv2.51rcc.com/api/login/wx_jscode2session',
data: {
code: code,
},
success:function(res){
console.log(res);
console.log("session_key:"+res.data.data.session_key);
}
})
} else {