wechatbridge-cli 1.7.1__tar.gz → 1.7.4__tar.gz

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 (29) hide show
  1. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/PKG-INFO +1 -1
  2. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/tests/test_hardening.py +21 -2
  3. wechatbridge_cli-1.7.4/tests/test_price.py +255 -0
  4. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge/__init__.py +1 -1
  5. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge/main.py +1 -1
  6. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge/price.py +51 -12
  7. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge_cli.egg-info/PKG-INFO +1 -1
  8. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge_cli.egg-info/SOURCES.txt +1 -0
  9. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/LICENSE +0 -0
  10. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/README.md +0 -0
  11. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/pyproject.toml +0 -0
  12. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/setup.cfg +0 -0
  13. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/tests/test_codex.py +0 -0
  14. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/tests/test_codex_auth.py +0 -0
  15. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/tests/test_dsh.py +0 -0
  16. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/tests/test_grok_auth.py +0 -0
  17. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge/__main__.py +0 -0
  18. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge/agy.py +0 -0
  19. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge/codex.py +0 -0
  20. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge/config.py +0 -0
  21. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge/dsh.py +0 -0
  22. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge/grok.py +0 -0
  23. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge/ilink.py +0 -0
  24. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge/runner_common.py +0 -0
  25. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge/update_check.py +0 -0
  26. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge_cli.egg-info/dependency_links.txt +0 -0
  27. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge_cli.egg-info/entry_points.txt +0 -0
  28. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge_cli.egg-info/requires.txt +0 -0
  29. {wechatbridge_cli-1.7.1 → wechatbridge_cli-1.7.4}/wechatbridge_cli.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wechatbridge-cli
3
- Version: 1.7.1
3
+ Version: 1.7.4
4
4
  Summary: Bridge WeChat messages to agy, Grok Build, or Codex CLIs — text/image/file/voice in, CLI replies and generated files back.
5
5
  Author: WeChatBridge contributors
6
6
  License: MIT
@@ -1218,6 +1218,19 @@ class TestPerUserLockContract(unittest.IsolatedAsyncioTestCase):
1218
1218
  m["_kind"] = kind
1219
1219
  return m
1220
1220
 
1221
+ async def _pump_until(self, predicate, tries=100):
1222
+ """Yield to the loop until predicate() holds (bounded).
1223
+
1224
+ A single sleep(0) is not enough on Python <= 3.11: the pre-3.12
1225
+ asyncio.wait_for in _safe_process_message costs extra loop passes
1226
+ before process_message is entered, so first-entry assertions must
1227
+ pump instead of assuming one yield suffices.
1228
+ """
1229
+ for _ in range(tries):
1230
+ if predicate():
1231
+ return
1232
+ await asyncio.sleep(0)
1233
+
1221
1234
  async def test_same_user_serializes(self):
1222
1235
  """同 user 两条消息:第一条阻塞期间,第二条必须排队等待。"""
1223
1236
  released = asyncio.Event()
@@ -1234,7 +1247,7 @@ class TestPerUserLockContract(unittest.IsolatedAsyncioTestCase):
1234
1247
  with mock.patch.object(self.main, "process_message", new=_pm):
1235
1248
  t1 = asyncio.create_task(self.main._safe_process_message(client, msg1))
1236
1249
  t2 = asyncio.create_task(self.main._safe_process_message(client, msg2))
1237
- await asyncio.sleep(0)
1250
+ await self._pump_until(lambda: len(started) >= 1)
1238
1251
  # 仅第一条进入 process_message;第二条被同 user 锁串行化阻塞
1239
1252
  self.assertEqual(started, ["alice"])
1240
1253
  self.assertEqual(ended, [])
@@ -1286,7 +1299,7 @@ class TestPerUserLockContract(unittest.IsolatedAsyncioTestCase):
1286
1299
  t_clear = asyncio.create_task(
1287
1300
  self.main._safe_process_message(client, msg_clear)
1288
1301
  )
1289
- await asyncio.sleep(0)
1302
+ await self._pump_until(lambda: "run_start" in order)
1290
1303
  # run 仍阻塞时,clear 被同 user 锁串行化阻塞,尚未删除 thread_id
1291
1304
  self.assertIn("run_start", order)
1292
1305
  self.assertNotIn("clear", order)
