$property_name)) { return($this->$property_name); } else { return(NULL); } } public function __construct($accessKey,$accessSecret,$serverUrl) { $this->accessKey = $accessKey; $this->accessSecret = $accessSecret; $this->serverUrl = $serverUrl; } /** * 普通接口服务 * @param SdkRequest $baseRequest * @return mixed|null|string */ public function service(SdkRequest $baseRequest) { $url = $this->serverUrl.$baseRequest->getUrl(); $time = $this->get_millistime(); $nonce = $this->get_guid(); $signature = md5(str_replace(' ', '',$this->accessKey.$this->accessSecret.$time.$nonce)); $httpHeader = new HttpHeader($this->accessKey, $time, $signature, self::SDK_VERSION, $nonce); $httpHeader = $httpHeader->getArray(); $httpParamers = $baseRequest->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; } /** * 下载接口服务 * @param SdkRequest $baseRequest * @param $filePath * @return mixed|null|string */ public function downloadService(SdkRequest $baseRequest, $filePath) { $url = $this->serverUrl.$baseRequest->getUrl(); $time = $this->get_millistime(); $nonce = $this->get_guid(); $signature = md5(str_replace(' ', '',$this->accessKey.$this->accessSecret.$time.$nonce)); $httpHeader = new HttpHeader($this->accessKey, $time, $signature, self::SDK_VERSION, $nonce); $httpHeader = $httpHeader->getArray(); $httpParamers = $baseRequest->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; } }