Commit c73719d8 by 庄欣

test

parent 0ea93306
......@@ -2,6 +2,7 @@
namespace App\Http\Controllers\Category\Controller;
use App\Http\Controllers\ControllerBase;
use App\Lib\Client\CurlClient;
use App\Lib\Response\Response;
class Category extends ControllerBase
......
......@@ -12,11 +12,11 @@ class CurlClient
protected $config;
protected $data;
protected $url;
private $format = "";
private $format = "JSON";
protected $header = [];
protected $base;
const Exceptions = [
protected $Exceptions = [
HttpStatus::HttpNotFound => \App\Exceptions\ApiNotFound::class,
HttpStatus::HttpUnauthorized => \App\Exceptions\ApiUnauthorized::class,
HttpStatus::HttpValidationFailed => \App\Exceptions\ApiValidationFailed::class,
......@@ -84,7 +84,7 @@ class CurlClient
curl_setopt($http,CURLOPT_URL,$this->base.$this->url);
curl_setopt($http,CURLOPT_HEADER,false);
curl_setopt($http,CURLOPT_CUSTOMREQUEST,$this->method);
curl_setopt($http,CURLOPT_TIMEOUT ,3);
curl_setopt($http,CURLOPT_TIMEOUT ,5);
if ($this->format == "JSON")
{
$this->header = array_merge($this->header,['Content-Type:application/json']);
......@@ -97,27 +97,8 @@ class CurlClient
if (!empty($this->data)) {
curl_setopt($http, CURLOPT_POSTFIELDS, $this->data);
}
/*if ($this->method === "GET") {
$NOW_TIME = time();
static $response_from_api;
$sign = $this->getSign();
$curlinfo = true;
if (!isset($response_from_api[$sign])) {
$response_from_api[$sign] = curl_exec($http);
//对于重复获取,缓存1S
$response_from_api["timeout"] = $NOW_TIME + 1;
$curlinfo = curl_getinfo($http);
} else {
if ($response_from_api["timeout"] > $NOW_TIME) {
$response_from_api[$sign] = curl_exec($http);
$response_from_api["timeout"] = $NOW_TIME + 1;
}
}
$res = $response_from_api[$sign];
} else {*/
$res = curl_exec($http);
$curlinfo = curl_getinfo($http);
//}
$res = curl_exec($http);
$curlinfo = curl_getinfo($http);
curl_close($http);
if ($curlinfo == false || (is_array($curlinfo) && $curlinfo['http_code'] != 200)) {
throw new \Exception("服务器无反应,请稍候再试");
......@@ -133,7 +114,6 @@ class CurlClient
$msg = is_array($res->message)?implode(";",$res->message):$res->message;
throw new $exception($msg);
}
}
public function getError()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment