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

43 lines
1.7 KiB
Python

from yuxi.channel.extensions.alipay.types import AlipayAccount, AlipayDmPolicy
class AlipaySecurity:
def __init__(self):
self._allow_from: list[str] = []
def resolve_dm_policy(self, account: AlipayAccount | None = None) -> dict:
if not account:
return {"mode": "disabled", "allow_from": []}
return {
"mode": account.dm_policy.value,
"allow_from": account.allow_from or [],
}
def check_allowlist(self, peer_id: str, channel_type: str = "direct", account: AlipayAccount | None = None) -> bool:
if not account:
return False
if account.dm_policy == AlipayDmPolicy.OPEN:
return True
if account.dm_policy == AlipayDmPolicy.DISABLED:
return False
if account.dm_policy == AlipayDmPolicy.ALLOWLIST:
return peer_id in (account.allow_from or [])
if account.dm_policy == AlipayDmPolicy.PAIRING:
return peer_id in self._allow_from
return False
def add_to_allowlist(self, peer_id: str) -> None:
if peer_id not in self._allow_from:
self._allow_from.append(peer_id)
def collect_warnings(
self, config: dict | None = None, account_id: str | None = None, account: AlipayAccount | None = None
) -> list[str]:
warnings = []
if account:
if account.dm_policy == AlipayDmPolicy.OPEN:
warnings.append("DM 策略为 'open',所有关注者均可发送消息")
if account.dm_policy == AlipayDmPolicy.OPEN and not account.allow_from:
warnings.append("DM 策略为 'open' 且无白名单限制")
return warnings