From 82e16054c7ed928074cf1d109fbaf83014e2f4d3 Mon Sep 17 00:00:00 2001 From: pengyuthon Date: Wed, 3 Jul 2024 22:11:28 +0800 Subject: [PATCH] =?UTF-8?q?ljm:=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1=20?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuthon_wechat/models/hr_employee.py | 3 +++ yuthon_wechat/models/wecom_apps.py | 5 +++-- yuthon_wechat/models/wecom_apps_config.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/yuthon_wechat/models/hr_employee.py b/yuthon_wechat/models/hr_employee.py index 06aed2986..9c06762f0 100644 --- a/yuthon_wechat/models/hr_employee.py +++ b/yuthon_wechat/models/hr_employee.py @@ -52,6 +52,9 @@ class HrEmployee(models.Model): pass def action_create_user(self): + # 测试消息发送 + # self.sudo().env["wecom.apps"].sync_send_message(self.wecom_userid, 1111) + # 传递参数给新创建的用户 self._context["default_oauth_uid"] = self.wecom_userid self._context["login"] = self.work_email return super().action_create_user() diff --git a/yuthon_wechat/models/wecom_apps.py b/yuthon_wechat/models/wecom_apps.py index 691ae5495..a9daae525 100644 --- a/yuthon_wechat/models/wecom_apps.py +++ b/yuthon_wechat/models/wecom_apps.py @@ -59,13 +59,14 @@ class WeComApps(models.Model): return user_list def sync_send_message(self, user_id, message): + wecom_app = self.sudo().env["wecom.apps.config"].search([("wecom_apps_type", "=", "MESSAGE_SEND")], limit=1).wecom_apps_id data = { 'touser': user_id, 'msgtype': 'text', - 'agentid': self.agent_id, + 'agentid': wecom_app.agent_id, 'text': { 'content': message } } - result_data = self.sync_function_api("SEND_MESSAGE", "SEND_MESSAGE", data) + result_data = self.sync_function_api("MESSAGE_SEND", "MESSAGE_SEND", data) return result_data diff --git a/yuthon_wechat/models/wecom_apps_config.py b/yuthon_wechat/models/wecom_apps_config.py index 67d0ed0be..add5ba005 100644 --- a/yuthon_wechat/models/wecom_apps_config.py +++ b/yuthon_wechat/models/wecom_apps_config.py @@ -16,7 +16,7 @@ class WecomAppsConfig(models.Model): ('USER_LIST', '员工同步应用'), ('DEPARTMENT_LIST', '部门同步应用'), ('login', '登录验证应用'), - ('SEND_MESSAGE', '发送消息应用'), + ('MESSAGE_SEND', '发送消息应用'), ], default="default") wecom_apps_id = fields.Many2one("wecom.apps", string="企业微信的应用")