云函数
const uniPush = uniCloud.getPushManager({appId:"xxx"})
exports.main = async (event, context) => {
const body = JSON.parse(event.body || "{}");
if(Array.isArray(body.clientId) && body.clientId.length){
body.clientId.forEach(pushClientId => {
uniPush.sendMessage({
"push_clientid": pushClientId, //填写上一步在uni-app客户端获取到的客户端推送标识push_clientid
"title": body.title,
"content": body.content, // event.body.content,
"force_notification": true, // 在线也提示
"payload": body.payload,
"request_id": body.requestId || context.requestId
})
})
return { code: 200, message: "发送成功" }
}else{
return { code: 2001, message: "参数异常" };
}
}
云函数URL化正常,访问正常,执行消息推送报连接超时
[testUniPush/ac1cd39b1751874604780140337/78ms/ERROR] ConnectionTimeoutError: Connect timeout for 5000ms, POST https://restapi.getui.com/v2/MyHWemPAef78No2Sfrs6hA/auth -2 (connected: false, keepalive socket: false, agent status: {"createSocketCount":1,"createSocketErrorCount":0,"closeSocketCount":1,"errorSocketCount":0,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"sockets":{},"requests":{}}, socketHandledRequests: 1, socketHandledResponses: 0)
headers: {}
at (/code/index.js:33:49878)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7)
请求响应状态: fail
[testUniPush/ac1cd39b1751874604780140337/80ms/ERROR] Error: Client network socket disconnected before secure TLS connection was established, POST https://api-inner.next.bspapp.com/server -1 (connected: true, keepalive socket: false, socketHandledRequests: 1, socketHandledResponses: 0)
headers: {}
at /tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:1580
at processTicksAndRejections (node:internal/process/task_queues:96:5)
请求响应状态: fail
1***@163.com (作者)
必现,问了个推,个推说:超时是云服务器网络或者你们自己网络问题,请到ask论坛咨询;我们的网络没有问题,有日志说明云函数访问没有问题;
2025-07-08 11:46
DCloud_uniCloud_JSON
回复 1***@163.com: 如遇 unicloud 服务空间故障,点击 unicloud web 控制台右上角 紧急报障
2025-07-08 11:51
1***@163.com (作者)
回复 DCloud_uniCloud_JSON: 试了,现在测试用的是免费的云空间,不支持上报
2025-07-08 12:05