* change for dingding.

This commit is contained in:
wangyidong
2019-10-31 11:08:41 +08:00
parent ef3f6af06f
commit e3e8ae1792
6 changed files with 28 additions and 3 deletions

1
db/update11.6.4.sql Normal file
View File

@@ -0,0 +1 @@
ALTER TABLE `zt_webhook` ADD `secret` varchar(255) COLLATE 'utf8_general_ci' NOT NULL AFTER `domain`;

View File

@@ -4,6 +4,7 @@ $(function()
{
var type = $(this).val();
$('#sendTypeTR').toggle(type != 'dingding');
$('#secretTR').toggle(type == 'dingding');
$('#paramsTR').toggle(type != 'bearychat' && type != 'dingding');
$('#urlNote').html(urlNote[type]);
});
@@ -33,5 +34,6 @@ $(function()
});
$('#name').focus();
$('#type').change();
$('#paramstext').attr('disabled', 'disabled');
});

View File

@@ -19,6 +19,7 @@ $lang->webhook->url = 'Hook地址';
$lang->webhook->domain = '禅道域名';
$lang->webhook->contentType = '内容类型';
$lang->webhook->sendType = '发送方式';
$lang->webhook->secret = '密钥';
$lang->webhook->product = "关联{$lang->productCommon}";
$lang->webhook->project = "关联{$lang->projectCommon}";
$lang->webhook->params = '参数';

View File

@@ -379,10 +379,21 @@ class webhookModel extends model
{
if(!extension_loaded('curl')) die(helper::jsonEncode($this->lang->webhook->error->curl));
$header[] = "Content-Type: {$webhook->contentType};charset=utf-8";
$contentType = "Content-Type: {$webhook->contentType};charset=utf-8";
if($webhook->type == 'dingding') $contentType = "Content-Type: application/json";
$header[] = $contentType;
$url = $webhook->url;
if($webhook->type == 'dingding' and $webhook->secret)
{
$timestamp = time() * 1000;
$sign = $timestamp . "\n" . $webhook->secret;
$sign = urlencode(base64_encode(hash_hmac('sha256', $sign, $webhook->secret, true)));
$url .= "&timestamp={$timestamp}&sign={$sign}";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $webhook->url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

View File

@@ -35,6 +35,10 @@
<td><?php echo html::input('url', '', "class='form-control'");?></td>
<td id='urlNote'><?php echo $lang->webhook->note->typeList['default'];?></td>
</tr>
<tr id='secretTR'>
<th><?php echo $lang->webhook->secret;?></th>
<td><?php echo html::input('secret', '', "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>

View File

@@ -21,7 +21,7 @@
<table class='table table-form'>
<tr>
<th class='thWidth'><?php echo $lang->webhook->type;?></th>
<td><?php echo html::select('type', $lang->webhook->typeList, $webhook->type, "class='form-control'");?></td>
<td><?php echo zget($lang->webhook->typeList, $webhook->type);?></td>
<td></td>
</tr>
<tr>
@@ -34,6 +34,12 @@
<td><?php echo html::input('url', $webhook->url, "class='form-control'");?></td>
<td><?php echo zget($lang->webhook->note->typeList, $webhook->type);?></td>
</tr>
<?php if($webhook->type == 'dingding'):?>
<tr id='secretTR'>
<th><?php echo $lang->webhook->secret;?></th>
<td><?php echo html::input('secret', $webhook->secret, "class='form-control'");?></td>
</tr>
<?php endif;?>
<tr>
<th><?php echo $lang->webhook->domain;?></th>
<td><?php echo html::input('domain', $webhook->domain, "class='form-control'");?></td>