예제 #1
0
 /**
  * _sendRequest
  * @param  string $url        请求url
  * @param  array  $paramArray 请求参数
  * @param  string $method     请求方法
  * @return
  */
 protected static function _sendRequest($url, $paramArray, $method = 'POST')
 {
     $ch = curl_init();
     if ($method == 'POST') {
         $paramArray = is_array($paramArray) ? http_build_query($paramArray) : $paramArray;
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $paramArray);
     } else {
         $url .= '?' . http_build_query($paramArray);
     }
     self::$_requestUrl = $url;
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     if (false !== strpos($url, "https")) {
         // 证书
         // curl_setopt($ch,CURLOPT_CAINFO,"ca.crt");
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     }
     $resultStr = curl_exec($ch);
     self::$_rawResponse = $resultStr;
     $result = json_decode($resultStr, true);
     if (!$result) {
         return $resultStr;
     }
     return $result;
 }