$property_name)) { return($this->$property_name); } else { return(NULL); } } public function __construct() { $count = func_num_args(); $args=func_get_args(); if (method_exists($this,$f='__construct'.$count)) { call_user_func_array(array($this,$f),$args); } } public function __construct3($agentToken, $agentSecret, $serverUrl) { $this->agentAccessKey = $agentToken; $this->agentAccessSecret = $agentSecret; $this->serverUrl = $serverUrl; } public function __construct4($agentToken, $agentSecret, $serverUrl, $proxy) { $this->agentAccessKey = $agentToken; $this->agentAccessSecret = $agentSecret; $this->serverUrl = $serverUrl; $this->proxy = $proxy; } /** * HttpHeader constructor. * @param $timestamp * @param $accessToken * @param $signature * @param $version */ public function __construct5($agentToken, $agentSecret, $accessKey, $accessSecret, $serverUrl) { $this->agentAccessKey = $agentToken; $this->agentAccessSecret = $agentSecret; $this->accessKey = $accessKey; $this->accessSecret = $accessSecret; $this->serverUrl = $serverUrl; } /** * SDK POST和GET请求调用封装 * * @param request 请求参数 * @return */ public function service(SdkRequest $request) { $url = $this->serverUrl.$request->getUrl(); $time = $this->get_millistime(); $nonce = $this->get_guid(); $signature = md5(str_replace(' ', '',$this->accessKey.$this->accessSecret.$time.$nonce)); $agentSignature = md5(str_replace(' ', '',$this->agentAccessKey.$this->agentAccessSecret.$time.$nonce)); $httpHeader = new HttpHeader($this->accessKey, $this->agentAccessKey, $time, $signature, $agentSignature,self::SDK_VERSION, $nonce); $httpHeader = $httpHeader->getAgentArray(); $httpParamers = $request->getHttpParamers(); if($httpParamers->isJson()){ $result = doServiceWithJson($url, $httpParamers->getJsonParams(), $httpHeader, self::connectTimeout, self::readTimeout); } else { $result = doService($url, $httpParamers, $httpHeader, self::connectTimeout, self::readTimeout); } if(strpos($url, 'download') === false ){ $result = json_decode($result, true); } return $result; } /** * 下载接口服务 */ public function download(SdkRequest $request, $outputStream) { $url = $this->serverUrl.$request->getUrl(); $time = $this->get_millistime(); $nonce = $this->get_guid(); $signature = null; if(!empty($accessKey)) { $nonce = $this->get_guid(); $signature = md5(str_replace(' ', '',$this->accessKey.$this->accessSecret.$time.$nonce)); } $agentSignature = md5(str_replace(' ', '',$this->agentAccessKey.$this->agentAccessSecret.$time.$nonce)); $httpHeader = new HttpHeader($this->accessKey, $this->agentAccessKey, $time, $signature, $agentSignature,self::SDK_VERSION, $nonce); $httpHeader = $httpHeader->getArray(); $httpParamers = $request->getHttpParamers(); return doDownload($url, $httpParamers, $httpHeader, self::connectTimeout, self::readTimeout, $filePath); } /** * 获取当前时间戳 * @return string */ private function get_millistime(){ $microtime = microtime(); $comps = explode(' ', $microtime); return sprintf('%d%03d', $comps[1], $comps[0] * 1000); } /** * 获取全局uuid * @return string */ private function get_guid(){ mt_srand((double) microtime() * 10000); $charid = md5(uniqid(rand(), true)); $hyphen = chr(45); // “-” $uuid = substr($charid, 0, 8) . $hyphen . substr($charid, 8, 4) . $hyphen . substr($charid, 12, 4) . $hyphen . substr($charid, 16, 4) . $hyphen . substr($charid, 20, 12); return $uuid; } }