微信授权登录,本地运行成功,云端运行失败?
错误码errCode: 40013 | errMsg: invalid appid, rid: 624aa747-6fc63992-5aab82ea 检查了我appid和密钥,都没有错误;使用的是uniApp开发,代码如下 //云函数wxLogin
'use strict';
const uniID = require('uni-id')
exports.main = async function(event,context) {
// 如下旧写法依然支持
// const res = await uniID.loginByWeixin(event.code)
const res = await uniID.loginByWeixin({
code: event.code
})
return res
}
//微信授权登录代码
uni.getUserProfile({
desc:"登录注册",
success: (res) => {
const userInfo=res.userInfo
console.log(res)
uni.login({
provider: 'weixin',
success:(res)=>{
console.log(res.code)
uniCloud.callFunction({
name:"wxLogin",
data:{
code:res.code
},
success: (res) => {
console.log(res.result,"登录成功")
const mytoken = res.result.token
uni.setStorageSync('uni_id_token', res.result.token)
uni.setStorageSync('uni_id_token_expired', res.result.tokenExpired)
uniCloud.callFunction({
name:"uploadInfo",
data:{
token:mytoken,
nickname:userInfo.nickName,
avatar:userInfo.avatarUrl
},
success:(res)=> {
uniCloud.callFunction({
name:"getUserInfo",
data:{
token:mytoken
},
success:(res)=>{
that.userInfo=res.result.data[0]
that.status=1
uni.showToast({
title:"登录成功"
})
},
fail: (err) => {
console.log("获取信息失败",err)
}
})
},
fail: (err) => {
console.log("上传信息失败",err)
}
})
},
fail(err) {
console.log("cloudLogin",err)
uni.showToast({
title:"cloudLogin",
icon:"fail"
})
}
})
},
fail: (err) => {
console.log("uni.login登录失败",err)
}
})
},
fail(err) {
console.log(err)
uni.showToast({
title:"授权失败",
icon:"error"
})
}
})uni.getUserProfile({
desc:"登录注册",
success: (res) => {
const userInfo=res.userInfo
console.log(res)
uni.login({
provider: 'weixin',
success:(res)=>{
console.log(res.code)
uniCloud.callFunction({
name:"wxLogin",
data:{
code:res.code
},
success: (res) => {
console.log(res.result,"登录成功")
const mytoken = res.result.token
uni.setStorageSync('uni_id_token', res.result.token)
uni.setStorageSync('uni_id_token_expired', res.result.tokenExpired)
uniCloud.callFunction({
name:"uploadInfo",
data:{
token:mytoken,
nickname:userInfo.nickName,
avatar:userInfo.avatarUrl
},
success:(res)=> {
uniCloud.callFunction({
name:"getUserInfo",
data:{
token:mytoken
},
success:(res)=>{
that.userInfo=res.result.data[0]
that.status=1
uni.showToast({
title:"登录成功"
})
},
fail: (err) => {
console.log("获取信息失败",err)
}
})
},
fail: (err) => {
console.log("上传信息失败",err)
}
})
},
fail(err) {
console.log("cloudLogin",err)
uni.showToast({
title:"cloudLogin",
icon:"fail"
})
}
})
},
fail: (err) => {
console.log("uni.login登录失败",err)
}
})
},
fail(err) {
console.log(err)
uni.showToast({
title:"授权失败",
icon:"error"
})
}
})