// 云函数代码
"use strict";
const uniPush = uniCloud.getPushManager({ appId: "__UNI__6687A33" }); // 注意这里需要传入你的应用appId
exports.main = async(event, context) => {
let bodyData = {};
let err;
try {
bodyData = JSON.parse(event.body);
} catch (e) {
err = e;
return {
success: false,
msg: err
};
}
if (bodyData.clientid && bodyData.clientid) {
return await uniPush.sendMessage({
force_notification: true,
push_clientid: bodyData.clientid, // 填写上一步在uni-app客户端获取到的客户端推送标识push_clientid
title: bodyData.title,
content: bodyData.content,
payload: {
path: bodyData.path,
title: bodyData.title,
content: bodyData.content,
text: bodyData.content
}
});
} else {
return {
success: false,
msg: "错误参数"
};
}
};
测试的请求地址
https://fc-mp-42de00e0-acb2-4b56-a9fc-aa6913f7afa8.next.bspapp.com/push
请求参数
{
"path": "pages/personalSon/SetInfo",
"title": "title",
"content": "content",
"text": "content",
"clientid": "47782690c680351efa7c91b5f31e42d5"
}
用这个cid在故障排查推送成功
但是直接发送请求报
{
"success": false,
"error": {
"code": "FunctionBizError",
"message": "InternalError:The request processing has failed due to some unknown error."
}
}
[push/ac1cc2ff1673237222136196982/61ms/ERROR] The request processing has failed due to some unknown error.
Error: The request processing has failed due to some unknown error.
at e.then.catch.e (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:1347)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
请求响应状态: fail
阿源叔叔 (作者)
[push/ac1cc2ff1673237222136196982/61ms/ERROR] The request processing has failed due to some unknown error.
Error: The request processing has failed due to some unknown error.
at e.then.catch.e (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:1347)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
请求响应状态: fail
看unicloud后台日志就只有这个
2023-01-09 13:49