这是云函数
const cloud = require('wx-server-sdk')
cloud.init()
const got = require('got');
exports.main = async (event, context) => {
const code=event.code;
const url='http://localhost:9090/link.php?code='+code;
let getResponse = await got(url)
return getResponse.body
}
这是调用的js:
Btn(){
wx.login({
success (res) {
if (res.code) {
console.log(res.code)
//发起网络请求
var code=res.code
wx.cloud.callFunction({
name:'http',
data:{
code:code
}
}).then(res=>{
console.log(res)
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
},
错误:
Error: cloud.callFunction:fail -404011 cloud function execution error. 云函数执行错误
云端堆栈信息(error stack)(requestId c0f9d766-886c-11eb-b043-525400fff70d, callid 1616128624067-0.8068190962394808):
RequestError: connect ECONNREFUSED 127.0.0.1:9090
在postman等插件中测试该请求是可以返回正确的openid,证明不是服务器端代码的问题,想问下问题是出在哪里。依赖都装好了。