{
wx.login({
success: res => {
let d = {
appid: 'wx111111111111', // 從微信公眾平臺開發(fā)設(shè)置中獲取
secret: 'sec2222222222' // 從微信公眾平臺開發(fā)設(shè)置中獲取
};
// 微信官方的獲取openid的接口
var wxLoginUrl = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + d.appid +'&secret='
+ d.secret + '&js_code=' + res.code + '&grant_type=authorization_code';
wx.request({
url: wxLoginUrl,
data: {},
method: 'GET',
success: res => {
let openid = res.data.openid;
this.judgeIsWxlogin(openid); // 向后端發(fā)送openid判斷是否可以直接用該微信號登陸
}
});
}
});
}
從微信公眾平臺開發(fā)設(shè)置中獲取appid和secret: