diff --git a/.env.development b/.env.development index 934abf9..f34654e 100644 --- a/.env.development +++ b/.env.development @@ -1,12 +1,12 @@ #调用后台地址 # 公司 -# VITE_APP_BASE_URL = 'http://118.186.13.120:31302' +VITE_APP_BASE_URL = 'http://118.186.13.120:31302' # VITE_APP_BASE_URL = "http://192.168.236.71:31302" # VITE_APP_BASE_URL = "http://123.57.20.168:3000" # 友晟外网 -VITE_APP_BASE_URL = 'https://app-test.718yousheng.com/app' +# VITE_APP_BASE_URL = 'https://app-test.718yousheng.com/app' # 友晟内网 # VITE_APP_BASE_URL = 'https://appi-test.718yousheng.com/app' diff --git a/src/App.vue b/src/App.vue index ee78382..b939d59 100644 --- a/src/App.vue +++ b/src/App.vue @@ -15,18 +15,19 @@ onLaunch((opt) => { console.log("APP onLaunch") // #ifdef APP-PLUS - // uni.getPushClientId({ - // success: (res) => { - // let push_clientid = res.cid - // console.log('客户端推送标识:', push_clientid); - // }, - // fail(err) { - // console.log(err) - // } - // }) + // uni.getPushClientId({ + // success: (res) => { + // let push_clientid = res.cid + // showAlert(push_clientid) + // console.log('客户端推送标识:', push_clientid); + // }, + // fail(err) { + // console.log(err) + // } + // }) + uni.onPushMessage(res => { console.log("收到推送消息:", res) //监听推送消息 - showAlert(JSON.stringify(res)) // uni.createPushMessage({ // title: res.data.title, // content: res.data.content, diff --git a/src/pages/login/login.vue b/src/pages/login/login.vue index 55638f0..1516040 100644 --- a/src/pages/login/login.vue +++ b/src/pages/login/login.vue @@ -281,7 +281,6 @@ const submitForm = () => { let deviceId = res3.data; // showAlert("读取成功=>"+deviceId); param.uniqCode = deviceId; - uni.getPushClientId({ success: (res) => { let push_clientid = res.cid diff --git a/uniCloud-aliyun/cloudfunctions/testUnipush2/index.js b/uniCloud-aliyun/cloudfunctions/testUnipush2/index.js index 309ce19..4666fc4 100644 --- a/uniCloud-aliyun/cloudfunctions/testUnipush2/index.js +++ b/uniCloud-aliyun/cloudfunctions/testUnipush2/index.js @@ -1,32 +1,46 @@ -// 'use strict'; -// exports.main = async (event, context) => { -// //event为客户端上传的参数 -// console.log('event : ', event) - -// //返回数据给客户端 -// return event -// }; +// 'use strict'; +// const uniPush = uniCloud.getPushManager({appId:"__UNI__4C459F4"}) //注意这里需要传入你的应用appId +// exports.main = async (event) => { +// console.log(event) +// if(event.cid){ +// let obj = JSON.parse(event.body); +// console.log(obj) +// const res = await uniPush.sendMessage({ +// "push_clientid": obj.cids, // 设备id,支持多个以数组的形式指定多个设备,如["cid-1","cid-2"],数组长度不大于1000 +// "title": obj.title, // 标题 +// "content": obj.content, // 内容 +// "settings": obj.settings, // 消息有效期 +// "payload": obj.payload, // 数据 +// "category": obj.category, // HarmonyOS NEXT系统(纯血鸿蒙、非安卓鸿蒙)的消息分类,要给鸿蒙设备推送时才必传 +// "force_notification": true, //填写true,客户端就会对在线消息自动创建“通知栏消息”,不填写则需要客户端自己处理。 +// "request_id": obj.request_id ,//请求唯一标识号,10-32位之间;如果request_id重复,会导致消息丢失 +// "options":obj.options //消息分类,没申请可以不传这个参数 +// }) +// return res; +// } +// return {} +// }; // 简单的使用示例 'use strict'; -const uniPush = uniCloud.getPushManager({appId:"__UNI__4C459F4"}) //注意这里需要传入你的应用appId -exports.main = async (event, context) => { - //event为客户端上传的参数 - console.log('event : ', event) - return await uniPush.sendMessage({ - "push_clientid": "xxx", //填写上一步在uni-app客户端获取到的客户端推送标识push_clientid - "force_notification":true, //填写true,客户端就会对在线消息自动创建“通知栏消息”。 - "title": "通知栏显示的标题", - "content": "通知栏显示的内容", - "payload": { - "text":"体验一下uni-push2.0" - } - "options":{ - "HW": { - // 1 表示华为测试消息,华为每个应用每日可发送该测试消息500条,此target_user_type 参数请勿发布至线上。 - "/message/android/target_user_type":1 - } - } +const uniPush = uniCloud.getPushManager({ + appId: "__UNI__4C459F4" +}) +exports.main = async (event) => { + console.log(event) + let obj = JSON.parse(event.body) + const res = await uniPush.sendMessage({ + "push_clientid": obj.cids, // 设备id,支持多个以数组的形式指定多个设备,如["cid-1","cid-2"],数组长度不大于1000 + "title": obj.title, // 标题 + "content": obj.content, // 内容 + "settings": obj.settings, // 消息有效期 + "payload": obj.payload, // 数据 + "category": obj.category, // HarmonyOS NEXT系统(纯血鸿蒙、非安卓鸿蒙)的消息分类,要给鸿蒙设备推送时才必传 + "force_notification": true, //填写true,客户端就会对在线消息自动创建“通知栏消息”,不填写则需要客户端自己处理。 + "request_id": obj.request_id ,//请求唯一标识号,10-32位之间;如果request_id重复,会导致消息丢失 + "options":obj.options //消息分类,没申请可以不传这个参数 }) + return res; }; +