Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
s_ibanshou
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
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋林
s_ibanshou
Commits
af63ccd6
Commit
af63ccd6
authored
Aug 22, 2017
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入更新用户信息API
数据库操作加入转义方法
parent
932a4770
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
375 additions
and
251 deletions
+375
-251
internal.php
e/api/internal.php
+67
-0
db_sql.php
e/class/db_sql.php
+11
-0
config_ibanshou.php
e/config/config_ibanshou.php
+1
-3
ApiException.php
e/extend/internalApi/base/ApiException.php
+21
-0
Client.php
e/extend/internalApi/base/Client.php
+243
-230
ClientException.php
e/extend/internalApi/base/ClientException.php
+9
-2
Server.php
e/extend/internalApi/base/Server.php
+23
-1
ServerException.php
e/extend/internalApi/base/ServerException.php
+0
-15
No files found.
e/api/internal.php
0 → 100644
View file @
af63ccd6
<?php
/**
* Created by PhpStorm.
* User: pader
* Date: 2017/8/22
* Time: 18:07
*/
require
'../class/connect.php'
;
require
'../class/db_sql.php'
;
require
'../class/q_functions.php'
;
require
'../extend/internalApi/autoload.php'
;
require
'../config/config_ibanshou.php'
;
$link
=
db_connect
();
$empire
=
new
mysqlquery
();
class
InternalApiWrap
{
/**
* 同步更新用户信息
*
* @param int $uid
* @param array $data 用户中心传递来的信息可能包括以下字段 nickname, avatar, phone_number, updated_at
* @return bool
*/
public
static
function
userUpdateSync
(
$uid
,
$data
)
{
global
$empire
,
$link
;
require_once
'../member/class/user.php'
;
$member
=
$empire
->
fetch1
(
"SELECT "
.
eReturnSelectMemberF
(
'*'
)
.
" FROM "
.
eReturnMemberTable
()
.
" WHERE "
.
egetmf
(
'ucid'
)
.
"=
{
$uid
}
limit 1"
);
if
(
!
$member
)
{
return
false
;
}
$updateSql
=
''
;
foreach
(
$data
as
$k
=>
$v
)
{
switch
(
$k
)
{
case
'avatar'
:
$updateSql
.=
"`avatar`="
.
$empire
->
quote
(
$v
)
.
","
;
break
;
case
'nickname'
:
$updateSql
.=
"`nickname`="
.
$empire
->
quote
(
$v
)
.
","
;
break
;
}
}
if
(
$updateSql
)
{
$updateSql
=
substr
(
$updateSql
,
0
,
-
1
);
$empire
->
query
(
"UPDATE "
.
eReturnMemberTable
()
.
" SET
$updateSql
WHERE "
.
egetmf
(
'userid'
)
.
"='"
.
$member
[
'userid'
]
.
"'"
);
return
true
;
}
return
true
;
}
}
$server
=
new
\internalApi\base\Server
(
$config
[
'wxh.internal'
][
'server_secret'
]);
$server
->
setApiMap
([
'user'
=>
[
'updateSync'
=>
[
'InternalApiWrap::userUpdateSync'
,
'uid'
,
'data'
]
]
]);
$server
->
invoke
();
e/class/db_sql.php
View file @
af63ccd6
...
...
@@ -110,5 +110,16 @@ class mysqlquery
{
return
mysqli_affected_rows
(
$GLOBALS
[
'link'
]);
}
/**
* 转义并包裹指定字符串以使其可安全用于查询
*
* @param string $str
* @return string
*/
function
quote
(
$str
)
{
return
'\''
.
mysqli_real_escape_string
(
$GLOBALS
[
'link'
],
$str
)
.
'\''
;
}
}
?>
\ No newline at end of file
e/config/config_ibanshou.php
View file @
af63ccd6
...
...
@@ -31,9 +31,7 @@ $config = [
//wxh_internal_api
'wxh.internal'
=>
[
'server'
=>
[
'secret'
=>
'U2FsdGVkX19ZiutUoO6F'
,
],
'server_secret'
=>
'TveYDczsq7LTllIUlM5t'
,
'client'
=>
[
'ucenter'
=>
[
'apiUrl'
=>
'http://u.yunya.com/api/server'
,
...
...
e/extend/internalApi/base/ApiException.php
0 → 100644
View file @
af63ccd6
<?php
/**
* Created by PhpStorm.
* User: pader
* Date: 2017/7/6
* Time: 11:46
*/
namespace
internalApi\base
;
/**
* 接口异常
*
* 本异常为目标接口业务异常
* 所的目标接口抛出的异常到客户端后均抛出为本异常
*
* @package internalApi\base
*/
class
ApiException
extends
\Exception
{
}
\ No newline at end of file
e/extend/internalApi/base/Client.php
View file @
af63ccd6
This diff is collapsed.
Click to expand it.
e/extend/internalApi/base/ClientException.php
View file @
af63ccd6
...
...
@@ -8,7 +8,14 @@
namespace
internalApi\base
;
class
ClientException
extends
\ErrorException
/**
* 客户端异常
*
* 本异常为非业务异常
* 如调用请求发送失败,数据异常,网络异常,接口参数不一致等程序和服务器环境导致的无法正常发送和解析接口的请求问题
*
* @package internalApi\base
*/
class
ClientException
extends
\Exception
{
}
\ No newline at end of file
e/extend/internalApi/base/Server.php
View file @
af63ccd6
...
...
@@ -94,7 +94,11 @@ class Server
}
}
$data
=
call_user_func_array
(
$callable
,
$params
);
try
{
$data
=
call_user_func_array
(
$callable
,
$params
);
}
catch
(
\Exception
$e
)
{
$this
->
responseException
(
$e
);
}
if
(
$return
)
{
return
$data
;
...
...
@@ -104,6 +108,24 @@ class Server
}
}
/**
* @param \Exception $e
*/
public
function
responseException
(
$e
)
{
header
(
'HTTP/1.0 500 Internal Server Error'
);
$exception
=
[
'class'
=>
get_class
(
$e
),
'code'
=>
$e
->
getCode
(),
'message'
=>
$e
->
getMessage
(),
'line'
=>
$e
->
getFile
(),
'file'
=>
$e
->
getFile
(),
'traceString'
=>
$e
->
getTraceAsString
()
];
echo
'exception:'
.
json_encode
(
$exception
,
JSON_UNESCAPED_UNICODE
);
exit
;
}
public
function
responseError
(
$message
)
{
header
(
'HTTP/1.0 403 Forbidden'
);
...
...
e/extend/internalApi/base/ServerException.php
deleted
100644 → 0
View file @
932a4770
<?php
/**
* Created by PhpStorm.
* User: pader
* Date: 2017/6/27
* Time: 16:44
*/
namespace
internalApi\base
;
class
ServerException
extends
\Exception
{
}
\ No newline at end of file
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