* finish task #6543.

This commit is contained in:
wangyidong
2019-11-19 15:39:23 +08:00
parent b4b96c2101
commit 546d4ae53d
5 changed files with 45 additions and 10 deletions

View File

@@ -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]);
});

View File

@@ -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'] = '同步';

View File

@@ -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;

View File

@@ -51,6 +51,11 @@
<th><?php echo $lang->webhook->dingAppSecret;?></th>
<td><?php echo html::input('appSecret', '', "class='form-control'");?></td>
</tr>
<tr>
<th><?php echo $lang->webhook->domain;?></th>
<td><?php echo html::input('domain', common::getSysURL(), "class='form-control'");?></td>
<td></td>
</tr>
<tr id='sendTypeTR'>
<th><?php echo $lang->webhook->sendType;?></th>
<td><?php echo html::select('sendType', $lang->webhook->sendTypeList, '', "class='form-control'");?></td>

View File

@@ -29,7 +29,7 @@
<td><?php echo html::input('name', $webhook->name, "class='form-control'");?></td>
<td></td>
</tr>
<tr id='urlTR' class='hidden'>
<tr id='urlTR' class='<?php echo $webhook->type == 'dingapi' ? 'hidden' : '';?>'>
<th><?php echo $lang->webhook->url;?></th>
<td><?php echo html::input('url', $webhook->url, "class='form-control'");?></td>
<td><?php echo zget($lang->webhook->note->typeList, $webhook->type, '');?></td>
@@ -60,7 +60,7 @@
<td><?php echo html::input('domain', $webhook->domain, "class='form-control'");?></td>
<td></td>
</tr>
<?php if($webhook->type != 'dingding'):?>
<?php if($webhook->type != 'dingding' and $webhook->type != 'dingapi'):?>
<tr>
<th><?php echo $lang->webhook->sendType;?></th>
<td><?php echo html::select('sendType', $lang->webhook->sendTypeList, $webhook->sendType, "class='form-control'");?></td>
@@ -77,7 +77,7 @@
<td><?php echo html::select('projects[]', $projects, $webhook->projects, "class='form-control chosen' multiple");?></td>
<td><?php echo $lang->webhook->note->project;?></td>
</tr>
<?php if(strpos(',bearychat,dingding,dingapi,', ",$webhook->type,") === false):?>
<?php if(strpos(',bearychat,dingding,dingapi,weixin,', ",$webhook->type,") === false):?>
<tr id='paramsTR'>
<th>
<div class='checkbox-primary'>