From 1a8abc6d47a657b3389880383776e930b36bd057 Mon Sep 17 00:00:00 2001 From: zhouyanli <593579392@qq.com> Date: Mon, 29 Jun 2026 15:39:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=8D=A2=E5=A4=A9=E5=9C=B0=E5=9B=BEke?= =?UTF-8?q?y,=E4=BF=AE=E6=94=B9push=E4=BA=91=E5=87=BD=E6=95=B0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- property-uniapp-project/manifest.json | 2 +- .../pageSubPack/activity-list/live-add.vue | 21 ++- .../pageSubPack/api/request.js | 2 +- .../pageSubPack/loginSub/login.vue | 2 +- .../cloudfunctions/push-send/index.js | 155 ++++++++++++++++-- .../cloudfunctions/push-send/package.json | 4 + 6 files changed, 159 insertions(+), 27 deletions(-) diff --git a/property-uniapp-project/manifest.json b/property-uniapp-project/manifest.json index 48efd92..3a6ffb2 100644 --- a/property-uniapp-project/manifest.json +++ b/property-uniapp-project/manifest.json @@ -3,7 +3,7 @@ "appid" : "__UNI__29C3D60", "description" : "智慧社区居民端面向小区业主使用,支持注册、验证码、账号密码多种登录方式,提供密码找回功能,账号使用安全便捷。支持多小区切换,首页设有轮播 banner、社区公告,集成远程开门、生活缴费、在线报修、访客邀请、社区活动常用服务。全服务板块统一涵盖门禁开门、线上缴费、报修申报、访客预约、投诉反馈、问卷调研、活动报名、社区公示、一键联系物业功能。个人中心可管理房屋、住户、车位、车辆信息,支持更换手机号、修改密码、消息通知设置、版本更新及账号退出,一站式满足业主居家生活、社区服务、房产车辆管理需求,实现社区生活数字化、便捷化。", "versionName" : "1.0.1", - "versionCode" : 105, + "versionCode" : 106, "transformPx" : false, "uniCloud" : { "provider" : "aliyun", diff --git a/property-uniapp-project/pageSubPack/activity-list/live-add.vue b/property-uniapp-project/pageSubPack/activity-list/live-add.vue index b6685f8..13909f2 100644 --- a/property-uniapp-project/pageSubPack/activity-list/live-add.vue +++ b/property-uniapp-project/pageSubPack/activity-list/live-add.vue @@ -58,9 +58,8 @@ import { ref } from 'vue'; import { onLoad } from '@dcloudio/uni-app'; import { addActivityLive, signinActivityLive, uploadFile } from '../api/api.js'; -// 高德地图 Web API Key(用于逆地址解析,需要去 https://lbs.amap.com 申请免费 Key) -const AMAP_KEY = '38cd7fb803c600a58c5a13e644feab34'; -// const AMAP_KEY = 'f362f595be12ab7d84bd502b48b30d2a'; +// 天地图 Web API Key(用于逆地址解析) +const TIANDITU_KEY = 'b0201708e26cb56e514d74d1686f6f91'; // 活动ID const activityId = ref(''); @@ -86,20 +85,20 @@ const handleTextInput = (e) => { currentLength.value = e.detail.value.length; }; -// 逆地址解析(坐标转地址) +// 逆地址解析(坐标转地址)- 天地图 API const reverseGeocode = async (lng, lat) => { - if (!AMAP_KEY) return null; + if (!TIANDITU_KEY) return null; try { const res = await uni.request({ - url: 'https://restapi.amap.com/v3/geocode/regeo', + url: 'http://api.tianditu.gov.cn/geocoder', data: { - key: AMAP_KEY, - location: `${lng},${lat}`, - extensions: 'base' + type: 'rgc', + postStr: JSON.stringify({ lon: lng, lat: lat, ver: 1 }), + tk: TIANDITU_KEY } }); - if (res.data?.status === '1' && res.data.regeocode?.formatted_address) { - return res.data.regeocode.formatted_address; + if (res.data?.status === '0' && res.data.result?.formatted_address) { + return res.data.result.formatted_address; } return null; } catch (e) { diff --git a/property-uniapp-project/pageSubPack/api/request.js b/property-uniapp-project/pageSubPack/api/request.js index a8fe37b..0bc049c 100644 --- a/property-uniapp-project/pageSubPack/api/request.js +++ b/property-uniapp-project/pageSubPack/api/request.js @@ -2,7 +2,7 @@ let baseUrl = ''; if (process.env.NODE_ENV === 'development') { baseUrl = 'http://192.168.1.222:8080'; // 开发环境 } else { - baseUrl = 'https://wuyeapi.bugtc.com'; // 生产环境 + baseUrl = 'https://wuyeapi.ckdzkj.com'; // 生产环境 } export default function request(url, data = {}, method = "GET") { diff --git a/property-uniapp-project/pageSubPack/loginSub/login.vue b/property-uniapp-project/pageSubPack/loginSub/login.vue index 9d10a1e..efe0937 100644 --- a/property-uniapp-project/pageSubPack/loginSub/login.vue +++ b/property-uniapp-project/pageSubPack/loginSub/login.vue @@ -202,7 +202,7 @@ const getVerifyCode = () => { }).catch(err => { uni.hideLoading(); uni.showToast({ - title: '网络异常', + title: err.msg||'网络异常', icon: 'error' }); }) diff --git a/property-uniapp-project/uniCloud-aliyun/cloudfunctions/push-send/index.js b/property-uniapp-project/uniCloud-aliyun/cloudfunctions/push-send/index.js index 3663151..18202f2 100644 --- a/property-uniapp-project/uniCloud-aliyun/cloudfunctions/push-send/index.js +++ b/property-uniapp-project/uniCloud-aliyun/cloudfunctions/push-send/index.js @@ -1,15 +1,144 @@ 'use strict'; -// 初始化推送管理器 -const uniPush = uniCloud.getPushManager({ - appId: "__UNI__29C3D60" -}) + +/** + * 推送云函数 + * 支持单推(cid)和群推(cids) + */ exports.main = async (event, context) => { - // event接收前端传入的推送参数 - const res = await uniPush.sendMessage({ - push_clientid: event.cid, // 客户端设备cid - title: "通知标题", - content: "通知内容", - force_notification: true // 离线厂商推送必填 - }) - return res -}; + // HTTP 触发器接收的参数在 event.body 中(JSON 字符串),需要解析 + let requestData; + + if (event.body && typeof event.body === 'string') { + try { + requestData = JSON.parse(event.body); + console.log('成功解析 event.body'); + } catch (e) { + console.error('JSON 解析失败:', e.message); + return { + success: false, + error: { + code: 'ParseError', + message: '请求体 JSON 格式错误' + } + }; + } + } else if (event.body && typeof event.body === 'object') { + // 某些情况下 body 可能已经是对象 + requestData = event.body; + console.log('使用 event.body 对象'); + } else { + // 兼容直接传递参数的情况(非 HTTP 触发器调用或测试环境) + requestData = event; + console.log('使用 event 对象(兼容模式)'); + } + + console.log('请求数据:', JSON.stringify(requestData)); + + // 从解析后的数据中解构参数 + const { appId, cids, cid, title, content, payload, request_id } = requestData; + + // 参数校验 + if (!appId || typeof appId !== 'string') { + console.error('appId 无效:', appId, '类型:', typeof appId); + return { + success: false, + error: { + code: 'ParameterError', + message: '缺少必填参数:appId,且必须为字符串' + } + }; + } + + // 统一推送目标:cid 优先,其次 cids + const clientIds = cid ? [cid] : cids; + if (!clientIds || (Array.isArray(clientIds) && clientIds.length === 0)) { + console.error('clientIds 无效:', clientIds); + return { + success: false, + error: { + code: 'ParameterError', + message: '缺少必填参数:cids 或 cid' + } + }; + } + + if (!title || typeof title !== 'string') { + console.error('title 无效:', title); + return { + success: false, + error: { + code: 'ParameterError', + message: '缺少必填参数:title,且必须为字符串' + } + }; + } + + if (!content || typeof content !== 'string') { + console.error('content 无效'); + return { + success: false, + error: { + code: 'ParameterError', + message: '缺少必填参数:content,且必须为字符串' + } + }; + } + + // 发送推送 + try { + console.log('初始化推送管理器,appId:', appId); + const uniPush = uniCloud.getPushManager({ appId }); + + const sendMessageParams = { + push_clientid: Array.isArray(clientIds) ? clientIds : [clientIds], + title, + content, + force_notification: true // 离线厂商推送必填 + }; + + // 自定义 payload(仅当为有效对象时添加) + if ( + payload && + typeof payload === 'object' && + !Array.isArray(payload) && + Object.keys(payload).length > 0 + ) { + sendMessageParams.payload = payload; + console.log('添加自定义 payload'); + } + + // 可选的 requestId + if (request_id) { + sendMessageParams.request_id = request_id; + console.log('添加 request_id:', request_id); + } + + console.log('准备发送推送,参数:', JSON.stringify(sendMessageParams)); + + const res = await uniPush.sendMessage(sendMessageParams); + + console.log('推送成功,结果:', JSON.stringify(res)); + + return { + success: true, + data: res + }; + + } catch (error) { + // 记录完整错误信息到云函数日志,便于排查 + console.error('push-send 推送失败:', JSON.stringify({ + message: error.message, + errMsg: error.errMsg, + code: error.code, + stack: error.stack + })); + + return { + success: false, + error: { + code: error.code || 'PushError', + message: error.errMsg || error.message || '推送失败,请稍后重试' + } + }; + } +}; \ No newline at end of file diff --git a/property-uniapp-project/uniCloud-aliyun/cloudfunctions/push-send/package.json b/property-uniapp-project/uniCloud-aliyun/cloudfunctions/push-send/package.json index 5d7e784..4cc1936 100644 --- a/property-uniapp-project/uniCloud-aliyun/cloudfunctions/push-send/package.json +++ b/property-uniapp-project/uniCloud-aliyun/cloudfunctions/push-send/package.json @@ -1,5 +1,9 @@ { "name": "push-send", + "cloudfunction-config": { + "path": "/push-send", + "timeout": 60 + }, "dependencies": {}, "extensions": { "uni-cloud-push": {}