diff --git a/libs/wecom_api/api.py b/libs/wecom_api/api.py index d0068be7..61458f8e 100644 --- a/libs/wecom_api/api.py +++ b/libs/wecom_api/api.py @@ -66,7 +66,7 @@ class WecomClient(): else: raise Exception("未获取用户") - async def send_to_all(self,content:str): + async def send_to_all(self,content:str,agent_id:int): if not self.check_access_token_for_contacts(): self.access_token_for_contacts = await self.get_access_token(self.secret_for_contacts) @@ -77,7 +77,7 @@ class WecomClient(): params = { "touser" : user_ids_string, "msgtype" : "text", - "agentid" : 1000002, + "agentid" : agent_id, "text" : { "content" : content, }, diff --git a/pkg/platform/sources/wecom.py b/pkg/platform/sources/wecom.py index b69e1c67..40632595 100644 --- a/pkg/platform/sources/wecom.py +++ b/pkg/platform/sources/wecom.py @@ -197,7 +197,19 @@ class WecomAdapter(adapter.MessagePlatformAdapter): async def send_message( self, target_type: str, target_id: str, message: platform_message.MessageChain ): - pass + """企业微信目前只有发送给个人的方法, + 构造target_id的方式为前半部分为账户id,后半部分为agent_id,中间使用“|”符号隔开。 + """ + content_list = await WecomMessageConverter.yiri2target(message, self.bot) + parts = target_id.split("|") + user_id = parts[0] + agent_id = int(parts[1]) + if target_type == 'person': + for content in content_list: + if content["type"] == "text": + await self.bot.send_private_msg(user_id,agent_id,content["content"]) + if content["type"] == "image": + await self.bot.send_image(user_id,agent_id,content["media"]) def register_listener( self,