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="企业微信的应用")