From 546d4ae53db495f19a14ae6020f8187b01d1a225 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Tue, 19 Nov 2019 15:39:23 +0800 Subject: [PATCH] * finish task #6543. --- module/webhook/js/create.js | 4 +-- module/webhook/lang/zh-cn.php | 1 + module/webhook/model.php | 39 +++++++++++++++++++++++++---- module/webhook/view/create.html.php | 5 ++++ module/webhook/view/edit.html.php | 6 ++--- 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/module/webhook/js/create.js b/module/webhook/js/create.js index bd1ccf4900..3d5833ee43 100644 --- a/module/webhook/js/create.js +++ b/module/webhook/js/create.js @@ -3,11 +3,11 @@ $(function() $('#type').change(function() { var type = $(this).val(); - $('#sendTypeTR').toggle(type != 'dingding'); + $('#sendTypeTR').toggle(type != 'dingding' && type != 'dingapi'); $('#secretTR').toggle(type == 'dingding'); $('#urlTR').toggle(type != 'dingapi'); $('.dingapiTR').toggle(type == 'dingapi'); - $('#paramsTR').toggle(type != 'bearychat' && type != 'dingding' && type != 'dingapi'); + $('#paramsTR').toggle(type != 'bearychat' && type != 'dingding' && type != 'dingapi' && type != 'weixin'); $('#urlNote').html(urlNote[type]); }); diff --git a/module/webhook/lang/zh-cn.php b/module/webhook/lang/zh-cn.php index e4035b76ac..efaadc34ef 100644 --- a/module/webhook/lang/zh-cn.php +++ b/module/webhook/lang/zh-cn.php @@ -37,6 +37,7 @@ $lang->webhook->result = '结果'; $lang->webhook->typeList[''] = ''; $lang->webhook->typeList['dingding'] = '钉钉群通知机器人'; $lang->webhook->typeList['dingapi'] = '钉钉工作消息通知'; +$lang->webhook->typeList['weixin'] = '企业微信'; $lang->webhook->typeList['default'] = '其他'; $lang->webhook->sendTypeList['sync'] = '同步'; diff --git a/module/webhook/model.php b/module/webhook/model.php index 05f7951fbb..1029b1aff5 100644 --- a/module/webhook/model.php +++ b/module/webhook/model.php @@ -257,6 +257,7 @@ class webhookModel extends model if($webhook->sendType == 'async') { + if($webhook->type == 'dingapi' and empty($this->getUseridList($webhook->id, $actionID))) continue; $this->saveData($id, $actionID, $postData); continue; } @@ -332,6 +333,10 @@ class webhookModel extends model { $data = $this->getBearychatData($text, $mobile, $email, $objectType, $objectID); } + elseif($webhook->type == 'weixin') + { + $data = $this->getWeixinData($title, $text, $mobile); + } else { $data = new stdclass(); @@ -434,6 +439,29 @@ class webhookModel extends model return $data; } + /** + * Get weixin data. + * + * @param string $title + * @param string $text + * @param string $mobile + * @access public + * @return object + */ + public function getWeixinData($title, $text, $mobile) + { + $data = new stdclass(); + $data->msgtype = 'markdown'; + + $markdown = new stdclass(); + $markdown->content = $text; + + if($mobile) $markdown->mentioned_mobile_list = array($mobile); + + $data->markdown = $markdown; + + return $data; + } /** * Get userid list. @@ -442,7 +470,7 @@ class webhookModel extends model * @access public * @return string */ - public function getUseridList($actionID) + public function getUseridList($webhookID, $actionID) { if(empty($actionID)) return false; @@ -455,7 +483,7 @@ class webhookModel extends model if(!empty($object->mailto)) $toList .= ',' . $object->mailto; if(empty($toList)) return false; - $useridList = $this->getBindUsers($webhook->id, $toList); + $useridList = $this->getBindUsers($webhookID, $toList); $useridList = join(',', $useridList); return $useridList; } @@ -477,16 +505,17 @@ class webhookModel extends model { $webhook->secret = json_decode($webhook->secret); - $useridList = $this->getUseridList($actionID); + $useridList = $this->getUseridList($webhook->id, $actionID); if(empty($useridList)) return false; $this->app->loadClass('dingapi', true); $dingapi = new dingapi($webhook->secret->appKey, $webhook->secret->appSecret, $webhook->secret->agentId); - return $dingapi->send($useridList, $sendData); + $result = $dingapi->send($useridList, $sendData); + return json_encode($result); } $contentType = "Content-Type: {$webhook->contentType};charset=utf-8"; - if($webhook->type == 'dingding') $contentType = "Content-Type: application/json"; + if($webhook->type == 'dingding' or $webhook->type == 'weixin') $contentType = "Content-Type: application/json"; $header[] = $contentType; $url = $webhook->url; diff --git a/module/webhook/view/create.html.php b/module/webhook/view/create.html.php index e473d0f39b..02795aacd0 100644 --- a/module/webhook/view/create.html.php +++ b/module/webhook/view/create.html.php @@ -51,6 +51,11 @@ webhook->dingAppSecret;?> + + webhook->domain;?> + + + webhook->sendType;?> webhook->sendTypeList, '', "class='form-control'");?> diff --git a/module/webhook/view/edit.html.php b/module/webhook/view/edit.html.php index 2a8f54ba18..991d1e96af 100644 --- a/module/webhook/view/edit.html.php +++ b/module/webhook/view/edit.html.php @@ -29,7 +29,7 @@ name, "class='form-control'");?> - + '> webhook->url;?> url, "class='form-control'");?> webhook->note->typeList, $webhook->type, '');?> @@ -60,7 +60,7 @@ domain, "class='form-control'");?> - type != 'dingding'):?> + type != 'dingding' and $webhook->type != 'dingapi'):?> webhook->sendType;?> webhook->sendTypeList, $webhook->sendType, "class='form-control'");?> @@ -77,7 +77,7 @@ projects, "class='form-control chosen' multiple");?> webhook->note->project;?> - type,") === false):?> + type,") === false):?>