@@ -1934,6 +1947,12 @@ class TestGrokThrottlePreserve(unittest.IsolatedAsyncioTestCase):
1934
1947
  mock.patch(
1935
1948
  "wechatbridge.grok._sync_grok_auth", return_value=True
1936
1949
  ),
1950
+ # run_grok gates on _grok_has_credentials(), which reads the real
1951
+ # host auth.json / XAI_API_KEY; without this the subprocess tests
1952
+ # only pass on machines where grok is already signed in.
1953
+ mock.patch(
1954
+ "wechatbridge.grok._grok_has_credentials", return_value=True
1955
+ ),
1937
1956
  ]
1938
1957
  for p in self._patchers:
1939
1958
  p.start()
@@ -0,0 +1,255 @@
1
+ """Price module contract tests (stdlib unittest only).
2
+
3
+ These pin the *external* contracts that cannot be exercised without real
4
+ API keys: the JD gateway signature rule (empty values excluded), the
5
+ Dataoke signRan rule, the correct Dataoke endpoints/params/versions for
6
+ taokouling parsing and goods detail, and response parsing against sample
7
+ payloads shaped like the real APIs.
8
+
9
+ Credentials are injected by patching the module-level constants so the
10
+ tests never read the host's real JDUNION_*/DATAOKE_* environment.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import asyncio
16
+ import hashlib
17
+ import unittest
18
+ from unittest import mock
19
+
20
+ from wechatbridge import price as price_mod
21
+
22
+
23
+ class _PriceCredentialsMixin:
24
+ """Patch price.py's module-level credentials; never touch os.environ."""
25
+
26
+ def setUp(self):
27
+ super().setUp()
28
+ for name, value in (
29
+ ("_JD_APP_KEY", "test_jd_key"),
30
+ ("_JD_SECRET_KEY", "test_jd_secret"),
31
+ ("_DT_APP_KEY", "test_dt_key"),
32
+ ("_DT_APP_SECRET", "test_dt_secret"),
33
+ ):
34
+ patcher = mock.patch.object(price_mod, name, value)
35
+ patcher.start()
36
+ self.addCleanup(patcher.stop)
37
+
38
+
39
+ class TestJdSign(_PriceCredentialsMixin, unittest.TestCase):
40
+ def test_secret_wraps_both_ends_and_skips_empty_values(self):
41
+ params = {
42
+ "method": "jd.union.open.goods.query",
43
+ "app_key": "test_jd_key",
44
+ "access_token": "",
45
+ "timestamp": "2026-11-01 19:00:00",
46
+ "format": "json",
47
+ "v": "1.0",
48
+ "sign_method": "md5",
49
+ "360buy_param_json": '{"skuIds":["123"]}',
50
+ }
51
+ # Official SDK areNotEmpty semantic: empty values are excluded from
52
+ # the signature input entirely (not concatenated as "k").
53
+ plain = "".join(
54
+ f"{k}{v}" for k, v in sorted(params.items()) if v != ""
55
+ )
56
+ expected = hashlib.md5(
57
+ ("test_jd_secret" + plain + "test_jd_secret").encode("utf-8")
58
+ ).hexdigest().upper()
59
+ self.assertEqual(price_mod._jd_sign(dict(params)), expected)
60
+
61
+ def test_jd_call_drops_access_token_and_sends_gmt8_timestamp(self):
62
+ captured = {}
63
+
64
+ class FakeResp:
65
+ def raise_for_status(self):
66
+ pass
67
+
68
+ def json(self):
69
+ return {"ok": True}
70
+
71
+ def fake_post(url, data=None, timeout=None):
72
+ captured["url"] = url
73
+ captured["data"] = dict(data or {})
74
+ return FakeResp()
75
+
76
+ with mock.patch.object(price_mod.httpx, "post", side_effect=fake_post):
77
+ price_mod._jd_call("jd.union.open.goods.query", {"skuIds": ["123"]})
78
+ sent = captured["data"]
79
+ self.assertNotIn("access_token", sent)
80
+ # GMT+8 Beijing time, "yyyy-MM-dd HH:mm:ss"
81
+ from datetime import datetime, timedelta, timezone
82
+
83
+ ts = datetime.strptime(sent["timestamp"], "%Y-%m-%d %H:%M:%S").replace(
84
+ tzinfo=timezone(timedelta(hours=8))
85
+ )
86
+ delta = abs(
87
+ (datetime.now(timezone.utc) - ts).total_seconds()
88
+ )
89
+ self.assertLess(delta, 60)
90
+ self.assertIn("sign", sent)
91
+
92
+ def test_jd_query_parses_sample_payload(self):
93
+ sample = {
94
+ "jd_union_open_goods_query_reslt": {
95
+ "code": "0",
96
+ "data": [
97
+ {
98
+ "skuName": "Sample Widget 2000",
99
+ "priceInfo": {"price": 129.0, "lowestPrice": 99.0},
100
+ "couponInfo": {
101
+ "couponList": [
102
+ {"discount": 20.0, "quota": 100.0, "endTime": "2026-11-11 23:59:59"}
103
+ ]
104
+ },
105
+ "imageInfo": {"imageList": ["https://img.example/x.jpg"]},
106
+ "shopInfo": {"shopName": "Sample Shop"},
107
+ "materialUrl": "https://item.jd.com/123.html",
108
+ }
109
+ ],
110
+ }
111
+ }
112
+ with mock.patch.object(price_mod, "_jd_call", return_value=sample):
113
+ res = price_mod.query_jd_sku("123")
114
+ self.assertEqual(res.title, "Sample Widget 2000")
115
+ self.assertEqual(res.price, 129.0)
116
+ self.assertEqual(res.lowest_price, 99.0)
117
+ self.assertEqual(res.net_price(), 109.0)
118
+ card = res.card()
119
+ self.assertIn("到手价: ¥109", card)
120
+ self.assertIn("历史最低: ¥99", card)
121
+
122
+
123
+ class TestDataokeSignAndCalls(_PriceCredentialsMixin, unittest.TestCase):
124
+ def test_dt_call_sends_signran_and_no_legacy_sign(self):
125
+ captured = {}
126
+
127
+ class FakeResp:
128
+ def raise_for_status(self):
129
+ pass
130
+
131
+ def json(self):
132
+ return {"code": 0, "data": {"ok": True}}
133
+
134
+ def fake_get(url, params=None, timeout=None):
135
+ captured["url"] = url
136
+ captured["params"] = dict(params or {})
137
+ return FakeResp()
138
+
139
+ with mock.patch.object(price_mod.httpx, "get", side_effect=fake_get):
140
+ out = price_mod._dt_call("/goods/get-goods-details", {"goodsId": "789"})
141
+ self.assertEqual(out, {"ok": True})
142
+ sent = captured["params"]
143
+ self.assertEqual(sent["appKey"], "test_dt_key")
144
+ self.assertIn("timer", sent)
145
+ self.assertIn("nonce", sent)
146
+ self.assertIn("signRan", sent)
147
+ self.assertNotIn("sign", sent)
148
+ expected = hashlib.md5(
149
+ (
150
+ f"appKey=test_dt_key&timer={sent['timer']}"
151
+ f"&nonce={sent['nonce']}&key=test_dt_secret"
152
+ ).encode("utf-8")
153
+ ).hexdigest().upper()
154
+ self.assertEqual(sent["signRan"], expected)
155
+
156
+ def test_dt_call_raises_on_nonzero_code(self):
157
+ class FakeResp:
158
+ def raise_for_status(self):
159
+ pass
160
+
161
+ def json(self):
162
+ return {"code": 1, "msg": "sign error"}
163
+
164
+ with mock.patch.object(price_mod.httpx, "get", return_value=FakeResp()):
165
+ with self.assertRaises(ValueError):
166
+ price_mod._dt_call("/goods/get-goods-details", {"goodsId": "1"})
167
+
168
+ def test_resolve_tkl_uses_parse_content_endpoint(self):
169
+ captured = {}
170
+
171
+ def fake_call(path, params):
172
+ captured["path"] = path
173
+ captured["params"] = dict(params)
174
+ return {"goodsId": "789456"}
175
+
176
+ with mock.patch.object(price_mod, "_dt_call", side_effect=fake_call):
177
+ out = price_mod.resolve_tkl("CZ0001 aBcd12")
178
+ self.assertEqual(captured["path"], "/tb-service/parse-content")
179
+ self.assertEqual(captured["params"]["content"], "CZ0001 aBcd12")
180
+ self.assertEqual(captured["params"]["version"], "v1.0.0")
181
+ self.assertEqual(out["goodsId"], "789456")
182
+
183
+ def test_query_tb_item_sends_goods_id_and_parses(self):
184
+ captured = {}
185
+ sample_data = {
186
+ "goods": {
187
+ "goodsName": "TB Sample",
188
+ "actualPrice": 59.9,
189
+ "originalPrice": 79.9,
190
+ "quanPrice": 10.0,
191
+ "quanReceiveCondition": 50.0,
192
+ "quanEndTime": "2026-11-11 00:00:00",
193
+ "shopName": "TB Shop",
194
+ "goodsImage": "https://img.example/y.jpg",
195
+ "goodsUrl": "https://detail.tmall.com/item.htm?id=789",
196
+ }
197
+ }
198
+
199
+ def fake_call(path, params):
200
+ captured["path"] = path
201
+ captured["params"] = dict(params)
202
+ return sample_data
203
+
204
+ with mock.patch.object(price_mod, "_dt_call", side_effect=fake_call):
205
+ res = price_mod.query_tb_item("789")
206
+ self.assertEqual(
207
+ captured["params"], {"goodsId": "789", "version": "v1.2.4"}
208
+ )
209
+ self.assertEqual(res.title, "TB Sample")
210
+ self.assertEqual(res.price, 59.9)
211
+ self.assertEqual(res.net_price(), 49.9)
212
+
213
+ def test_handle_price_query_ignores_internal_id_field(self):
214
+ # parse-content returns goodsId/itemId; a bare dataoke-internal `id`
215
+ # must NOT be used as a Taobao item id — reply with the
216
+ # "no goods info" fallback instead of querying garbage.
217
+ with mock.patch.object(
218
+ price_mod, "resolve_tkl", return_value={"id": "12345"}
219
+ ), mock.patch.object(
220
+ price_mod, "query_tb_item"
221
+ ) as mock_query:
222
+ reply = asyncio.run(
223
+ price_mod.handle_price_query({"kind": "tkl", "token": "tk"})
224
+ )
225
+ self.assertIn("没拿到商品信息", reply)
226
+ mock_query.assert_not_called()
227
+
228
+ def test_dt_configured_requires_secret(self):
229
+ with mock.patch.object(price_mod, "_DT_APP_SECRET", ""):
230
+ self.assertFalse(price_mod.dt_configured())
231
+ with mock.patch.object(price_mod, "_DT_APP_SECRET", "x"):
232
+ self.assertTrue(price_mod.dt_configured())
233
+
234
+
235
+ class TestDetectTrigger(unittest.TestCase):
236
+ def test_samples(self):
237
+ cases = [
238
+ ("看看 https://u.jd.com/AbCdEf 不错", "jd_short"),
239
+ ("8.8¥CZ0001 aBcd12¥ 打开淘宝", "tkl"),
240
+ ("https://item.jd.com/100012043978.html", "jd_item"),
241
+ ("https://detail.tmall.com/item.htm?id=789456123", "tb_item"),
242
+ ("https://m.tb.cn/h.abc123", "tb_short"),
243
+ ("今天天气不错", None),
244
+ ]
245
+ for text, kind in cases:
246
+ got = price_mod.detect_price_trigger(text)
247
+ if kind is None:
248
+ self.assertIsNone(got, msg=text)
249
+ else:
250
+ self.assertIsNotNone(got, msg=text)
251
+ self.assertEqual(got["kind"], kind, msg=text)
252
+
253
+
254
+ if __name__ == "__main__":
255
+ unittest.main()
@@ -1,2 +1,2 @@
1
1
  """WeChatBridge — bridge WeChat messages to agy, Grok Build, or Codex CLIs."""
