index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict';
  2. const uniPush = uniCloud.getPushManager({
  3. appId: "__UNI__33EAA2D"
  4. })
  5. exports.main = async (event) => {
  6. let obj = JSON.parse(event.body)
  7. console.log(obj)
  8. // const res = await uniPush.sendMessage({
  9. // category: {
  10. // //HarmonyOS NEXT系统(纯血鸿蒙、非安卓鸿蒙)的消息分类,要给鸿蒙设备推送时才必传
  11. // "harmony":"MARKETING"
  12. // },
  13. // options:{
  14. // "HW": {
  15. // // 值为int 类型。1 表示华为测试消息,华为每个应用每日可发送该测试消息500条。此 target_user_type 参数请勿发布至线上。
  16. // "/message/android/target_user_type":1
  17. // } ,
  18. // "HO": {
  19. // //值为int 类型。1 表示测试推送,不填默认为0。荣耀每个应用每日可发送该测试消息1000条。此测试参数请勿发布至线上。
  20. // "/android/targetUserType": 1
  21. // } ,
  22. // "VV": {
  23. // //值为int 类型。0 表示正式推送;1 表示测试推送,不填默认为0。此 pushMode 参数请勿发布至线上。
  24. // "/pushMode":1
  25. // } ,
  26. // "XM": {
  27. // //新小米消息分类下,私信公信id都必须要传,否则请求小米厂商接口会被拦截
  28. // "/extra.channel_id": ""
  29. // }
  30. // },
  31. // ...obj,
  32. // })
  33. switch (obj.action) {
  34. case 'getClientDetail':
  35. return getClientDetailByCid(obj.cid)
  36. default:
  37. return sendMessage(obj)
  38. }
  39. };
  40. // 推送通知
  41. async function sendMessage(event) {
  42. const res = await uniPush.sendMessage(event)
  43. return res
  44. }
  45. // 查询设备的信息
  46. async function getClientDetailByCid(cid) {
  47. const res = await uniPush.getClientDetailByCid(cid)
  48. return res
  49. }