From cd37f89807115c3bd1028998e0ae9d058621406d Mon Sep 17 00:00:00 2001 From: laoyang Date: Mon, 28 Sep 2026 19:12:59 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=AF=BC=E8=88=AA=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E7=9A=84=20src=20=E6=94=B9=E4=B8=BA=E8=AF=BB=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=8C=E5=8E=BB=E6=8E=89=E4=BB=A3=E7=A0=81=E9=87=8C=E7=9A=84?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E5=9F=9F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 面向公开仓库脱敏:高德 URI API 的 src 原先在服务端与前端各写死一份个人域名。 - src/helpers.php / templates/nodes/form.php:src 统一取 `config.php` 的 `amap.nav_src`。 前端模板用 json_encode 输出,与后端同源 —— 原先这个值在两处各写一遍, 注释里也提醒着「改一边就得改另一边」,现在只改配置一处即可。 - config.example.php:新增 `amap.nav_src`,默认占位 `trip.example.com` (src 只是高德侧的来源统计标识,填任意英数字串都能正常工作), 并注明部署时按自己的域名改这一行。 - LICENSE:版权署名由个人昵称改为 The TripLog Authors。 线上配置已同步补上 `nav_src`(保持原有取值),因此**线上行为不变**: 以线上真实代码 + 真实配置跑过 amap_nav_url(),PHP 7.4 与 8.1 产出的 URL 与改动前逐字节一致。 验证:php -l 全过;amap_nav_url 单测 25/25(新增「src 必须来自配置」「源码里不得出现个人域名」 两条守卫,并做了反向验证 —— 把域名写回去时确实会红);渲染检查 386/386; 部署 10 步全绿(双版本 php -l + 静态断言 + 哈希校验 + 数据库迁移 + HTTP 冒烟 + 真实渲染)。 --- LICENSE | 2 +- config.example.php | 10 +++++++++- src/helpers.php | 12 ++++++++++-- templates/nodes/form.php | 3 ++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/LICENSE b/LICENSE index 3a6327d..865d8e0 100644 --- a/LICENSE +++ b/LICENSE @@ -58,7 +58,7 @@ APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. -Copyright 2026 laoyang +Copyright 2026 The TripLog Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/config.example.php b/config.example.php index 283d86c..50c30b8 100644 --- a/config.example.php +++ b/config.example.php @@ -19,9 +19,17 @@ return [ 'timezone' => 'Asia/Shanghai', ], - // 高德地图:key 用于服务端接口,security_js 用于前端 JS API 2.0 安全密钥 + // 高德地图 + // key —— 服务端接口用 + // security_js —— 前端 JS API 2.0 的安全密钥 + // nav_src —— URI API 的「调用来源」(src) 参数。它**只用于高德侧的来源统计**, + // 填任意英数字串都能正常工作。想按自己的域名统计就改这一行, + // 例如 'trip.example.com' → 'your-domain.com'。 + // 服务端 amap_nav_url() 与前端表单里的 NAV_SRC 都读这个值, + // 所以只改这里一处,两边自动一致。 'amap' => [ 'key' => '', 'security_js' => '', + 'nav_src' => getenv('AMAP_NAV_SRC') ?: 'trip.example.com', ], ]; diff --git a/src/helpers.php b/src/helpers.php index 5b00f69..0189975 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -273,6 +273,9 @@ function media_avatar(?string $url): string * ⚠️ 只给 to 不给 from:from 留空时移动端会自动用「当前位置」当起点, * 这正是「导航到这个位置」的语义。 * + * src 参数取 `config.php` 的 `amap.nav_src`(仅统计用,默认占位 `trip.example.com`)—— + * 部署时按自己的域名改这一处即可,服务端与前端自动一致。 + * * 没坐标时退化成关键词搜索 —— 用户在表单里只敲了名字、没从下拉里选中的情况很常见, * 这种节点也给一个能用的链接,总比什么都不显示强。 * @@ -285,13 +288,18 @@ function amap_nav_url(array $loc, string $mode = 'car'): string $lng = trim((string)($loc['lng'] ?? '')); $lat = trim((string)($loc['lat'] ?? '')); + // 高德 URI API 要求带 src(「调用来源」,只用于统计,任意英数字串都行)。 + // 取值统一放 config.php 的 amap.nav_src,与前端 templates/nodes/form.php 里的 + // NAV_SRC 同源 —— 想换成自己的域名做统计时,只改配置一处即可。 + $src = (string)(app_config()['amap']['nav_src'] ?? 'trip.example.com'); + if (is_numeric($lng) && is_numeric($lat)) { // 只对名称做 URL 编码(逗号保持字面量,否则高德解析不出三段式); // 名称里若含 & 或 = 也能被正确转义。 $to = $lng . ',' . $lat . ($name !== '' ? ',' . rawurlencode($name) : ''); return 'https://uri.amap.com/navigation?to=' . $to . '&mode=' . rawurlencode($mode) - . '&policy=1&src=trip.yangyq.net&coordinate=gaode&callnative=1'; + . '&policy=1&src=' . rawurlencode($src) . '&coordinate=gaode&callnative=1'; } $keyword = $name !== '' ? $name : trim((string)($loc['address'] ?? '')); @@ -299,7 +307,7 @@ function amap_nav_url(array $loc, string $mode = 'car'): string return ''; } return 'https://uri.amap.com/search?keyword=' . rawurlencode($keyword) - . '&src=trip.yangyq.net'; + . '&src=' . rawurlencode($src); } /** 人类可读的文件大小 */ diff --git a/templates/nodes/form.php b/templates/nodes/form.php index a654790..3e90ffb 100644 --- a/templates/nodes/form.php +++ b/templates/nodes/form.php @@ -412,7 +412,8 @@ $tripField = [ // 规则必须与服务端 amap_nav_url() 保持一致(改一边就得改另一边): // 有经纬度 → navigation;只填了名字 → search。 // ⚠️ navigation 的坐标顺序是「经度,纬度」(lng 在前),写反了会导到地球另一边。 - var NAV_SRC = 'trip.yangyq.net'; + // src 与服务端同源,取自 config.php 的 amap.nav_src(只用于统计),不要在别处写死。 + var NAV_SRC = ; function navUrl(name, address, lng, lat) { name = String(name || '').trim();