请求jscode2session 返回的一直是invalid code?
直接上代码
//小程序端
async getUserInfo() {
const that = this
if (that.globalData.userInfo) {
return that.globalData.userInfo
}
var reqLogin = await wepy.login(),
reqGetUserInfo = await wepy.getUserInfo(),
userInfo = reqGetUserInfo.userInfo
console.log('reqLogin',reqLogin)
console.log('reqGetUserInfo',reqGetUserInfo)
var reqOnlogin = await wepy.request({url: `${that.globalData.api.gicWechat}/base/onlogin?weappcode=${reqLogin.code}`}),
json = reqOnlogin.data
console.log('reqOnlogin',reqOnlogin)
if (json.data && json.data.body && json.data.body.sessionKey) {
var pc = new WXBizDataCrypt(Config.weAppId, json.data.body.sessionKey),
userInfo = pc.decryptData(reqGetUserInfo.encryptedData , reqGetUserInfo.iv)
} else {
console.warn('json.data.body',json.data.body)
}
console.log('userInfo',userInfo)
return that.globalData.userInfo = userInfo
}
//服务器端
exports.onlogin = function *(next){
log(logger, `/base/onlogin => onlogin` ,this)
var code = this.query.weappcode
var res = yield superagent.get(`https://api.weixin.qq.com/sns/jscode2session?appid=${wechatOpts.appId}&secret=${wechatOpts.appSecret}&js_code=${code}&grant_type=authorization_code`)
var body
if (res.text) {
body = JSON.parse(res.text)
}
logger.debug(`res: ${JSON.stringify(res)}`)
yield this.body = {
data:{
body : body,
success : true
},
status:{
code : 1,
msg : 'success'
}
}
}
服务器端的 结果一直是invalid code , 求大神指导