123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <?php
- namespace Api;
- abstract class AliyunSdk
- {
-
- protected $AccessKey = null;
-
- protected $AccessKeySecret = null;
-
- protected $autoLoadPath = [];
-
- protected $showError = false;
-
- protected $request = [];
-
- protected $client = null;
-
- protected $action = [];
-
- protected $config;
-
- protected static $instance = null;
-
- protected static $errorInfo = null;
-
- protected function __construct($cofing = [])
- {
- $this->AccessKey = isset($cofing['AccessKey']) ? $cofing['AccessKey'] : null;
- $this->AccessKeySecret = isset($cofing['AccessKeySecret']) ? $cofing['AccessKeySecret'] : null;
- $this->config = $cofing;
- $this->autoLoaderClass();
- $this->_initialize();
- }
-
- protected function autoLoaderClass()
- {
- if ($this->autoLoadPath) {
- require_once(ROOT_PATH . '/extend/Api/aliyun/aliyun-php-sdk-core/Config.php');
- foreach ($this->autoLoadPath as $item) {
- \Autoloader::addAutoloadPath('aliyun-php-sdk-' . $item);
- }
- }
- }
-
- abstract protected function _initialize();
-
- protected static function setErrorInfo($error, $thsiAction = null)
- {
- $_this = self::instance();
- $request = \think\Request::instance();
- if ($error instanceof \Exception) {
- self::$errorInfo = [
- 'line' => $error->getLine(),
- 'msg' => $error->getMessage(),
- 'code' => $error->getCode(),
- 'file' => $error->getFile(),
- ];
- (!$request->isAjax() && $_this->showError) && dump([
- 'msg' => $error->getMessage(),
- 'code' => $error->getCode(),
- 'file' => $error->getFile(),
- 'line' => $error->getLine(),
- 'action' => $thsiAction,
- ]);
- } else {
- self::$errorInfo = $error;
- (!$request->isAjax() && $_this->showError) && dump($error);
- }
- return false;
- }
-
- public static function getErrorInfo($error = '')
- {
- if (is_null(self::$errorInfo)) self::$errorInfo = $error;
- $errorInfo = self::$errorInfo;
- self::$errorInfo = null;
- if (!is_array($errorInfo)) {
- return ['msg' => $errorInfo];
- }
- return $errorInfo;
- }
-
- public static function instance($cofing = [])
- {
- if (is_null(self::$instance)) self::$instance = new static($cofing);
- return self::$instance;
- }
-
- public static function setTimeFormat($time = '')
- {
- $time = $time ? $time : time();
- if (is_string($time)) {
- if ((int)$time == 0) {
- $data = date("Y-m-d\\TH:i:s\\Z", strtotime($time));
- } else {
- $data = date("Y-m-d\\TH:i:s\\Z", $time);
- }
- } else {
- $data = date("Y-m-d\\TH:i:s\\Z", $time);
- }
- return $data;
- }
-
- public function setShowError($showError)
- {
- $this->showError = $showError;
- return $this;
- }
-
- public function setAccessKey($AccessKey)
- {
- $this->AccessKey = $AccessKey;
- return $this;
- }
-
- public function setAccessKeySecret($AccessKeySecret)
- {
- $this->AccessKeySecret = $AccessKeySecret;
- return $this;
- }
- }
|