@tencent-map/lbs-skills 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/cli.js CHANGED
@@ -133,6 +133,7 @@ Options:
133
133
  --location <name> 位置名称(如"西直门"),与 --keywords 组合为搜索词
134
134
  --keywords <kw> 搜索关键词(如"美食")
135
135
  --keyword <kw> 直接指定完整搜索关键词(如"西直门美食")
136
+ --radius <meters> 搜索半径(米,默认 1000)
136
137
 
137
138
  Examples:
138
139
  tmap-lbs nearby --location 西直门 --keywords 美食
@@ -326,7 +327,9 @@ async function cmdNearby(args) {
326
327
  }
327
328
 
328
329
  const encoded = encodeURIComponent(keyword);
329
- const url = `https://mapapi.qq.com/web/claw/nearby-search.html?keyword=${encoded}&key=${encodeURIComponent(key)}`;
330
+ const code = lib.encodeKey(key);
331
+ const radius = args.radius || 1000;
332
+ const url = `https://mapapi.qq.com/web/claw/nearby-search.html?keyword=${encoded}&radius=${radius}&code=${encodeURIComponent(code)}`;
330
333
 
331
334
  console.log(`\n🔍 已生成周边搜索链接:\n`);
332
335
  console.log(` ${url}\n`);
@@ -453,7 +456,7 @@ async function cmdTravel(args) {
453
456
  const params = new URLSearchParams();
454
457
  params.set('spots', spotsJSON);
455
458
  if (recommend) params.set('recommend', recommend);
456
- params.set('key', key);
459
+ params.set('code', lib.encodeKey(key));
457
460
 
458
461
  const url = `https://mapapi.qq.com/web/claw/travel.html?${params.toString()}`;
459
462
 
package/lib/index.js CHANGED
@@ -85,6 +85,40 @@ function ensureKey() {
85
85
  return key;
86
86
  }
87
87
 
88
+ // ─── Key 编码(用于网页链接) ─────────────────────────────────────────
89
+
90
+ /**
91
+ * 字符串错位:每个字符的 charCode 加上偏移量
92
+ * @param {string} str - 原始字符串
93
+ * @param {number} shift - 偏移量
94
+ * @returns {string}
95
+ */
96
+ function shiftChars(str, shift) {
97
+ return Array.from(str)
98
+ .map((ch) => String.fromCharCode(ch.charCodeAt(0) + shift))
99
+ .join('');
100
+ }
101
+
102
+ /**
103
+ * 对 Key 进行简单加密:先字符错位,再 base64 编码
104
+ * @param {string} key - 原始 API Key
105
+ * @returns {string} 加密后的字符串
106
+ */
107
+ function encodeKey(key) {
108
+ const shifted = shiftChars(key, 5);
109
+ return Buffer.from(shifted, 'utf-8').toString('base64');
110
+ }
111
+
112
+ /**
113
+ * 解密 Key:先 base64 解码,再反向字符错位
114
+ * @param {string} encoded - 加密后的字符串
115
+ * @returns {string} 原始 API Key
116
+ */
117
+ function decodeKey(encoded) {
118
+ const shifted = Buffer.from(encoded, 'base64').toString('utf-8');
119
+ return shiftChars(shifted, -5);
120
+ }
121
+
88
122
  // ─── HTTP 请求 ───────────────────────────────────────────────────────
89
123
 
90
124
  /**
@@ -463,6 +497,9 @@ module.exports = {
463
497
  saveConfigFile,
464
498
  CONFIG_DIR,
465
499
  CONFIG_FILE,
500
+ // Key 编码
501
+ encodeKey,
502
+ decodeKey,
466
503
  // HTTP
467
504
  httpGet,
468
505
  // 坐标
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@tencent-map/lbs-skills",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "腾讯地图位置服务命令行工具,支持 POI 搜索、地理编码、周边搜索、路径规划、旅游规划、轨迹可视化等功能",
5
5
  "bin": {
6
- "tmap-lbs": "./bin/cli.js",
7
- "tmaplbs": "./bin/cli.js"
6
+ "tmap-lbs": "./bin/cli.js"
8
7
  },
9
8
  "main": "lib/index.js",
10
9
  "files": [