ForcePilot/backend/package/yuxi/channel/extensions/alipay/dedup.py
Kris 71364ea579 feat(alipay): 新增支付宝渠道插件完整实现
实现了支付宝生活号渠道的完整功能,包括消息接收回调、发送、安全验证、去重、配对绑定、流式回复支持等完整能力。
2026-05-21 10:39:23 +08:00

29 lines
834 B
Python

import time
from yuxi.channel.extensions.alipay.constants import (
ALIPAY_DEDUPE_MAX_SIZE,
ALIPAY_DEDUPE_TTL_SECONDS,
)
class AlipayMessageDeduplicator:
def __init__(self):
self._cache: dict[str, float] = {}
def is_duplicate(self, msg_id: str) -> bool:
if not msg_id:
return False
now = time.time()
if msg_id in self._cache:
if now - self._cache[msg_id] < ALIPAY_DEDUPE_TTL_SECONDS:
return True
self._cache[msg_id] = now
self._evict_expired(now)
return False
def _evict_expired(self, now: float):
if len(self._cache) > ALIPAY_DEDUPE_MAX_SIZE:
expired = [k for k, v in self._cache.items() if now - v > ALIPAY_DEDUPE_TTL_SECONDS]
for k in expired:
del self._cache[k]