上传部署后执行
uniCloud.callFunction({
name: 'addNewsHeNan',
complete(res) {
console.log('结果', res)
}
})
产品分类: uniCloud/App
上传部署后执行
uniCloud.callFunction({
name: 'addNewsHeNan',
complete(res) {
console.log('结果', res)
}
})
得到正确的第三方返回的数据
Error: [addNewsHeNan]: ENOTFOUND:getaddrinfo ENOTFOUND v.api.aa1.cn v.api.aa1.cn:443, GET https:/xxx -1 (connected: false, keepalive socket: false, agent status: {"createSocketCount":1,"createSocketErrorCount":0,"closeSocketCount":0,"errorSocketCount":1,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"sockets":{"xxxx:443:::::::::":1},"requests":{}}, socketHandledRequests: 1, socketHandledResponses: 0)
headers: {}
'use strict';
exports.main = async (event, context) => {
//event为客户端上传的参数
console.log('event : ', event);
const dbJQL = uniCloud.databaseForJQL({
event,
context
});
const page = event.page || 0
const url = "https://xxxxx";
const detail_url = 'https://xxxxxxx'
const res = await uniCloud.httpclient.request(url, {
method: 'GET',
data: {},
contentType: 'json', // 指定以application/json发送data内的数据
dataType: 'json' // 指定返回值为json格式,自动进行parse
});
let listNes = [];
let requests = [];
let lastResult = [];
if(res.status == 200) {
if(res.data.code == 1) {
const tempList = res.data.data;
console.log('tempList', tempList)
for(let i=0;i<tempList.length;i++) {
const item = tempList[i];
const result = await dbJQL.collection("xxx")get();
if(!result.data) {
requests.push({data: item});
};
};
};
};
let promiseRequest = []
for(let i=0;i<requests.length; i++) {
const item = requests[i].data;
const p = new Promise((resolve, reject) => {
resolve(i);
})
promiseRequest.push({item, p})
}
for(let i=0;i<promiseRequest.length;i++) {
const promisea = promiseRequest[i]
const r = await promisea.p
const item = await promisea.item
await new Promise((resolve,reject) => {
setTimeout(() => {
uniCloud.httpclient.request(detail_url, {
method: 'GET',
data: {},
contentType: 'json', // 指定以application/json发送data内的数据
dataType: 'json' // 指定返回值为json格式,自动进行parse
}).then(result => {
if(result.result.data.code == 1) {
const detail = result.result.data.data;
const create_date = new Date(item.ptime).getTime();
console.log("create_date", create_date)
listNes.push({id:item.docid, create_date})
dbJQL.collection("xxx").add({
"docid": item.docid
});
resolve()
}
})
}, 5*1000)
})
}
console.log('执行完毕')
return {res:listNes, msg: '执行完毕'}
};
代码如上,做了延时请求第三方API的处理,本地调试是正常的,但是部署之后报错:
Error: [addNewsHeNan]: ENOTFOUND:getaddrinfo ENOTFOUND v.api.aa1.cn v.api.aa1.cn:443, GET https:/xxx -1 (connected: false, keepalive socket: false, agent status: {"createSocketCount":1,"createSocketErrorCount":0,"closeSocketCount":0,"errorSocketCount":1,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"sockets":{"xxxx:443:::::::::":1},"requests":{}}, socketHandledRequests: 1, socketHandledResponses: 0)
headers: {}
xxxx代表请求域名
这个问题困扰两天了,希望能得到官方解答!!!!
3 个回复
7***@qq.com (作者)
在我编写云函数代码时,无意间引入了一个 inport resolve form 'dns';
后来看到后就删掉了,但是不确定是否因为引入这个之后所导致的,
报错信息里有这样一段 GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
如果是这个原因,该怎么解决呢?
DCloud_uniCloud_CRL
域名解析了吗?
7***@qq.com (作者)
解析了的
2022-11-30 11:07
wenxr
解决了吗?我也遇到了同样的问题