* finish task #7274.

This commit is contained in:
z
2020-06-28 11:26:54 +08:00
parent 2b00714695
commit 7ab4e53714
6 changed files with 154 additions and 22 deletions
+26 -5
View File
@@ -7,6 +7,7 @@ class dingapi
private $token;
private $expires;
private $errors = array();
public $maxRequest = 100;
/**
* Construct
@@ -52,10 +53,11 @@ class dingapi
* @access public
* @return array
*/
public function getAllUsers()
public function getAllUsers($whiteListDept = '')
{
$depts = $this->getAllDepts();
$depts = $this->getAllDepts($whiteListDept);
if($this->isError()) return array('result' => 'fail', 'message' => $this->errors);
if(empty($whiteListDept) and count($depts) > $this->maxRequest) return array('result' => 'fail', 'message' => 'moreRequest');
set_time_limit(0);
$users = array();
@@ -80,12 +82,11 @@ class dingapi
* @access public
* @return array
*/
public function getAllDepts()
public function getAllDepts($whiteList = '')
{
$response = $this->queryAPI($this->apiUrl . "department/list?access_token={$this->token}");
if($this->isError()) return false;
$whiteList = array();
if($whiteList)
{
$parentIdList = array();
@@ -93,7 +94,7 @@ class dingapi
foreach($response->department as $dept)
{
if(!empty($dept->parentid)) $parentIdList[$dept->id] = $dept->parentid;
if(in_array($dept->name, $whiteList)) $whiteListParent[$dept->id] = $dept->id;
if(strpos(",{$whiteList},", ",{$dept->id},") !== false) $whiteListParent[$dept->id] = $dept->id;
}
}
@@ -129,6 +130,26 @@ class dingapi
return $deptPairs;
}
/**
* Get top depts.
*
* @access public
* @return array
*/
public function getTopDepts()
{
$response = $this->queryAPI($this->apiUrl . "department/list?access_token={$this->token}");
if($this->isError()) return array('result' => 'fail', 'message' => $this->errors);
$topDepts = array();
foreach($response->department as $dept)
{
if(isset($dept->parentid) and $dept->parentid == '1') $topDepts[$dept->id] = $dept->name;
}
return array('result' => 'success', 'data' => $topDepts);
}
/**
* Send message
*