pushUtils.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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});
  7. const value = uni.getStorageSync('pushreg_switch');
  8. if (value) {
  9. return;
  10. }
  11. const roadinfoCache = uni.getStorageSync('payee_roadinfo');
  12. alog.info({msg: '本地路段信息:' + roadinfoCache});
  13. if (!roadinfoCache){
  14. return;
  15. }
  16. let content = JSON.parse(message.content);
  17. const roadinfo = JSON.parse(roadinfoCache) ;
  18. if(content.roadNo && roadinfo.roadNo && content.roadNo == roadinfo.roadNo){
  19. if (content.type === 1){
  20. deviceParkIn(content)
  21. }else if (content.type === 2){
  22. deviceParkOut(content)
  23. }
  24. }
  25. } catch(e){
  26. }
  27. };
  28. // content 消息格式: JSON格式
  29. // type: 1-设备入场 2-设备出场 3-用户已经支付
  30. // speakMsg: 语音播报内容
  31. // popNode: 弹出框内容
  32. // jumpTo: 页面跳转地址
  33. // data: {} 其他参数,JSON格式
  34. function deviceParkIn(content){
  35. //获取存储的设备入场语音播报开关状态
  36. uni.getStorage({
  37. key:'speakData',
  38. success: (res) => {
  39. let speakDeviceParkIn = res.data.switchVal1;
  40. },
  41. fail: (err) => {
  42. }
  43. })
  44. if(content.speakMsg&&speakDeviceParkIn==true){
  45. speaker.speakAction(content.speakMsg)
  46. }
  47. // const value = uni.getStorageSync('pushModel_switch');
  48. // if (value) {
  49. // return;
  50. // }
  51. // uni.setStorageSync('pushModel_switch', '1');
  52. // uni.showModal({
  53. // title: '温馨提示',
  54. // content: content.popNode,
  55. // success: (res) => {
  56. // if(res.confirm){
  57. // uni.navigateTo({
  58. // url: content.jumpTo
  59. // });
  60. // }
  61. // } ,
  62. // complete:()=>{
  63. // uni.removeStorageSync('pushModel_switch');
  64. // }
  65. // });
  66. }
  67. function deviceParkOut(content){
  68. //获取存储的设备出场语音播报开关状态
  69. uni.getStorage({
  70. key:'speakData',
  71. success: (res) => {
  72. let speakDeviceParkOut = res.data.switchVal2;
  73. },
  74. fail: (err) => {
  75. }
  76. })
  77. if(content.speakMsg&&speakDeviceParkOut==true){
  78. speaker.speakAction(content.speakMsg)
  79. }
  80. }
  81. function pushreg(vue){
  82. //添加推送开关
  83. uni.setStorageSync('pushreg_switch', '1');
  84. //监听系统通知栏消息点击事件
  85. plus.push.addEventListener('click', _handlePush, false);
  86. //监听接收透传消息事件
  87. plus.push.addEventListener('receive', _handlePush, false);
  88. }
  89. export default pushreg