新增 Lazada 渠道扩展,支持在 Yuxi 平台中集成 Lazada 电商客服渠道。 包含以下功能模块: - client: Lazada API 客户端封装 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - pairing: 用户配对与绑定 - security: 安全校验 - signature: 请求签名验证 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - session: 会话管理 - tools: Agent 工具集成 - tools_config: 工具配置 - types: 类型定义
34 lines
839 B
Python
34 lines
839 B
Python
from __future__ import annotations
|
|
|
|
import hmac
|
|
import hashlib
|
|
from urllib.parse import urlencode
|
|
|
|
|
|
def generate_signature(app_secret: str, params: dict) -> str:
|
|
sorted_params = sorted(params.items(), key=lambda x: x[0])
|
|
sign_str = urlencode(sorted_params)
|
|
signature = (
|
|
hmac.new(
|
|
app_secret.encode("utf-8"),
|
|
sign_str.encode("utf-8"),
|
|
hashlib.sha256,
|
|
)
|
|
.hexdigest()
|
|
.upper()
|
|
)
|
|
return signature
|
|
|
|
|
|
def verify_webhook_signature(app_key: str, app_secret: str, body: str, auth_header: str) -> bool:
|
|
expected = (
|
|
hmac.new(
|
|
app_secret.encode("utf-8"),
|
|
(app_key + body).encode("utf-8"),
|
|
hashlib.sha256,
|
|
)
|
|
.hexdigest()
|
|
.upper()
|
|
)
|
|
return hmac.compare_digest(expected, auth_header)
|