微信小程序获取openid
getCode(){
//获取code
wx.login({
success: (result)=>{
console.log("获取code",result);
if(result.errMsg == 'login:ok'){
this.setData({
code: result.code
});
this.getOpenId();
}else{
wx.showToast({
title: '获取用户code失败',
icon: 'none',
image: '',
duration: 1500,
mask: false,
});
}
},
fail: ()=>{},
complete: ()=>{}
});
},
getOpenId(){
let openIdUrl = 'https://30paotui.com/user/wechat';
let openIdData = {
appid: '小程序appid',
secret: '小程序appsecret',
code: this.data.code
};
app.wxRequest('GET', openIdUrl, openIdData, (res) => {
this.setData({
openid: res.openid
});
console.log("获取到的openid",this.data.openid);
}, (err) => {
console.log(err)
})
},