Exemplo n.º 1
0
 /**
  * 发出请求
  * @param $url
  * @param $params
  * @param $cookie
  * @param string $method
  * @param string $protocol
  * @return \Simple\Curl\Response\ResponseValue
  * @throws DeepInException
  */
 private function makeRequest($url, $params, $cookie, $method = "POST", $protocol = 'http')
 {
     $request = new Request($url, $method, RequestBodyEncodeType::JSON);
     $request->addHeaders(array("Expect" => "", "Access-Token" => $this->hookClient->getToken(), "Content-Type" => "application/json"));
     foreach ($params as $key => $val) {
         $request->setParam($key, $val);
     }
     foreach ($cookie as $key => $val) {
         $request->setCookie($key, $val);
     }
     $curl = new Curl($request);
     $response = $curl->makeRequest(new HookResponseValue());
     if ($response->getErrorCode() != 0) {
         throw new DeepInException($response->getErrorMsg());
     }
     if (in_array(intval($response->getHttpCode() / 100), array(4, 5))) {
         throw new DeepInException("hook server返回状态码为" . $response->getHttpCode());
     }
     return $response->getResponseValue()->getData();
 }
Exemplo n.º 2
0
 /**
  * 调用API接口
  * @param $apiName
  * @param $httpMethod
  * @param array $params
  * @param null $request
  * @return \Simple\Curl\Response\Response
  * @throws DeepInException
  */
 public function api($apiName, $httpMethod, $params = array(), $request = null)
 {
     $url = $this->serverName . $apiName;
     $httpMethod = strtoupper($httpMethod);
     if (!$request instanceof Request) {
         $request = new Request($url, $httpMethod, RequestBodyEncodeType::FORM_DATA);
         $request->addHeaders(array("Content-Type" => "application/json", "Expect" => ''));
     }
     $request->addParams($params);
     $curl = new Curl($request);
     $response = $curl->makeRequest(new OpenAPIResponseValue());
     if ($response->getErrorCode() != 0) {
         throw new DeepInException("请求" . $url . '失败,失败原因:' . $response->getErrorMsg());
     }
     $httpStatus = $response->getHttpCode();
     if (in_array(intval($httpStatus / 100), array(4, 5))) {
         throw new DeepInException("Api server返回http状态码为:" . $httpStatus);
     }
     return $response;
 }
Exemplo n.º 3
0
 /**
  * 获取又拍云的资源地址
  * @param $resourceUrl
  * @return Response
  * @throws CurlException
  */
 public function getUpYunUrl($resourceUrl)
 {
     $request = new Request($this->serverURL . "/" . $resourceUrl, HttpMethod::GET);
     $request->setOption(CURLOPT_HEADER, true);
     $this->curl = new Curl($request);
     $response = $this->curl->makeRequest(new UpYunResponseValue());
     return $response;
 }