index.obj.js 565 B

123456789101112131415161718192021
  1. module.exports = {
  2. async sendPushMessage(cid) {
  3. // 防止非法调用
  4. if (!cid) {
  5. throw new Error('请传入推送客户端ID')
  6. }
  7. if (typeof cid !== 'string') {
  8. throw new Error('推送客户端ID必须为字符串')
  9. }
  10. const pushManager = uniCloud.getPushManager({appId: '__UNI__HelloUniAppX'})
  11. const res = await pushManager.sendMessage({
  12. push_clientid: cid,
  13. title: '测试推送标题',
  14. content: '测试推送内容',
  15. payload: {
  16. data: '测试推送数据'
  17. }
  18. })
  19. return res
  20. }
  21. }