Files
abot/wechat_ipad/gateway.py
liuwei 99d226c092 搭建 legacy_855 独立 provider 骨架
- 新增微信 Gateway 与 Provider 基类,为多版本 server 切换预留入口
- 将 855/859 现有协议实现迁入 providers/legacy_855 独立目录管理
- 保留 WechatAPIClient 旧命名出口,先维持调用面兼容并带上运行资源文件
2026-05-07 09:49:06 +08:00

34 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)