From f55e28a6fd82b50b751946a078c345fd49d79473 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Tue, 26 Nov 2019 10:09:51 +0800 Subject: [PATCH] * finish task #6592. --- lib/dingapi/dingapi.class.php | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/lib/dingapi/dingapi.class.php b/lib/dingapi/dingapi.class.php index b6d65323cc..13daecea38 100644 --- a/lib/dingapi/dingapi.class.php +++ b/lib/dingapi/dingapi.class.php @@ -8,6 +8,16 @@ class dingapi private $expires; private $errors = array(); + /** + * Construct + * + * @param string $appKey + * @param string $appSecret + * @param string $agentId + * @param string $apiUrl + * @access public + * @return void + */ public function __construct($appKey, $appSecret, $agentId, $apiUrl = '') { $this->appKey = $appKey; @@ -18,6 +28,12 @@ class dingapi if(!$this->getToken()) return array('result' => 'fail', 'message' => $this->errors); } + /** + * Get token. + * + * @access public + * @return string + */ public function getToken() { if($this->token and (time() - $this->expires) >= 0) return $this->token; @@ -30,6 +46,12 @@ class dingapi return $this->token; } + /** + * Get all users. + * + * @access public + * @return array + */ public function getAllUsers() { $depts = $this->getAllDepts(); @@ -47,6 +69,12 @@ class dingapi return array('result' => 'success', 'data' => $users); } + /** + * Get all depts. + * + * @access public + * @return array + */ public function getAllDepts() { $response = $this->queryAPI($this->apiUrl . "department/list?access_token={$this->token}"); @@ -57,6 +85,14 @@ class dingapi return $deptPairs; } + /** + * Send message + * + * @param string $userList + * @param string $message + * @access public + * @return array + */ public function send($userList, $message) { $curl = curl_init(); @@ -90,6 +126,13 @@ class dingapi return array('result' => 'fail', 'message' => $this->errors); } + /** + * Query API. + * + * @param string $url + * @access public + * @return string + */ public function queryAPI($url) { $response = json_decode(file_get_contents($url)); @@ -99,11 +142,23 @@ class dingapi return false; } + /** + * Check for errors. + * + * @access public + * @return bool + */ public function isError() { return !empty($this->errors); } + /** + * Get errors. + * + * @access public + * @return array + */ public function getErrors() { $errors = $this->errors;