2
- __version__ = "1.7.1"
2
+ __version__ = "1.7.4"
@@ -467,7 +467,7 @@ async def _cmd_price(args: str) -> str:
467
467
  "ℹ️ **比价功能未启用** ℹ️\n\n"
468
468
  "在桥的 .env 里配置以下任一项后重启:\n"
469
469
  "`JDUNION_APP_KEY` / `JDUNION_APP_SECRET`(京东联盟)\n"
470
- "`DATAOKE_APP_KEY`(淘宝/天猫,大淘客代理)"
470
+ "`DATAOKE_APP_KEY` / `DATAOKE_APP_SECRET`(淘宝/天猫,大淘客代理)"
471
471
  )
472
472
  trigger = detect_price_trigger(target)
473
473
  if not trigger:
@@ -19,9 +19,11 @@ import hashlib
19
19
  import json
20
20
  import logging
21
21
  import os
22
+ import random
22
23
  import re
23
24
  import time
24
25
  from dataclasses import dataclass, field
26
+ from datetime import datetime, timedelta, timezone
25
27
  from urllib.parse import urljoin, urlparse
26
28
 
27
29
  import httpx
@@ -37,6 +39,7 @@ _JD_APP_KEY = os.getenv("JDUNION_APP_KEY", "")
37
39
  # false-positive on this empty getenv default (no literal secret value here).
