pushUtils.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. var alog = uni.requireNativePlugin("AndroidLog")
  2. let speaker = uni.requireNativePlugin("SpeechPlug");
  3. const _handlePush = function(message) {
  4. //{"message":{"__UUID__":"androidPushMsg222631973","appid":"__UNI__29ECCC8","content":"{\"type\":2,\"jumpTo\":\"pages/login/login\"}","payload":{"jumpTo":"pages/login/login","type":2},"title":"智慧停车PDA"}}
  5. try {
  6. alog.info({msg: '接收到推送信息:' + message.content});
  7. let content = JSON.parse(message.content);
  8. if (content.type === 1){
  9. deviceParkIn(content)
  10. }else if (content.type === 2){
  11. deviceParkOut(content)
  12. }
  13. } catch(e){
  14. }
  15. };
  16. // content 消息格式: JSON格式
  17. // type: 1-设备入场 2-设备出场 3-用户已经支付
  18. // speakMsg: 语音播报内容
  19. // popNode: 弹出框内容
  20. // jumpTo: 页面跳转地址
  21. // data: {} 其他参数,JSON格式
  22. function deviceParkIn(content){
  23. if(content.speakMsg){
  24. speaker.speakAction(content.speakMsg)
  25. }
  26. uni.showModal({
  27. title: '温馨提示',
  28. content: content.popNode,
  29. success: (res) => {
  30. if(res.confirm){
  31. uni.navigateTo({
  32. url: content.jumpTo
  33. });
  34. }
  35. }
  36. });
  37. }
  38. function deviceParkOut(content){
  39. if(content.speakMsg){
  40. speaker.speakAction(content.speakMsg)
  41. }
  42. }
  43. function pushreg(vue){
  44. alog.info({msg: '推送注册'});
  45. //监听系统通知栏消息点击事件
  46. plus.push.addEventListener('click', _handlePush, false);
  47. //监听接收透传消息事件
  48. plus.push.addEventListener('receive', _handlePush, false);
  49. }
  50. export default pushreg