From 034facfbf0fd9c7cd7f2d43d100e773c85f3d99e Mon Sep 17 00:00:00 2001 From: aihe <961836564@qq.com> Date: Sun, 16 Jun 2024 22:35:23 +0800 Subject: [PATCH] uu --- App.vue | 4 +++- common/messageNotice/index.js | 34 ++++++++++++++++++++++++++++++++++ manifest.json | 6 ++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 common/messageNotice/index.js diff --git a/App.vue b/App.vue index 10c04bf..c8e5eba 100644 --- a/App.vue +++ b/App.vue @@ -8,6 +8,7 @@ // import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'; import { USERKEY, COMMONKEY } from "@/store/actionKey" import { checkUpdate } from "@/common/appUpdate" + import { onPushMessage } from "@/common/messageNotice" export default { globalData: { @@ -16,7 +17,8 @@ onLaunch: function() { this.$store.dispatch(USERKEY.GETUSERINFO) this.$store.dispatch(COMMONKEY.GETDIC) - + // 监听消息通知 + onPushMessage() // #ifdef H5 console.log( `%c hello uniapp %c v${version} `, diff --git a/common/messageNotice/index.js b/common/messageNotice/index.js new file mode 100644 index 0000000..264ec47 --- /dev/null +++ b/common/messageNotice/index.js @@ -0,0 +1,34 @@ +import { setClipboardData, showToast } from "@/common/untool" + +// #ifdef APP-PLUS + var jpushModule = uni.requireNativePlugin("JG-JPush"); + var audioObj = uni.getBackgroundAudioManager(); +// #endif + +const getPushClientId = ()=> { + return new Promise((resolve, reject)=>{ + // uni-app客户端获取push客户端标记 + uni.getPushClientId({ + success: (res) => { + let push_clientid = res.cid + console.log('客户端推送标识:', push_clientid) + resolve(res) + }, + fail(err) { + console.log('getPushClientId err =========', err) + reject(err) + } + }) + }) + +} + +export const onPushMessage = async()=> { + uni.onPushMessage((res) => { + console.log("收到推送消息 onPushMessage ===== ",res) //监听推送消息 + showToast(JSON.stringify(res)) + }) + let cltRes = await getPushClientId() + // 复制 PushClientId + setClipboardData(cltRes.cid) +} \ No newline at end of file diff --git a/manifest.json b/manifest.json index dbf87f5..2f0e3de 100644 --- a/manifest.json +++ b/manifest.json @@ -95,6 +95,12 @@ "appkey_ios" : "aatodo", "appkey_android" : "b7feefb9882f1d0953fbeffb1cef8aec" } + }, + "push" : { + "unipush" : { + "version" : "2", + "offline" : true + } } }, "orientation" : [ "portrait-primary" ],