38
40
  _JD_SECRET_KEY = os.getenv("JDUNION_APP_SECRET", "")
39
41
  _DT_APP_KEY = os.getenv("DATAOKE_APP_KEY", "")
42
+ _DT_APP_SECRET = os.getenv("DATAOKE_APP_SECRET", "")
40
43
  _DT_TIMEOUT = int(os.getenv("PRICE_HTTP_TIMEOUT", "15"))
41
44
 
42
45
  JD_API_URL = "https://api.jd.com/routerjson"
@@ -48,7 +51,9 @@ def jd_configured() -> bool:
48
51
 
49
52
 
50
53
  def dt_configured() -> bool:
51
- return bool(_DT_APP_KEY)
54
+ # Dataoke rejects unsigned requests: both the appKey and the appSecret
55
+ # (used only locally to compute `signRan`, never sent) are required.
56
+ return bool(_DT_APP_KEY and _DT_APP_SECRET)
52
57
 
53
58
 
54
59
  def price_feature_ready() -> bool:
@@ -182,27 +187,36 @@ def detect_price_trigger(text: str) -> dict | None:
182
187
 
183
188
 
184
189
  def _jd_sign(params: dict) -> str:
190
+ # JD gateway rule (per the official SDK's areNotEmpty semantic): MD5 of
191
+ # secret + sorted non-empty key+value concat + secret, upper. Params with
192
+ # empty values participate in NEITHER the signature NOR the request — the
193
+ # secret wraps both ends.
185
194
  plain = "".join(
186
- f"{k}{v}" for k, v in sorted(params.items()) if k != "sign"
195
+ f"{k}{v}" for k, v in sorted(params.items()) if k != "sign" and v != ""
187
196
  )
