* adjust for feishu webhook.

This commit is contained in:
wangyidong
2021-01-29 13:15:50 +08:00
parent 5db4e3a0f7
commit fc5adc765c
10 changed files with 91 additions and 29 deletions
+45 -4
View File
@@ -55,17 +55,58 @@ class feishuapi
public function getAllUsers()
{
set_time_limit(0);
$users = array();
$response = $this->queryAPI($this->apiUrl . "contact/v3/users", json_encode(array('department_id' => 0)), array(CURLOPT_CUSTOMREQUEST => "GET"));
if(isset($response->data->items))
$users = array();
$depts = $this->getDepts();
foreach($depts as $deptID => $count)
{
foreach($response->data->items as $user) $users[$user->name] = $user->open_id;
if($deptID and empty($count)) continue;
$pageToken = '';
while(true)
{
$response = $this->queryAPI($this->apiUrl . "contact/v3/users?department_id={$deptID}" . ($pageToken ? "&page_token={$pageToken}" : ''), '', array(CURLOPT_CUSTOMREQUEST => "GET"));
if(isset($response->data->items))
{
foreach($response->data->items as $user) $users[$user->name] = $user->open_id;
}
if(!isset($response->data->page_token)) break;
$pageToken = $response->data->page_token;
}
}
return array('result' => 'success', 'data' => $users);
}
/**
* Get depts.
*
* @access public
* @return array
*/
public function getDepts()
{
set_time_limit(0);
$depts = array('0' => '0');
$pageToken = '';
while(true)
{
$response = $this->queryAPI($this->apiUrl . "contact/v3/departments?parent_department_id=0" . ($pageToken ? "&page_token={$pageToken}" : '') . "&fetch_child=true", '', array(CURLOPT_CUSTOMREQUEST => "GET"));
if(isset($response->data->items))
{
foreach($response->data->items as $dept) $depts[$dept->open_department_id] = $dept->member_count;
}
if(!isset($response->data->page_token)) break;
$pageToken = $response->data->page_token;
}
return $depts;
}
/**
* Send message
*
+2 -2
View File
@@ -185,7 +185,7 @@ class webhook extends control
}
$webhook = $this->webhook->getById($id);
if($webhook->type != 'dinguser' && $webhook->type != 'wechatuser' && $webhook->type != 'feishu')
if($webhook->type != 'dinguser' && $webhook->type != 'wechatuser' && $webhook->type != 'feishuuser')
{
echo js::alert($this->lang->webhook->note->bind);
die(js::locate($this->createLink('webhook', 'browse')));
@@ -212,7 +212,7 @@ class webhook extends control
$wechatApi = new wechatapi($webhook->secret->appKey, $webhook->secret->appSecret, $webhook->secret->agentId);
$response = $wechatApi->getAllUsers();
}
elseif($webhook->type == 'feishu')
elseif($webhook->type == 'feishuuser')
{
$this->app->loadClass('feishuapi', true);
$feishuApi = new feishuapi($webhook->secret->appId, $webhook->secret->appSecret);
+7 -4
View File
@@ -21,8 +21,11 @@ $(function ()
$(".bind").on("click",function()
{
var inputName = this.getAttribute("data-value");
$("#saveInput").html();
var $obj = $(this);
var inputName = $obj.attr("data-value");
$("#saveInput").html("<input type='hidden' name='" + inputName + "' value=''>");
myModalTrigger.show();
});
myModalTrigger.show({shown:function()
{
$('#triggerModal #userSelect').val($obj.closest('tr').find("[id^=userid]").val()).trigger('chosen:updated');
}});
});
+5 -5
View File
@@ -3,13 +3,13 @@ $(function()
$('#type').change(function()
{
var type = $(this).val();
$('#sendTypeTR').toggle(type != 'dinggroup' && type != 'dinguser' && type != 'wechatuser' && type != 'wechatgroup' && type != 'feishu');
$('#secretTR').toggle(type == 'dinggroup');
$('#urlTR').toggle(type != 'dinguser' && type != 'wechatuser' && type != 'feishu');
$('#sendTypeTR').toggle(type != 'dinggroup' && type != 'dinguser' && type != 'wechatuser' && type != 'wechatgroup' && type != 'feishuuser' && type != 'feishugroup');
$('#secretTR').toggle(type == 'dinggroup' || type == 'feishugroup');
$('#urlTR').toggle(type != 'dinguser' && type != 'wechatuser' && type != 'feishuuser');
$('.dinguserTR').toggle(type == 'dinguser');
$('.wechatTR').toggle(type == 'wechatuser');
$('.feishuTR').toggle(type == 'feishu');
$('#paramsTR').toggle(type != 'bearychat' && type != 'dinggroup' && type != 'dinguser' && type != 'wechatuser' && type != 'wechatgroup' && type != 'feishu');
$('.feishuTR').toggle(type == 'feishuuser');
$('#paramsTR').toggle(type != 'bearychat' && type != 'dinggroup' && type != 'dinguser' && type != 'wechatuser' && type != 'wechatgroup' && type != 'feishuuser' && type != 'feishugroup');
$('#urlNote').html(urlNote[type]);
});
+2 -1
View File
@@ -40,7 +40,8 @@ $lang->webhook->typeList['dinggroup'] = '钉钉群通知机器人';
$lang->webhook->typeList['dinguser'] = '钉钉工作消息通知';
$lang->webhook->typeList['wechatgroup'] = '企业微信群机器人';
$lang->webhook->typeList['wechatuser'] = '企业微信应用消息';
$lang->webhook->typeList['feishu'] = '飞书工作消息通知';
$lang->webhook->typeList['feishugroup'] = '飞书群通知机器人';
$lang->webhook->typeList['feishuuser'] = '飞书工作消息通知';
$lang->webhook->typeList['default'] = '其他';
$lang->webhook->sendTypeList['sync'] = '同步';
+24 -6
View File
@@ -96,6 +96,11 @@ class webhookModel extends model
{
$text = substr($data->markdown->content, 0, strpos($data->markdown->content, '(http'));
}
elseif(isset($data->content))
{
$text = $data->content->text;
$text = substr($text, 0, strpos($text, '(http')) ? substr($text, 0, strpos($text, '(http')) : zget($users, $data->user, $this->app->user->realname) . $this->lang->action->label->{$action->action} . $this->lang->action->objectTypes[$action->objectType] . "[#{$action->objectID}::{$object->$field}]";
}
else
{
$text = substr($data->text, 0, strpos($data->text, '(http')) ? substr($data->text, 0, strpos($data->text, '(http')) : zget($users, $data->user, $this->app->user->realname) . $this->lang->action->label->{$action->action} . $this->lang->action->objectTypes[$action->objectType] . "[#{$action->objectID}::{$object->$field}]";
@@ -188,7 +193,7 @@ class webhookModel extends model
$webhook->secret = json_encode($webhook->secret);
$webhook->url = $this->config->webhook->wechatApiUrl;
}
elseif($webhook->type == 'feishu')
elseif($webhook->type == 'feishuuser')
{
$webhook->secret = array();
$webhook->secret['appId'] = $webhook->feishuAppId;
@@ -259,7 +264,7 @@ class webhookModel extends model
$webhook->secret = json_encode($webhook->secret);
}
elseif($webhook->type == 'feishu')
elseif($webhook->type == 'feishuuser')
{
$webhook->secret = array();
$webhook->secret['appId'] = $webhook->feishuAppId;
@@ -418,7 +423,7 @@ class webhookModel extends model
{
$data = $this->getWeixinData($title, $text, $mobile);
}
elseif($webhook->type == 'feishu')
elseif($webhook->type == 'feishuuser')
{
$data = $this->getFeishuData($title, $text);
}
@@ -595,7 +600,7 @@ class webhookModel extends model
{
if(!extension_loaded('curl')) die(helper::jsonEncode($this->lang->webhook->error->curl));
if($webhook->type == 'dinguser' || $webhook->type == 'wechatuser' || $webhook->type == 'feishu')
if($webhook->type == 'dinguser' || $webhook->type == 'wechatuser' || $webhook->type == 'feishuuser')
{
if(is_string($webhook->secret)) $webhook->secret = json_decode($webhook->secret);
@@ -615,7 +620,7 @@ class webhookModel extends model
$result = $wechatapi->send($openIdList, $sendData);
return json_encode($result);
}
elseif($webhook->type == 'feishu')
elseif($webhook->type == 'feishuuser')
{
$this->app->loadClass('feishuapi', true);
$feishuapi = new feishuapi($webhook->secret->appId, $webhook->secret->appSecret);
@@ -625,7 +630,7 @@ class webhookModel extends model
}
$contentType = "Content-Type: {$webhook->contentType};charset=utf-8";
if($webhook->type == 'dinggroup' or $webhook->type == 'wechatgroup') $contentType = "Content-Type: application/json";
if($webhook->type == 'dinggroup' or $webhook->type == 'wechatgroup' or $webhook->type == 'feishugroup') $contentType = "Content-Type: application/json";
$header[] = $contentType;
$url = $webhook->url;
@@ -636,6 +641,19 @@ class webhookModel extends model
$sign = urlencode(base64_encode(hash_hmac('sha256', $sign, $webhook->secret, true)));
$url .= "&timestamp={$timestamp}&sign={$sign}";
}
if($webhook->type == 'feishugroup' and $webhook->secret)
{
$timestamp = time();
$sign = $timestamp . "\n" . $webhook->secret;
$sign = base64_encode(hash_hmac('sha256', '', $sign, true));
$content = array();
$content['timestamp'] = $timestamp;
$content['sign'] = $sign;
$content['msg_type'] = 'text';
$content['content'] = json_decode($sendData);
$sendData = json_encode($content);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
+2 -2
View File
@@ -13,7 +13,7 @@
<?php
if($webhook->type == 'dinguser') echo $lang->webhook->dingUserid;
if($webhook->type == 'wechatuser') echo $lang->webhook->wechatUserid;
if($webhook->type == 'feishu') echo $lang->webhook->feishuUserid;
if($webhook->type == 'feishuuser') echo $lang->webhook->feishuUserid;
?>
</th>
<th class='w-100px'><?php echo $lang->actions;?></th>
@@ -21,7 +21,7 @@
<?php
if($webhook->type == 'dinguser') echo $lang->webhook->dingBindStatus;
if($webhook->type == 'wechatuser') echo $lang->webhook->wechatBindStatus;
if($webhook->type == 'feishu') echo $lang->webhook->feishuBindStatus;
if($webhook->type == 'feishuuser') echo $lang->webhook->feishuBindStatus;
?>
</th>
</tr>
+1 -1
View File
@@ -35,7 +35,7 @@
<td class='c-actions text-right'>
<?php
if($webhook->type == 'dinguser') common::printIcon('webhook', 'chooseDept', "webhookID=$id", '', 'list', 'link');
if($webhook->type == 'wechatuser' or $webhook->type == 'feishu') common::printIcon('webhook', 'bind', "webhookID=$id", '', 'list', 'link');
if($webhook->type == 'wechatuser' or $webhook->type == 'feishuuser') common::printIcon('webhook', 'bind', "webhookID=$id", '', 'list', 'link');
common::printIcon('webhook', 'log', "webhookID=$id", '', 'list', 'file-text');
common::printIcon('webhook', 'edit', "webhookID=$id", '', 'list');
if(common::hasPriv('webhook', 'delete'))
-1
View File
@@ -70,7 +70,6 @@
<tr class='feishuTR'>
<th><?php echo $lang->webhook->feishuAppId;?></th>
<td class='required'><?php echo html::input('feishuAppId', '', "class='form-control'");?></td>
<td><?php echo $lang->webhook->note->dingHelp;?></td>
</tr>
<tr class='feishuTR'>
<th><?php echo $lang->webhook->feishuAppSecret;?></th>
+3 -3
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='<?php echo strpos("dinguser|wechatuser|feishu", $webhook->type) !== false ? 'hidden' : '';?>'>
<tr id='urlTR' class='<?php echo strpos("dinguser|wechatuser|feishuuser", $webhook->type) !== false ? '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>
@@ -74,7 +74,7 @@
<td></td>
</tr>
<?php endif;?>
<?php if($webhook->type == 'feishu'):?>
<?php if($webhook->type == 'feishuuser'):?>
<?php $secret = json_decode($webhook->secret);?>
<tr class="feishuTR">
<th><?php echo $lang->webhook->feishuAppId;?></th>
@@ -91,7 +91,7 @@
<td><?php echo html::input('domain', $webhook->domain, "class='form-control'");?></td>
<td></td>
</tr>
<?php if(strpos("dinggroup|dinguser|wechatgroup|wechatuser|feishu", $webhook->type) === false):?>
<?php if(strpos("dinggroup|dinguser|wechatgroup|wechatuser|feishuuser", $webhook->type) === false):?>
<tr>
<th><?php echo $lang->webhook->sendType;?></th>
<td><?php echo html::select('sendType', $lang->webhook->sendTypeList, $webhook->sendType, "class='form-control'");?></td>