From 02624b4cac90d2c8c477162be73c40e578412dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A1=E6=A0=8B?= Date: Tue, 24 Aug 2021 13:32:31 +0800 Subject: [PATCH] * finish task #41677. --- lib/dingapi/dingapi.class.php | 80 ++++++++++++++++++++++++----------- module/webhook/control.php | 8 ++++ 2 files changed, 64 insertions(+), 24 deletions(-) diff --git a/lib/dingapi/dingapi.class.php b/lib/dingapi/dingapi.class.php index d5194d2452..a9d2e2d388 100644 --- a/lib/dingapi/dingapi.class.php +++ b/lib/dingapi/dingapi.class.php @@ -9,12 +9,12 @@ class dingapi private $errors = array(); /** - * Construct - * - * @param string $appKey - * @param string $appSecret - * @param string $agentId - * @param string $apiUrl + * Construct + * + * @param string $appKey + * @param string $appSecret + * @param string $agentId + * @param string $apiUrl * @access public * @return void */ @@ -30,7 +30,7 @@ class dingapi /** * Get token. - * + * * @access public * @return string */ @@ -48,7 +48,7 @@ class dingapi /** * Get users. - * + * * @param string $selectedDepts * @access public * @return array @@ -74,25 +74,57 @@ class dingapi foreach($response->userlist as $user) $users[$user->name] = $user->userid; } + $response = $this->queryAPI($this->apiUrl . "auth/scopes?access_token={$this->token}"); + if(!empty($response->auth_org_scopes->authed_user)) + { + foreach($response->auth_org_scopes->authed_user as $userid) + { + $user = $this->queryAPI($this->apiUrl . "user/get?access_token={$this->token}&userid={$userid}"); + if($this->isError()) + { + $this->getErrors(); + continue; + } + + $users[$user->name] = $user->userid; + } + } + return array('result' => 'success', 'data' => $users); } /** * Get dept tree. - * + * * @access public * @return array */ public function getDeptTree() { - $response = $this->queryAPI($this->apiUrl . "department/list?access_token={$this->token}"); - if($this->isError()) return array('result' => 'fail', 'message' => $this->errors); - - $parentDepts = array(); - foreach($response->department as $dept) + $response = $this->queryAPI($this->apiUrl . "auth/scopes?access_token={$this->token}"); + if(isset($response->auth_org_scopes->authed_dept) and $response->auth_org_scopes->authed_dept[0] != 1) { - $parentID = isset($dept->parentid) ? $dept->parentid : 0; - $parentDepts[$parentID][$dept->id] = $dept->name; + $selectedDepts = array(); + foreach($response->auth_org_scopes->authed_dept as $deptID) + { + $selectedDepts[$deptID] = $deptID; + + $response = $this->queryAPI($this->apiUrl . "department/list?access_token={$this->token}&id=$deptID"); + foreach($response->department as $dept) $selectedDepts[$dept->id] = $dept->id; + } + return array('result' => 'selected', 'data' => $selectedDepts); + } + else + { + $response = $this->queryAPI($this->apiUrl . "department/list?access_token={$this->token}"); + if($this->isError()) return array('result' => 'fail', 'message' => $this->errors); + + $parentDepts = array(); + foreach($response->department as $dept) + { + $parentID = isset($dept->parentid) ? $dept->parentid : 0; + $parentDepts[$parentID][$dept->id] = $dept->name; + } } $tree = array(); @@ -114,10 +146,10 @@ class dingapi } /** - * Send message - * - * @param string $userList - * @param string $message + * Send message + * + * @param string $userList + * @param string $message * @access public * @return array */ @@ -142,8 +174,8 @@ class dingapi /** * Query API. - * - * @param string $url + * + * @param string $url * @access public * @return string */ @@ -162,7 +194,7 @@ class dingapi /** * Check for errors. - * + * * @access public * @return bool */ @@ -173,7 +205,7 @@ class dingapi /** * Get errors. - * + * * @access public * @return array */ diff --git a/module/webhook/control.php b/module/webhook/control.php index 000e7fd5a5..fcc4d174a7 100644 --- a/module/webhook/control.php +++ b/module/webhook/control.php @@ -295,6 +295,14 @@ class webhook extends control die(js::locate($this->createLink('webhook', 'browse'))); } + if($response['result'] == 'selected') + { + $locateLink = $this->createLink('webhook', 'bind', "id={$id}"); + $locateLink .= strpos($locateLink, '?') !== false ? '&' : '?'; + $locateLink .= 'selectedDepts=' . join(',', $response['data']); + die(js::locate($locateLink)); + } + $this->view->title = $this->lang->webhook->chooseDept; $this->view->position[] = $this->lang->webhook->chooseDept;