Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wxh_internal_api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
杨培培
wxh_internal_api
Commits
ca93eb6c
Commit
ca93eb6c
authored
Mar 14, 2019
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持以 JSON 方式请求数据
parent
84ce032a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
8 deletions
+39
-8
Server.php
src/base/Server.php
+39
-8
No files found.
src/base/Server.php
View file @
ca93eb6c
...
@@ -77,6 +77,23 @@ class Server
...
@@ -77,6 +77,23 @@ class Server
$paramsList
=
array_slice
(
$this
->
apiMap
[
$group
][
$name
],
1
);
$paramsList
=
array_slice
(
$this
->
apiMap
[
$group
][
$name
],
1
);
$params
=
[];
$params
=
[];
//确认请求数据
$contentType
=
$_SERVER
[
'HTTP_CONTENT_TYPE'
]
??
''
;
switch
(
$contentType
)
{
case
'application/x-www-form-urlencoded'
:
$requestData
=
$_POST
;
break
;
case
'application/json'
:
$json
=
file_get_contents
(
'php://input'
);
$requestData
=
$json
!==
''
?
json_decode
(
$json
,
true
)
:
[];
break
;
default
:
$requestData
=
[];
}
foreach
(
$paramsList
as
$k
=>
$v
)
{
foreach
(
$paramsList
as
$k
=>
$v
)
{
if
(
is_int
(
$k
))
{
if
(
is_int
(
$k
))
{
$k
=
$v
;
$k
=
$v
;
...
@@ -85,8 +102,8 @@ class Server
...
@@ -85,8 +102,8 @@ class Server
$hasDefault
=
true
;
$hasDefault
=
true
;
}
}
if
(
isset
(
$
_POST
[
$k
]))
{
if
(
isset
(
$
requestData
[
$k
]))
{
$params
[]
=
$
_POST
[
$k
];
$params
[]
=
$
requestData
[
$k
];
}
elseif
(
$hasDefault
)
{
}
elseif
(
$hasDefault
)
{
$params
[]
=
$v
;
$params
[]
=
$v
;
}
else
{
}
else
{
...
@@ -141,17 +158,31 @@ class Server
...
@@ -141,17 +158,31 @@ class Server
$timestamp
=
isset
(
$_GET
[
'timestamp'
])
?
$_GET
[
'timestamp'
]
:
0
;
$timestamp
=
isset
(
$_GET
[
'timestamp'
])
?
$_GET
[
'timestamp'
]
:
0
;
$nonce
=
isset
(
$_GET
[
'nonce'
])
?
$_GET
[
'nonce'
]
:
''
;
$nonce
=
isset
(
$_GET
[
'nonce'
])
?
$_GET
[
'nonce'
]
:
''
;
$servTime
=
time
();
//确认用于签名的请求数据
$params
=
$_POST
;
$contentType
=
$_SERVER
[
'HTTP_CONTENT_TYPE'
]
??
''
;
ksort
(
$params
);
$str
=
$api
.
http_build_query
(
$params
)
.
$clientId
.
$this
->
secret
.
$timestamp
.
$nonce
;
switch
(
$contentType
)
{
case
'application/x-www-form-urlencoded'
:
$parr
=
ksort
(
$_POST
);
$pstr
=
http_build_query
(
$parr
);
break
;
case
'application/json'
:
$pstr
=
file_get_contents
(
'php://input'
);
break
;
default
:
$pstr
=
''
;
}
$str
=
$api
.
$pstr
.
$clientId
.
$this
->
secret
.
$timestamp
.
$nonce
;
$servSign
=
md5
(
$str
);
$servSign
=
md5
(
$str
);
if
(
$servSign
!==
$sign
)
{
if
(
$servSign
!==
$sign
)
{
return
false
;
return
false
;
}
}
if
(
$servTime
-
$timestamp
>
300
)
{
if
(
time
()
-
$timestamp
>
300
)
{
return
false
;
return
false
;
}
}
...
...
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