更换天地图key,修改push云函数配置

This commit is contained in:
zhouyanli
2026-06-29 15:39:26 +08:00
parent d0ed33ccc3
commit 1a8abc6d47
6 changed files with 159 additions and 27 deletions

View File

@@ -3,7 +3,7 @@
"appid" : "__UNI__29C3D60", "appid" : "__UNI__29C3D60",
"description" : "智慧社区居民端面向小区业主使用,支持注册、验证码、账号密码多种登录方式,提供密码找回功能,账号使用安全便捷。支持多小区切换,首页设有轮播 banner、社区公告集成远程开门、生活缴费、在线报修、访客邀请、社区活动常用服务。全服务板块统一涵盖门禁开门、线上缴费、报修申报、访客预约、投诉反馈、问卷调研、活动报名、社区公示、一键联系物业功能。个人中心可管理房屋、住户、车位、车辆信息支持更换手机号、修改密码、消息通知设置、版本更新及账号退出一站式满足业主居家生活、社区服务、房产车辆管理需求实现社区生活数字化、便捷化。", "description" : "智慧社区居民端面向小区业主使用,支持注册、验证码、账号密码多种登录方式,提供密码找回功能,账号使用安全便捷。支持多小区切换,首页设有轮播 banner、社区公告集成远程开门、生活缴费、在线报修、访客邀请、社区活动常用服务。全服务板块统一涵盖门禁开门、线上缴费、报修申报、访客预约、投诉反馈、问卷调研、活动报名、社区公示、一键联系物业功能。个人中心可管理房屋、住户、车位、车辆信息支持更换手机号、修改密码、消息通知设置、版本更新及账号退出一站式满足业主居家生活、社区服务、房产车辆管理需求实现社区生活数字化、便捷化。",
"versionName" : "1.0.1", "versionName" : "1.0.1",
"versionCode" : 105, "versionCode" : 106,
"transformPx" : false, "transformPx" : false,
"uniCloud" : { "uniCloud" : {
"provider" : "aliyun", "provider" : "aliyun",

View File

@@ -58,9 +58,8 @@ import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app'; import { onLoad } from '@dcloudio/uni-app';
import { addActivityLive, signinActivityLive, uploadFile } from '../api/api.js'; import { addActivityLive, signinActivityLive, uploadFile } from '../api/api.js';
// 高德地图 Web API Key用于逆地址解析,需要去 https://lbs.amap.com 申请免费 Key // 地图 Web API Key用于逆地址解析
const AMAP_KEY = '38cd7fb803c600a58c5a13e644feab34'; const TIANDITU_KEY = 'b0201708e26cb56e514d74d1686f6f91';
// const AMAP_KEY = 'f362f595be12ab7d84bd502b48b30d2a';
// 活动ID // 活动ID
const activityId = ref(''); const activityId = ref('');
@@ -86,20 +85,20 @@ const handleTextInput = (e) => {
currentLength.value = e.detail.value.length; currentLength.value = e.detail.value.length;
}; };
// 逆地址解析(坐标转地址) // 逆地址解析(坐标转地址)- 天地图 API
const reverseGeocode = async (lng, lat) => { const reverseGeocode = async (lng, lat) => {
if (!AMAP_KEY) return null; if (!TIANDITU_KEY) return null;
try { try {
const res = await uni.request({ const res = await uni.request({
url: 'https://restapi.amap.com/v3/geocode/regeo', url: 'http://api.tianditu.gov.cn/geocoder',
data: { data: {
key: AMAP_KEY, type: 'rgc',
location: `${lng},${lat}`, postStr: JSON.stringify({ lon: lng, lat: lat, ver: 1 }),
extensions: 'base' tk: TIANDITU_KEY
} }
}); });
if (res.data?.status === '1' && res.data.regeocode?.formatted_address) { if (res.data?.status === '0' && res.data.result?.formatted_address) {
return res.data.regeocode.formatted_address; return res.data.result.formatted_address;
} }
return null; return null;
} catch (e) { } catch (e) {

View File

@@ -2,7 +2,7 @@ let baseUrl = '';
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
baseUrl = 'http://192.168.1.222:8080'; // 开发环境 baseUrl = 'http://192.168.1.222:8080'; // 开发环境
} else { } else {
baseUrl = 'https://wuyeapi.bugtc.com'; // 生产环境 baseUrl = 'https://wuyeapi.ckdzkj.com'; // 生产环境
} }
export default function request(url, data = {}, method = "GET") { export default function request(url, data = {}, method = "GET") {

View File

@@ -202,7 +202,7 @@ const getVerifyCode = () => {
}).catch(err => { }).catch(err => {
uni.hideLoading(); uni.hideLoading();
uni.showToast({ uni.showToast({
title: '网络异常', title: err.msg||'网络异常',
icon: 'error' icon: 'error'
}); });
}) })

View File

@@ -1,15 +1,144 @@
'use strict'; 'use strict';
// 初始化推送管理器
const uniPush = uniCloud.getPushManager({ /**
appId: "__UNI__29C3D60" * 推送云函数
}) * 支持单推cid和群推cids
*/
exports.main = async (event, context) => { exports.main = async (event, context) => {
// event接收前端传入的推送参数 // HTTP 触发器接收的参数在 event.body 中JSON 字符串),需要解析
const res = await uniPush.sendMessage({ let requestData;
push_clientid: event.cid, // 客户端设备cid
title: "通知标题", if (event.body && typeof event.body === 'string') {
content: "通知内容", try {
force_notification: true // 离线厂商推送必填 requestData = JSON.parse(event.body);
}) console.log('成功解析 event.body');
return res } 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 || '推送失败,请稍后重试'
}
};
}
}; };

View File

@@ -1,5 +1,9 @@
{ {
"name": "push-send", "name": "push-send",
"cloudfunction-config": {
"path": "/push-send",
"timeout": 60
},
"dependencies": {}, "dependencies": {},
"extensions": { "extensions": {
"uni-cloud-push": {} "uni-cloud-push": {}