188
- plain += _JD_SECRET_KEY
189
- return hashlib.md5(plain.encode("utf-8")).hexdigest().upper()
197
+ return hashlib.md5(
198
+ (_JD_SECRET_KEY + plain + _JD_SECRET_KEY).encode("utf-8")
199
+ ).hexdigest().upper()
190
200
 
191
201
 
192
202
  def _jd_call(method: str, param_json: dict) -> dict:
193
203
  # JD gateway contract: form field is `360buy_param_json`; the signature
194
- # covers every field except `sign` itself (access_token="" participates).
204
+ # covers every non-empty field except `sign` itself. access_token="" is
205
+ # dropped (empty values are neither signed nor sent). timestamp must be
206
+ # Beijing time (GMT+8) — the gateway tolerance is only ~6–10 minutes, so
207
+ # a UTC-local server clock would fail verification by 8 hours.
195
208
  params = {
196
209
  "method": method,
197
210
  "app_key": _JD_APP_KEY,
198
211
  "access_token": "",
199
- "timestamp": time.strftime("%Y-%m-%d %H:%M:%S"),
212
+ "timestamp": datetime.now(timezone(timedelta(hours=8))).strftime("%Y-%m-%d %H:%M:%S"),
200
213
  "format": "json",
201
214
  "v": "1.0",
202
215
  "sign_method": "md5",
203
216
  "360buy_param_json": json.dumps(param_json, ensure_ascii=False, separators=(",", ":")),
204
217
  }
205
218
  params["sign"] = _jd_sign(params)
219
+ params = {k: v for k, v in params.items() if v != ""}
206
220
  resp = httpx.post(JD_API_URL, data=params, timeout=_DT_TIMEOUT)
207
221
  resp.raise_for_status()
208
222
  return resp.json()
@@ -245,9 +259,20 @@ def query_jd_sku(sku: str) -> PriceResult:
245
259
  # ---------------------------------------------------------------------------
246
260
 
247
261
  def _dt_call(path: str, params: dict) -> dict:
262
+ # Dataoke signRan rule (official SDK): business params are NOT signed.
263
+ # signRan = MD5("appKey=<appKey>&timer=<ms>&nonce=<rand6>&key=<appSecret>")
264
+ # upper; the request carries appKey/version/timer/nonce/signRan plus the
265
+ # business params — no legacy `sign` field is sent.
248
266
  params = dict(params)
