71 lines
1.5 KiB
JavaScript
71 lines
1.5 KiB
JavaScript
import storageManage from '@/commons/utils/storageManage.js'
|
|
import dayjs from 'dayjs'
|
|
import baiduyy from './QS-baiduyy.js'; // 百度语音合成
|
|
|
|
// #ifdef MP-WEIXIN
|
|
import wxTextToSpeach from './wxTextToSpeach.js'; // 微信小程序插件语音合成
|
|
// #endif
|
|
|
|
|
|
const model = {
|
|
// 监听推送通知
|
|
addPushMsgEventListener: function(){
|
|
|
|
console.log("监听推送")
|
|
|
|
// #ifdef APP-PLUS
|
|
// unipush1.0监听消息
|
|
if(plus && plus.push) {
|
|
plus.push.addEventListener('receive', model.handlePush)
|
|
}
|
|
// #endif
|
|
// unipush2.0监听消息
|
|
model.uniPushListener2()
|
|
},
|
|
|
|
|
|
// uniPush2.0 接收推送消息
|
|
uniPushListener2: function() {
|
|
uni.onPushMessage((res) => {
|
|
console.log("uniPush2.0 收到推送消息:", res.data) //监听推送消息
|
|
model.handlePush(res.data)
|
|
})
|
|
},
|
|
|
|
// 语音播报
|
|
handlePush: function(message) {
|
|
|
|
// 没有token信息
|
|
if(!storageManage.token()){
|
|
return false;
|
|
}
|
|
|
|
// 信息不存在
|
|
if(!message || !message.content) {
|
|
return false;
|
|
}
|
|
|
|
const content = JSON.parse(message.content)
|
|
console.log("消息内容:", content)
|
|
|
|
// 支付成功
|
|
if (content && content.type == 'paySuccess') {
|
|
// 在过期时间之内, 则调起语音播报。
|
|
if( dayjs(content.expiredTime).isAfter(dayjs()) ){
|
|
console.log('执行消息播报');
|
|
// #ifdef MP-WEIXIN
|
|
wxTextToSpeach(content.msg)
|
|
// #endif
|
|
|
|
// #ifndef MP-WEIXIN
|
|
baiduyy(content.msg)
|
|
// #endif
|
|
uni.vibrateLong({});
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
export default model |