新增拼多多(Pinduoduo)渠道扩展,支持在 Yuxi 平台中集成拼多多电商客服渠道。 包含以下功能模块: - client: 拼多多 API 客户端封装 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - pairing: 用户配对与绑定 - security: 安全校验 - signature: 请求签名验证 - token: Token 管理 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - tools: Agent 工具集成 - window: 窗口管理 - types: 类型定义
24 lines
988 B
Python
24 lines
988 B
Python
import hashlib
|
|
import hmac
|
|
|
|
|
|
def generate_sign(params: dict, client_secret: str, sign_method: str = "md5") -> str:
|
|
filtered = {k: str(v) for k, v in params.items() if k not in ("sign",)}
|
|
sorted_keys = sorted(filtered.keys())
|
|
raw = "".join(f"{k}{filtered[k]}" for k in sorted_keys)
|
|
|
|
if sign_method == "hmac-sha256":
|
|
return hmac.new(client_secret.encode(), raw.encode(), hashlib.sha256).hexdigest().upper()
|
|
|
|
raw = f"{client_secret}{raw}{client_secret}"
|
|
return hashlib.md5(raw.encode("utf-8")).hexdigest().upper()
|
|
|
|
|
|
def verify_push_sign(payload: str, client_secret: str, sign: str, sign_method: str = "md5") -> bool:
|
|
if sign_method == "hmac-sha256":
|
|
expected = hmac.new(client_secret.encode(), payload.encode(), hashlib.sha256).hexdigest().upper()
|
|
return hmac.compare_digest(expected, sign)
|
|
|
|
expected = hashlib.md5(f"{client_secret}{payload}{client_secret}".encode()).hexdigest().upper()
|
|
return hmac.compare_digest(expected, sign)
|