增加 unipush2.0
This commit is contained in:
@@ -1,32 +1,46 @@
|
||||
// 'use strict';
|
||||
// exports.main = async (event, context) => {
|
||||
// //event为客户端上传的参数
|
||||
// console.log('event : ', event)
|
||||
|
||||
// //返回数据给客户端
|
||||
// return event
|
||||
// };
|
||||
|
||||
// 'use strict';
|
||||
// const uniPush = uniCloud.getPushManager({appId:"__UNI__4C459F4"}) //注意这里需要传入你的应用appId
|
||||
// exports.main = async (event) => {
|
||||
// console.log(event)
|
||||
// if(event.cid){
|
||||
// let obj = JSON.parse(event.body);
|
||||
// console.log(obj)
|
||||
// const res = await uniPush.sendMessage({
|
||||
// "push_clientid": obj.cids, // 设备id,支持多个以数组的形式指定多个设备,如["cid-1","cid-2"],数组长度不大于1000
|
||||
// "title": obj.title, // 标题
|
||||
// "content": obj.content, // 内容
|
||||
// "settings": obj.settings, // 消息有效期
|
||||
// "payload": obj.payload, // 数据
|
||||
// "category": obj.category, // HarmonyOS NEXT系统(纯血鸿蒙、非安卓鸿蒙)的消息分类,要给鸿蒙设备推送时才必传
|
||||
// "force_notification": true, //填写true,客户端就会对在线消息自动创建“通知栏消息”,不填写则需要客户端自己处理。
|
||||
// "request_id": obj.request_id ,//请求唯一标识号,10-32位之间;如果request_id重复,会导致消息丢失
|
||||
// "options":obj.options //消息分类,没申请可以不传这个参数
|
||||
// })
|
||||
// return res;
|
||||
// }
|
||||
// return {}
|
||||
// };
|
||||
|
||||
// 简单的使用示例
|
||||
'use strict';
|
||||
const uniPush = uniCloud.getPushManager({appId:"__UNI__4C459F4"}) //注意这里需要传入你的应用appId
|
||||
exports.main = async (event, context) => {
|
||||
//event为客户端上传的参数
|
||||
console.log('event : ', event)
|
||||
return await uniPush.sendMessage({
|
||||
"push_clientid": "xxx", //填写上一步在uni-app客户端获取到的客户端推送标识push_clientid
|
||||
"force_notification":true, //填写true,客户端就会对在线消息自动创建“通知栏消息”。
|
||||
"title": "通知栏显示的标题",
|
||||
"content": "通知栏显示的内容",
|
||||
"payload": {
|
||||
"text":"体验一下uni-push2.0"
|
||||
}
|
||||
"options":{
|
||||
"HW": {
|
||||
// 1 表示华为测试消息,华为每个应用每日可发送该测试消息500条,此target_user_type 参数请勿发布至线上。
|
||||
"/message/android/target_user_type":1
|
||||
}
|
||||
}
|
||||
const uniPush = uniCloud.getPushManager({
|
||||
appId: "__UNI__4C459F4"
|
||||
})
|
||||
exports.main = async (event) => {
|
||||
console.log(event)
|
||||
let obj = JSON.parse(event.body)
|
||||
const res = await uniPush.sendMessage({
|
||||
"push_clientid": obj.cids, // 设备id,支持多个以数组的形式指定多个设备,如["cid-1","cid-2"],数组长度不大于1000
|
||||
"title": obj.title, // 标题
|
||||
"content": obj.content, // 内容
|
||||
"settings": obj.settings, // 消息有效期
|
||||
"payload": obj.payload, // 数据
|
||||
"category": obj.category, // HarmonyOS NEXT系统(纯血鸿蒙、非安卓鸿蒙)的消息分类,要给鸿蒙设备推送时才必传
|
||||
"force_notification": true, //填写true,客户端就会对在线消息自动创建“通知栏消息”,不填写则需要客户端自己处理。
|
||||
"request_id": obj.request_id ,//请求唯一标识号,10-32位之间;如果request_id重复,会导致消息丢失
|
||||
"options":obj.options //消息分类,没申请可以不传这个参数
|
||||
})
|
||||
return res;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user