<button open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo" class="cu-btn round bg-green shadow lg">登录</button>
bindGetUserInfo: function (e) {
if(!this.data.readed){
wx.showToast({
icon:"none",
title: '请先阅读用户协议',
})
return
}
if (!e.detail.userInfo) {
return;
}
wx.setStorageSync('userInfo', e.detail.userInfo)
this.login(e.detail);
},
login: function (detail) {
var requestUrl = app.globalData.baseUrl
let that = this;
this.setData({
loadModal: true
})
wx.login({
success: function (res) {
wx.request({
url: requestUrl + '/wx/user/'+app.globalData.appkey+'/login',
method: "POST",
header:{
"Content-Type": "application/json"
},
data: {
code: res.code,
encryptedData: detail.encryptedData,
signature:detail.signature,
rawData:detail.rawData,
encryptedData:detail.encryptedData,
iv:detail.iv
},
success: function (res) {
that.setData({
loadModal: false
})
if(res && res.data && res.data.success){
//成功后续代码
}else{
}
}
})
}
})
},
第一次大概率返回报错:
Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
再点击又直接成功了
你好,请问你后面是怎么解决的呢
https://developers.weixin.qq.com/community/develop/doc/00022c683e8a80b29bed2142b56c01
建议调用接口前先把所有接口传的变量都打印以下 包括 请求地址里的变量 应该是同步和异步的问题 要保证所有变量都有值了之后再去登录