249
267
  params["appKey"] = _DT_APP_KEY
250
268
  params["version"] = params.get("version", "v2.0.0")
269
+ timer = int(time.time() * 1000)
270
+ nonce = str(random.randint(100000, 999999))
271
+ params["timer"] = timer
272
+ params["nonce"] = nonce
273
+ params["signRan"] = hashlib.md5(
274
+ f"appKey={_DT_APP_KEY}&timer={timer}&nonce={nonce}&key={_DT_APP_SECRET}".encode("utf-8")
275
+ ).hexdigest().upper()
251
276
  resp = httpx.get(f"{DT_API_URL}{path}", params=params, timeout=_DT_TIMEOUT)
252
277
  resp.raise_for_status()
253
278
  data = resp.json()
@@ -257,16 +282,27 @@ def _dt_call(path: str, params: dict) -> dict:
257
282
 
258
283
 
259
284
  def resolve_tkl(token: str) -> dict:
260
- """Parse taokouling → item info via dataoke tpwd API."""
285
+ """Parse taokouling → item info via dataoke's universal parse API.
286
+
287
+ The endpoint for turning a share token / share text into a goods id is
288
+ /tb-service/parse-content (param: content). The privilege-link endpoint
289
+ only converts an already-known goodsId into a promotion link and cannot
290
+ parse tokens.
291
+ """
261
292
  return _dt_call(
262
- "/goods/get-privilege-link",
263
- {"taoCommand": token, "apiName": "generous"},
293
+ "/tb-service/parse-content",
294
+ {"content": token, "version": "v1.0.0"},
264
295
  )
265
296
 
266
297
 
267
298
  def query_tb_item(item_id: str) -> PriceResult:
268
299
  """Query Taobao/Tmall item via dataoke goods detail API."""
269
- data = _dt_call("/goods/get-goods-details", {"id": item_id})
300
+ # get-goods-details takes the Taobao item id as `goodsId`, not `id`
301
+ # (`id` is dataoke's own internal goods id and matches nothing here).
302
+ data = _dt_call(
303
+ "/goods/get-goods-details",
304
+ {"goodsId": str(item_id), "version": "v1.2.4"},
305
+ )
270
306
  goods = data.get("goods", data)
271
307
  quan_price = float(goods.get("quanPrice", 0) or 0)
272
308
  actual_price = float(goods.get("actualPrice", goods.get("originalPrice", 0)) or 0)
@@ -400,7 +436,10 @@ async def handle_price_query(trigger: dict) -> str:
400
436
  if not dt_configured():
401
437
  return _not_configured("大淘客(淘宝口令解析)")
402
438
  data = await asyncio.to_thread(resolve_tkl, trigger["token"])
403
- goods_id = str(data.get("goodsId", "") or data.get("id", ""))
439
+ goods_id = str(
440
+ data.get("goodsId", "")
441
+ or data.get("itemId", "")
442
+ )
404
443
  if not goods_id:
405
444
  return "❓ 口令解析出来了但没拿到商品信息,可能商品未收录。"
406
445
  res = await asyncio.to_thread(query_tb_item, goods_id)
@@ -440,5 +479,5 @@ def _not_configured(what: str) -> str:
440
479
  f"ℹ️ **比价功能未启用** ℹ️\n\n{what} 的 API key 还没配置。\n"
441
480
  "在桥的 .env 里设置后重启即可:\n"
442
481
  "`JDUNION_APP_KEY` / `JDUNION_APP_SECRET`(京东)\n"
443
- "`DATAOKE_APP_KEY`(淘宝/天猫)"
482
+ "`DATAOKE_APP_KEY` / `DATAOKE_APP_SECRET`(淘宝/天猫)"
444
483
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wechatbridge-cli
3
- Version: 1.7.1
3
+ Version: 1.7.4
4
4
  Summary: Bridge WeChat messages to agy, Grok Build, or Codex CLIs — text/image/file/voice in, CLI replies and generated files back.
5
5
  Author: WeChatBridge contributors
6
6
  License: MIT
@@ -6,6 +6,7 @@ tests/test_codex_auth.py
6
6
  tests/test_dsh.py
7
7
  tests/test_grok_auth.py
8
8
  tests/test_hardening.py
9
+ tests/test_price.py
9
10
  wechatbridge/__init__.py
10
11
  wechatbridge/__main__.py
11
12
  wechatbridge/agy.py