pushUtils.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. }
  11. } catch(e){
  12. }
  13. };
  14. // content 消息格式: JSON格式
  15. // type: 1-设备入场 2-设备出场 3-用户已经支付
  16. // speakMsg: 语音播报内容
  17. // popNode: 弹出框内容
  18. // jumpTo: 页面跳转地址
  19. // data: {} 其他参数,JSON格式
  20. function deviceParkIn(content){
  21. if(content.speakMsg){
  22. speaker.speakAction(content.speakMsg)
  23. }
  24. uni.showModal({
  25. title: '温馨提示',
  26. content: content.popNode,
  27. success: (res) => {
  28. if(res.confirm){
  29. uni.navigateTo({
  30. url: content.jumpTo
  31. });
  32. }
  33. }
  34. });
  35. }
  36. function pushreg(vue){
  37. alog.info({msg: '推送注册'});
  38. //监听系统通知栏消息点击事件
  39. plus.push.addEventListener('click', _handlePush, false);
  40. //监听接收透传消息事件
  41. plus.push.addEventListener('receive', _handlePush, false);
  42. }
  43. export default pushreg