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();