新增京东(JD)渠道扩展,支持在 Yuxi 平台中集成京东客服渠道。 包含以下功能模块: - client: 京东 API 客户端封装 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - pairing: 用户配对与绑定 - security: 安全校验 - signature: 请求签名验证 - crypto: 加解密处理 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - session: 会话管理 - business: 业务逻辑处理 - types: 类型定义
29 lines
730 B
Python
29 lines
730 B
Python
import base64
|
|
import hashlib
|
|
import json
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def decrypt_jd_message(encrypted_body: str, app_secret: str) -> dict | None:
|
|
try:
|
|
key = hashlib.md5(app_secret.encode("utf-8")).hexdigest()[:16].encode("utf-8")
|
|
raw = base64.b64decode(encrypted_body)
|
|
|
|
iv = raw[:16]
|
|
ciphertext = raw[16:]
|
|
|
|
from Crypto.Cipher import AES
|
|
|
|
cipher = AES.new(key, AES.MODE_CBC, iv)
|
|
decrypted = cipher.decrypt(ciphertext)
|
|
|
|
pad_len = decrypted[-1]
|
|
decrypted = decrypted[:-pad_len]
|
|
|
|
return json.loads(decrypted.decode("utf-8"))
|
|
except Exception:
|
|
logger.warning("JD message AES decrypt failed")
|
|
return None
|