Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminApi4Tpl
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminApi4Tpl
Commits
c73719d8
Commit
c73719d8
authored
Oct 25, 2016
by
庄欣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
0ea93306
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
25 deletions
+6
-25
app/Http/Controllers/Category/Controller/Category.php
+1
-0
app/Lib/Client/CurlClient.php
+5
-25
No files found.
app/Http/Controllers/Category/Controller/Category.php
View file @
c73719d8
...
...
@@ -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
...
...
app/Lib/Client/CurlClient.php
View file @
c73719d8
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment