@tencent-map/lbs-skills 0.0.6 → 0.0.8

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.
Files changed (3) hide show
  1. package/bin/cli.js +12 -3
  2. package/lib/index.js +37 -0
  3. package/package.json +2 -3
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 美食
@@ -325,8 +326,11 @@ async function cmdNearby(args) {
325
326
  keyword = (args.location || '') + (args.keywords || '');
326
327
  }
327
328
 
328
- const encoded = encodeURIComponent(keyword);
329
- const url = `https://mapapi.qq.com/web/claw/nearby-search.html?keyword=${encoded}&key=${encodeURIComponent(key)}`;
329
+ const params = new URLSearchParams();
330
+ params.set('keyword', keyword);
331
+ params.set('radius', args.radius || 1000);
332
+ params.set('code', lib.encodeKey(key));
333
+ const url = `https://mapapi.qq.com/web/claw/nearby-search.html?${params.toString()}`;
330
334
 
331
335
  console.log(`\n🔍 已生成周边搜索链接:\n`);
332
336
  console.log(` ${url}\n`);
@@ -453,7 +457,7 @@ async function cmdTravel(args) {
453
457
  const params = new URLSearchParams();
454
458
  params.set('spots', spotsJSON);
455
459
  if (recommend) params.set('recommend', recommend);
456
- params.set('key', key);
460
+ params.set('code', lib.encodeKey(key));
457
461
 
458
462
  const url = `https://mapapi.qq.com/web/claw/travel.html?${params.toString()}`;
459
463
 
@@ -488,6 +492,11 @@ async function main() {
488
492
  const argv = process.argv.slice(2);
489
493
  const command = argv[0];
490
494
 
495
+ if (command === '--version' || command === '-v') {
496
+ console.log(version);
497
+ return;
498
+ }
499
+
491
500
  if (!command || command === '--help' || command === '-h') {
492
501
  console.log(HELP);
493
502
  return;
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.8",
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": [