|
|
@@ -5,14 +5,11 @@ if (!defined('IN_ONLINE')) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Description of utilsclass
|
|
|
+ * Description of dms_edoc
|
|
|
*
|
|
|
* @author Administrator
|
|
|
*/
|
|
|
-class utils {
|
|
|
- private static $cachedToken = null;
|
|
|
- private static $tokenExpiryTime = 0;
|
|
|
-
|
|
|
+class dms_edoc {
|
|
|
/**
|
|
|
* 获取文件
|
|
|
*/
|
|
|
@@ -30,25 +27,21 @@ class utils {
|
|
|
$grant_type = 'client_credentials';
|
|
|
$client_id = 'online';
|
|
|
$client_secret = 'ouuRZ8QbIrcqKZi0NBJLt7PUEiRr5uXd';
|
|
|
- $accessToken = utils::getAccessToken($accessTokenUrl,$grant_type,$client_id,$client_secret);
|
|
|
+ $accessToken = dms_edoc::getAccessToken($accessTokenUrl,$grant_type,$client_id,$client_secret);
|
|
|
if ($accessToken === null) {
|
|
|
throw new Exception("Failed to obtain access token");
|
|
|
}
|
|
|
|
|
|
$New_Dms_Url = 'http://dms.kln.com/edoc/documents/fileList';
|
|
|
- $result = utils::CURLClient($New_Dms_Url,$accessToken,$data);
|
|
|
+ $result = dms_edoc::CURLClient($New_Dms_Url,$accessToken,$data);
|
|
|
} catch (Exception $e) {
|
|
|
- error_log("Error in downloadFiles: " . $e->getMessage());
|
|
|
+ error_log("Error getEdocFile: " . $e->getMessage());
|
|
|
}
|
|
|
return $result;
|
|
|
|
|
|
}
|
|
|
|
|
|
public static function getAccessToken($accessTokenUrl,$grant_type,$client_id,$client_secret){
|
|
|
- if (self::$cachedToken !== null && time() * 1000 < self::$tokenExpiryTime) {
|
|
|
- return self::$cachedToken;
|
|
|
- }
|
|
|
-
|
|
|
$postData = http_build_query([
|
|
|
'grant_type' => $grant_type,
|
|
|
'client_id' => $client_id,
|
|
|
@@ -83,15 +76,9 @@ class utils {
|
|
|
if ($httpCode === 200) {
|
|
|
$jsonResponse = json_decode($response, true);
|
|
|
if (isset($jsonResponse['access_token'])) {
|
|
|
- self::$cachedToken = $jsonResponse['access_token'];
|
|
|
- //计算过期时间,但是换算成毫秒*1000
|
|
|
- $expiresIn = isset($jsonResponse['expires_in']) ? $jsonResponse['expires_in'] * 1000 : 0;
|
|
|
- self::$tokenExpiryTime = (time() * 1000) + $expiresIn - 300000;
|
|
|
- return self::$cachedToken;
|
|
|
+ return $jsonResponse['access_token'];
|
|
|
}
|
|
|
}
|
|
|
- self::$cachedToken = null;
|
|
|
- self::$tokenExpiryTime = 0;
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@@ -137,12 +124,11 @@ class utils {
|
|
|
$result = json_decode($response, true);
|
|
|
if ($httpCode == 200 && isset($result['data'])) {
|
|
|
return json_encode($result['data'], JSON_UNESCAPED_UNICODE);
|
|
|
- }else{
|
|
|
- return null;
|
|
|
}
|
|
|
} catch (Exception $e) {
|
|
|
error_log($e->getMessage());
|
|
|
}
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
}
|