Exemplo n.º 1
0
Arquivo: tool.php Projeto: wxl2012/wx
 /**
  * 生成签名
  */
 public static function getWxPaySign($params, $key)
 {
     $data = array();
     foreach ($params as $k => $v) {
         $data[$k] = $v;
     }
     //签名步骤一:按字典序排序参数
     ksort($data);
     $String = UrlTool::createLinkstring($data);
     //echo '【string1】'.$String.'</br>';
     //签名步骤二:在string后加入KEY
     $String = $String . "&key=" . $key;
     //echo "【string2】".$String."</br>";
     //签名步骤三:MD5加密
     $String = md5($String);
     //echo "【string3】 ".$String."</br>";
     //签名步骤四:所有字符转为大写
     $result_ = strtoupper($String);
     //echo "【result】 ".$result_."</br>";
     return $result_;
 }
Exemplo n.º 2
0
 /**
  * Prepare all parameter to request
  * @param String $urlMethod Type of method in REST API
  * @throws Exception If some parameters are not set
  */
 private function BuildRequest($urlMethod, $pagination, $additionalUrlParams = null)
 {
     $urlTool = new UrlTool($this->_root);
     $restUrl = $urlTool->GetRestUrl($urlMethod, $this->_authRequired, $pagination, $additionalUrlParams);
     $this->_requestUrl = $urlTool->GetFullUrl($restUrl);
     $logClass = $this->_root->Config->LogClass;
     if ($this->_root->Config->DebugMode) {
         $logClass::Debug('FullUrl', $this->_requestUrl);
     }
     $this->_curlHandle = curl_init($this->_requestUrl);
     if ($this->_curlHandle === false) {
         throw new Exception('Cannot initialize cURL session');
     }
     curl_setopt($this->_curlHandle, CURLOPT_RETURNTRANSFER, true);
     if ($this->_root->Config->CertificatesFilePath == '') {
         curl_setopt($this->_curlHandle, CURLOPT_SSL_VERIFYPEER, false);
     } else {
         curl_setopt($this->_curlHandle, CURLOPT_SSL_VERIFYPEER, true);
         curl_setopt($this->_curlHandle, CURLOPT_CAINFO, $this->_root->Config->CertificatesFilePath);
     }
     if (!is_null($pagination)) {
         curl_setopt($this->_curlHandle, CURLOPT_HEADERFUNCTION, array(&$this, 'ReadResponseHeader'));
         $this->_pagination = $pagination;
     }
     switch ($this->_requestType) {
         case RequestType::POST:
             curl_setopt($this->_curlHandle, CURLOPT_POST, true);
             break;
         case RequestType::PUT:
             curl_setopt($this->_curlHandle, CURLOPT_CUSTOMREQUEST, 'PUT');
             break;
         case RequestType::DELETE:
             curl_setopt($this->_curlHandle, CURLOPT_CUSTOMREQUEST, "DELETE");
             break;
     }
     if ($this->_root->Config->DebugMode) {
         $logClass::Debug('RequestType', $this->_requestType);
     }
     $httpHeaders = $this->GetHttpHeaders();
     curl_setopt($this->_curlHandle, CURLOPT_HTTPHEADER, $httpHeaders);
     if ($this->_root->Config->DebugMode) {
         $logClass::Debug('HTTP Headers', $httpHeaders);
     }
     if (!is_null($this->_requestData)) {
         if ($this->_root->Config->DebugMode) {
             $logClass::Debug('RequestData object', $this->_requestData);
         }
         // encode to json if needed
         if (in_array(self::$_JSON_HEADER, $httpHeaders)) {
             $this->_requestData = json_encode($this->_requestData);
             if ($this->_root->Config->DebugMode) {
                 $logClass::Debug('RequestData JSON', $this->_requestData);
             }
         }
         curl_setopt($this->_curlHandle, CURLOPT_POSTFIELDS, $this->_requestData);
     }
 }