From de3ef5acd3005d5b86e68ad75e4d963bd235fad5 Mon Sep 17 00:00:00 2001 From: Leslie Leung Date: Tue, 16 Jan 2024 00:02:12 +0800 Subject: [PATCH] fix: wecom app auth --- heimdallr/channel/wecom.py | 13 ++++++++----- heimdallr/config/config.py | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/heimdallr/channel/wecom.py b/heimdallr/channel/wecom.py index 3148141..c20bd01 100644 --- a/heimdallr/channel/wecom.py +++ b/heimdallr/channel/wecom.py @@ -7,6 +7,7 @@ from heimdallr.channel.base import Channel, Message from heimdallr.config.config import get_config_str from heimdallr.config.definition import ( + SUFFIX_WECOM_AGENT_ID, SUFFIX_WECOM_CORP_ID, SUFFIX_WECOM_KEY, SUFFIX_WECOM_SECRET, @@ -40,7 +41,7 @@ def render_message(self) -> Any: class WecomAppMessage(Message): msg_type: str - agent_id: str + agent_id: int def __init__(self, title: str, body: str, msg_type: str = "text"): super().__init__(title, body) @@ -99,18 +100,20 @@ def send(self, message: Message): class WecomApp(Channel): base_url: str = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" - corp_id: str = "" - secret: str = "" - access_token: str = "" - agent_id: str = "" + corp_id: str + secret: str + access_token: str + agent_id: int def __init__(self, name: str): super().__init__(name) + self._build_channel() def _build_channel(self) -> None: channel_name = str.upper(self.name) self.corp_id = get_config_str(channel_name, SUFFIX_WECOM_CORP_ID, "") self.secret = get_config_str(channel_name, SUFFIX_WECOM_SECRET, "") + self.agent_id = int(get_config_str(channel_name, SUFFIX_WECOM_AGENT_ID, "")) if self.corp_id == "" or self.secret == "": raise WecomException("corp id or secret not set") diff --git a/heimdallr/config/config.py b/heimdallr/config/config.py index 0879e71..c13e052 100644 --- a/heimdallr/config/config.py +++ b/heimdallr/config/config.py @@ -3,7 +3,7 @@ from environs import Env env = Env() -env.read_env() +env.read_env(recurse=False) def get_config_str(name: str, suffix: str, default: str = "") -> str: