增加 unipush2.0

This commit is contained in:
xuli3099
2025-09-05 13:08:49 +08:00
parent 426ac9171d
commit c205422420
4 changed files with 53 additions and 39 deletions

View File

@@ -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://192.168.236.71:31302"
# VITE_APP_BASE_URL = "http://123.57.20.168:3000" # 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' # VITE_APP_BASE_URL = 'https://appi-test.718yousheng.com/app'

View File

@@ -18,15 +18,16 @@ onLaunch((opt) => {
// uni.getPushClientId({ // uni.getPushClientId({
// success: (res) => { // success: (res) => {
// let push_clientid = res.cid // let push_clientid = res.cid
// showAlert(push_clientid)
// console.log('客户端推送标识:', push_clientid); // console.log('客户端推送标识:', push_clientid);
// }, // },
// fail(err) { // fail(err) {
// console.log(err) // console.log(err)
// } // }
// }) // })
uni.onPushMessage(res => { uni.onPushMessage(res => {
console.log("收到推送消息:", res) //监听推送消息 console.log("收到推送消息:", res) //监听推送消息
showAlert(JSON.stringify(res))
// uni.createPushMessage({ // uni.createPushMessage({
// title: res.data.title, // title: res.data.title,
// content: res.data.content, // content: res.data.content,

View File

@@ -281,7 +281,6 @@ const submitForm = () => {
let deviceId = res3.data; let deviceId = res3.data;
// showAlert("读取成功=>"+deviceId); // showAlert("读取成功=>"+deviceId);
param.uniqCode = deviceId; param.uniqCode = deviceId;
uni.getPushClientId({ uni.getPushClientId({
success: (res) => { success: (res) => {
let push_clientid = res.cid let push_clientid = res.cid

View File

@@ -1,32 +1,46 @@
// 'use strict'; // 'use strict';
// exports.main = async (event, context) => { // const uniPush = uniCloud.getPushManager({appId:"__UNI__4C459F4"}) //注意这里需要传入你的应用appId
// //event为客户端上传的参数 // exports.main = async (event) => {
// console.log('event : ', event) // console.log(event)
// if(event.cid){
// //返回数据给客户端 // let obj = JSON.parse(event.body);
// return event // 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'; 'use strict';
const uniPush = uniCloud.getPushManager({appId:"__UNI__4C459F4"}) //注意这里需要传入你的应用appId const uniPush = uniCloud.getPushManager({
exports.main = async (event, context) => { appId: "__UNI__4C459F4"
//event为客户端上传的参数 })
console.log('event : ', event) exports.main = async (event) => {
return await uniPush.sendMessage({ console.log(event)
"push_clientid": "xxx", //填写上一步在uni-app客户端获取到的客户端推送标识push_clientid let obj = JSON.parse(event.body)
"force_notification":true, //填写true客户端就会对在线消息自动创建“通知栏消息”。 const res = await uniPush.sendMessage({
"title": "通知栏显示的标题", "push_clientid": obj.cids, // 设备id支持多个以数组的形式指定多个设备如["cid-1","cid-2"]数组长度不大于1000
"content": "通知栏显示的内容", "title": obj.title, // 标题
"payload": { "content": obj.content, // 内容
"text":"体验一下uni-push2.0" "settings": obj.settings, // 消息有效期
} "payload": obj.payload, // 数据
"options":{ "category": obj.category, // HarmonyOS NEXT系统纯血鸿蒙、非安卓鸿蒙的消息分类要给鸿蒙设备推送时才必传
"HW": { "force_notification": true, //填写true客户端就会对在线消息自动创建“通知栏消息”不填写则需要客户端自己处理。
// 1 表示华为测试消息华为每个应用每日可发送该测试消息500条此target_user_type 参数请勿发布至线上。 "request_id": obj.request_id ,//请求唯一标识号10-32位之间如果request_id重复会导致消息丢失
"/message/android/target_user_type":1 "options":obj.options //消息分类,没申请可以不传这个参数
}
}
}) })
return res;
}; };