index.js 1.7 KB

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