diff --git a/yuthon_wechat/models/hr_employee.py b/yuthon_wechat/models/hr_employee.py index 00a2922c4..1dcbe3f1c 100644 --- a/yuthon_wechat/models/hr_employee.py +++ b/yuthon_wechat/models/hr_employee.py @@ -90,7 +90,7 @@ class HrEmployee(models.Model): def action_create_user(self): # 测试消息发送 -- success - # self.sudo().env["wecom.apps"].sync_send_message(self.wecom_userid, 1111) + # self.sudo().env["wecom.apps"].sync_send_message(category, self.wecom_userid, 1111) # 传递参数给新创建的用户 self._context["default_oauth_uid"] = self.wecom_userid return super().action_create_user() diff --git a/yuthon_wechat/models/wecom_apps.py b/yuthon_wechat/models/wecom_apps.py index 3112bbf67..3cd337e09 100644 --- a/yuthon_wechat/models/wecom_apps.py +++ b/yuthon_wechat/models/wecom_apps.py @@ -60,8 +60,8 @@ class WeComApps(models.Model): return True, user_list return False, result_data - 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 + def sync_send_message(self, category='default', user_id=None, message=None): + wecom_app = self.sudo().env["wecom.apps.config"].search([("wecom_apps_type", "=", "message_send"), ("wecom_apps_category", "=", category)], limit=1).wecom_apps_id data = { 'touser': user_id, 'msgtype': 'text', @@ -75,6 +75,62 @@ class WeComApps(models.Model): return True, result_data return False, result_data + def sync_send_message_textcard(self, category='default', user_id=None, title="", description="", url="", btntxt="详情"): + """ + touser 否 成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送 + toparty 否 部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数 + totag 否 标签ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数 + msgtype 是 消息类型,此时固定为:textcard + agentid 是 企业应用的id,整型。企业内部开发,可在应用的设置页面查看;第三方服务商,可通过接口 获取企业授权信息 获取该参数值 + title 是 标题,不超过128个字符,超过会自动截断(支持id转译) + description 是 描述,不超过512个字符,超过会自动截断(支持id转译) + url 是 点击后跳转的链接。最长2048字节,请确保包含了协议头(http/https) + btntxt 否 按钮文字。 默认为“详情”, 不超过4个文字,超过自动截断。 + enable_id_trans 否 表示是否开启id转译,0表示否,1表示是,默认0 + enable_duplicate_check 否 表示是否开启重复消息检查,0表示否,1表示是,默认0 + duplicate_check_interval 否 表示是否重复消息检查的时间间隔,默认1800s,最大不超过4小时 + { + "touser" : "UserID1|UserID2|UserID3", + "toparty" : "PartyID1 | PartyID2", + "totag" : "TagID1 | TagID2", + "msgtype" : "textcard", + "agentid" : 1, + "textcard" : { + "title" : "领奖通知", + "description" : "
2016年9月26日
恭喜你抽中iPhone 7一台,领奖码:xxxx
请于2016年10月10日前联系行政同事领取
", + "url" : "URL", + "btntxt":"更多" + }, + "enable_id_trans": 0, + "enable_duplicate_check": 0, + "duplicate_check_interval": 1800 + } + :param category: + :param user_id: + :param title: + :param description: + :param url: + :param btntxt: + :return: + """ + wecom_app = self.sudo().env["wecom.apps.config"].search( + [("wecom_apps_type", "=", "message_send"), ("wecom_apps_category", "=", category)], limit=1).wecom_apps_id + data = { + 'touser': user_id, + 'msgtype': 'textcard', + 'agentid': wecom_app.agent_id, + "textcard": { + "title": title, + "description": description, + "url": url, + "btntxt": btntxt + }, + } + result_data = self.sync_function_api("message_send", "MESSAGE_SEND", data) + if result_data.get("errcode", None) == 0: + return True, result_data + return False, result_data + # def sync_user_create(self, user_id=None, name=None, mobile=None, biz_mail=None, department=None): # data = {} # if user_id: diff --git a/yuthon_wechat/models/wecom_apps_config.py b/yuthon_wechat/models/wecom_apps_config.py index 3bb390669..efd864fdc 100644 --- a/yuthon_wechat/models/wecom_apps_config.py +++ b/yuthon_wechat/models/wecom_apps_config.py @@ -19,5 +19,10 @@ class WecomAppsConfig(models.Model): ('message_send', '发送消息应用'), ('meeting', '会议管理应用'), ], default="default") + wecom_apps_category = fields.Selection( + string='应用场景', + selection=[('default', '默认'), + ('oa', '审批类型'), + ], default="default") wecom_apps_id = fields.Many2one("wecom.apps", string="企业微信的应用") diff --git a/yuthon_wechat/views/wecom_apps_config_views.xml b/yuthon_wechat/views/wecom_apps_config_views.xml index edcb402f9..7a42c8674 100644 --- a/yuthon_wechat/views/wecom_apps_config_views.xml +++ b/yuthon_wechat/views/wecom_apps_config_views.xml @@ -7,6 +7,7 @@ + @@ -20,6 +21,7 @@ +