コード例 #1
0
ファイル: Pay.php プロジェクト: tofindme/work_note
 private function _verifyOrder($params)
 {
     $url = self::VERIFY_URL_ONLINE;
     unset($params['gateway_flag'], $params['sign'], $params['sign_return']);
     $params['app_key'] = $this->_appKey;
     $params['sign'] = Qihoo_Util::getSign($params, $this->_appSecret);
     $url .= '?' . http_build_query($params);
     $ret = Qihoo_Util::request($url, Qihoo_Util::METHOD_POST);
     $json = json_decode($ret, TRUE);
     return $json['ret'];
 }
コード例 #2
0
ファイル: Util.php プロジェクト: tofindme/work_note
 public static function request($url, $mode, $params = '', $needHeader = false, $timeout = 10)
 {
     self::$err = null;
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_USERAGENT, self::USERAGENT);
     curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
     if (self::$_followRedirect) {
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     }
     if ($needHeader) {
         curl_setopt($ch, CURLOPT_HEADER, true);
     }
     if ($mode == 'POST') {
         curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
         curl_setopt($ch, CURLOPT_POST, true);
         if (is_array($params)) {
             curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
         } else {
             curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
         }
     } else {
         if (is_array($params)) {
             $url .= (strpos($url, '?') === false ? '?' : '&') . http_build_query($params);
         } else {
             $url .= (strpos($url, '?') === false ? '?' : '&') . $params;
         }
     }
     curl_setopt($ch, CURLOPT_URL, $url);
     $result = curl_exec($ch);
     if ($needHeader) {
         $tmp = $result;
         $result = array();
         $info = curl_getinfo($ch);
         $result['header'] = substr($tmp, 0, $info['header_size']);
         $result['body'] = trim(substr($tmp, $info['header_size']));
         //直接从header之后开始截取,因为 1.body可能为空   2.下载可能不全
         //$info['download_content_length'] > 0 ? substr($tmp, -$info['download_content_length']) : '';
     }
     $errno = curl_errno($ch);
     if ($errno) {
         self::$err = array('errno' => $errno, 'error' => curl_error($ch));
     }
     curl_close($ch);
     return $result;
 }
コード例 #3
0
ファイル: OAuth2.php プロジェクト: tofindme/work_note
 /**
  * 请求360接口
  * @param type $url
  * @param type $data
  * @param type $decode
  * @return type
  * @throws Qihoo_Exception
  */
 private function _request($url, $data, $decode = true)
 {
     $debugUrl = $url . '?' . http_build_query($data);
     $this->_debug(__METHOD__, "请求 {$debugUrl}");
     $jsonStr = Qihoo_Util::request($url, Qihoo_Util::METHOD_GET, $data);
     $err = Qihoo_Util::getError();
     if ($err) {
         $errMsg = "错误:{$err['error']}({$err['errno']})";
         $this->_debug(__METHOD__, $errMsg);
         throw new Qihoo_Exception(Qihoo_Exception::CODE_NET_ERROR, $errMsg . "\r\n" . $url);
     }
     if (empty($jsonStr)) {
         $this->_debug(__METHOD__, "请求{$debugUrl} 返回了空字符串");
         throw new Qihoo_Exception(Qihoo_Exception::CODE_NET_ERROR, $debugUrl);
     }
     $this->_debug(__METHOD__, "请求{$debugUrl} 返回了" . $jsonStr);
     if (!$decode) {
         return $jsonStr;
     }
     $response = json_decode($jsonStr, true);
     if (empty($response)) {
         $this->_debug(__METHOD__, "json_decode失败,原串为{$jsonStr}");
         throw new Qihoo_Exception(Qihoo_Exception::CODE_JSON_ERROR, $jsonStr);
     }
     $this->_debug(__METHOD__, "请求{$debugUrl} json解压后结果为" . var_export($response, 1));
     if (!empty($response['error_code'])) {
         $this->_debug(__METHOD__, "返回结果有错误:" . $response['error'] . "({$response['error_code']})");
         throw new Qihoo_Exception($response['error_code'], $response['error']);
     }
     return $response;
 }