Skip to content

Commit

Permalink
fix: wecom app auth
Browse files Browse the repository at this point in the history
  • Loading branch information
LeslieLeung committed Jan 15, 2024
1 parent f0fd679 commit de3ef5a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions heimdallr/channel/wecom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion heimdallr/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit de3ef5a

Please sign in to comment.