$name = $value; } public function __get($name){ return $this->$name; } public function setSignRet($signRet) { $signRetStr = $signRet?'true':'false'; $this->signRet = $signRet; $this->addParam($this->Config->SIGN_RETURN, $signRetStr); } public function setSignAlg($signAlg) { $this->signAlg = $signAlg; } public function setEncrypt($encrypt) { $this->encrypt = $encrypt; } public function setVersion($version) { $this->version = $version; } public function setMethod($method) { $this->method = $method; } public function __construct($appKey='', $secretKey=null, $yopPublicKey=null,$serverRoot=null) { //定义构造函数 $this->config = new YopConfig(); $this->requestId = YopRequest::uuid(); if(!empty($appKey)){ $this->appKey = $appKey; } else{ $this->appKey = $this->config->appKey; } if(!empty($secretKey)){ $this->secretKey = $secretKey; } else{ $this->secretKey = $this->config->getSecret(); } if(!empty($yopPublicKey)){ $this->yopPublicKey = $yopPublicKey; } else{ $this->yopPublicKey = $this->config->publickey; } if(!empty($serverRoot)){ $this->serverRoot = $serverRoot; } else{ $this->serverRoot = $this->config->serverRoot; } } public function addParam($key,$values){ if ("_file"==$key) { YopRequest::addFile($key,$values); } else { $addParam = array($key=>$values); $this->paramMap = array_merge($this->paramMap,$addParam); } } public function addFile($key,$values){ $this->ignoreSignParams = array_push($this->ignoreSignParams,$key); $addFile = array($key=>$values); $this->fileMap = array_merge($this->fileMap,$addFile); } public function removeParam($key){ foreach ($this->paramMap as $k => $v){ if($key == $k){ unset($this->paramMap[$k]); } } } public function getParam($key){ return $this->paramMap[$key]; } public function setJsonParam($jsonParam){ $this->jsonParam = $jsonParam; } public function getJsonParam(){ return $this->jsonParam; } public function encoding(){ foreach ($this->paramMap as $k=>$v){ $this->paramMap[$k] = urlencode($v); } } /** * 将参数转换成k=v拼接的形式 */ public function toQueryString(){ $StrQuery=""; foreach ($this->paramMap as $k=>$v){ $StrQuery .= strlen($StrQuery) == 0 ? "" : "&"; $StrQuery.=$k."=".urlencode($v); } return $StrQuery; } private function uuid($namespace = '') { static $guid = ''; $uid = uniqid("", true); $data = $_SERVER['REQUEST_TIME']; $hash = hash('ripemd128', $uid . $data); $guid = $namespace . substr($uid, 0, 14) . substr($uid, 15, 24) . substr($hash, 0, 10) . ''; return $guid; } }