搭建 legacy_855 独立 provider 骨架

- 新增微信 Gateway 与 Provider 基类,为多版本 server 切换预留入口
- 将 855/859 现有协议实现迁入 providers/legacy_855 独立目录管理
- 保留 WechatAPIClient 旧命名出口,先维持调用面兼容并带上运行资源文件
This commit is contained in:
liuwei
2026-05-07 09:49:06 +08:00
parent 33dea46e1b
commit 99d226c092
15 changed files with 2247 additions and 2 deletions

33
wechat_ipad/gateway.py Normal file
View File

@@ -0,0 +1,33 @@
from typing import Any, Dict, Type
from wechat_ipad.providers.legacy_855 import Legacy855WechatClient
class WechatGateway:
"""按 server_type 选择具体 Provider 的薄网关。
当前策略:
1. Gateway 只负责选择 Provider并把调用透传出去
2. 不在这里承载协议差异或运行时细节,避免再次形成新的“大中台”;
3. 第一阶段默认只完整支持 `legacy_855`,后续接入 864 时在映射表中扩展即可。
"""
_PROVIDER_MAP: Dict[str, Type[Legacy855WechatClient]] = {
"legacy_855": Legacy855WechatClient,
"855": Legacy855WechatClient,
"859": Legacy855WechatClient,
}
def __init__(self, ip: str, port: int, server_type: str = "legacy_855", **kwargs: Any):
normalized_server_type = str(server_type or "legacy_855").strip().lower()
provider_cls = self._PROVIDER_MAP.get(normalized_server_type)
if provider_cls is None:
raise ValueError(f"不支持的 wechat provider 类型: {server_type}")
self.server_type = normalized_server_type
self.provider = provider_cls(ip=ip, port=port, **kwargs)
def __getattr__(self, item: str) -> Any:
"""将未显式实现的属性/方法透传给具体 Provider。"""
return getattr(self.provider, item)