客户端代码:
wx.login({
success (res) {
if (res.code) {
//console.log(res.code)
//发起网络请求
wx.request({
url: 'http://www.服务器域名:8080/user/getopenid',
header: {
'content-type': 'application/x-www-form-urlencoded' // 默认值
},
method:"POST",
data: {
code: res.code
},
success(res){
//解析用户信息
var my = getUserInfoByHtml(res.data.replaceAll(""","\"").replaceAll("'","\'"))
console.log(my)
my = JSON.parse(my.replaceAll(" ",""))
my.place = my.place.replaceAll("\'","").replaceAll("[","").replaceAll("]","")
if(my.power != 0){
that.UpdateShowList(my)
}
wx.setStorage({
key:'myinfo',
data:my
})
that.setData({
bannerData:that.data.bannerData,
myInfo : my
})
},
fail(res){
console.log(res)
}
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
在接口测试过程结果已经获取
报错情况
ping下域名看看返回是否正常,提示看是域名解析问题
把域名修改成IP地址后报错消失