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
f0ed7539
Commit
f0ed7539
authored
Jan 06, 2020
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加请求与返回ID匹配校验;优化RPC服务调用异常处理;
parent
78b08abb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
13 deletions
+23
-13
ucenter_message.php
example/ucenter_message.php
+14
-9
Client.php
src/base/Client.php
+1
-1
JsonRpc.php
src/base/JsonRpc.php
+8
-3
No files found.
example/ucenter_message.php
View file @
f0ed7539
...
@@ -16,18 +16,23 @@ Message::setDebug();
...
@@ -16,18 +16,23 @@ Message::setDebug();
//$ret = Message::sendTemplateSmsByUidAsync('12', 'default_code', ['code'=>rand(1000, 9999)]);
//$ret = Message::sendTemplateSmsByUidAsync('12', 'default_code', ['code'=>rand(1000, 9999)]);
//$ret = Message::sendSms('18019580609', 'Hello World 3');
//$ret = Message::sendSms('18019580609', 'Hello World 3');
$ret
=
Message
::
sendTemplateSms
(
'18019580609'
,
'shop_item_shipped'
,
[
try
{
'order'
=>
'4124'
,
$ret
=
Message
::
sendTemplateSmsAsync
(
'18019580609'
,
'shop_item_shipped'
,
[
'express'
=>
'顺丰速运'
,
'order'
=>
'4124'
,
'number'
=>
'sf123456'
'express'
=>
'顺丰速运'
,
]);
'number'
=>
'sf123456'
]);
}
catch
(
\Exception
$e
)
{
echo
$e
->
getCode
()
.
'/'
.
$e
->
getMessage
();
$ret
=
null
;
}
//Message::setUserOnline(12, 60);
//Message::setUserOnline(12, 60);
//$ret = Message::isUseOnline(12);
//$ret = Message::isUseOnline(12);
$ret
=
Message
::
sendSystemMessageAsync
(
'remind'
,
0
,
12
,
Message
::
TYPE_REMIND
,
[
//
$ret = Message::sendSystemMessageAsync('remind', 0, 12, Message::TYPE_REMIND, [
'title'
=>
'测试的标题'
,
//
'title' => '测试的标题',
'text'
=>
'新消息测试'
.
uniqid
()
//
'text'=>'新消息测试'.uniqid()
]);
//
]);
var_dump
(
$ret
);
var_dump
(
$ret
);
\ No newline at end of file
src/base/Client.php
View file @
f0ed7539
...
@@ -217,7 +217,7 @@ class Client
...
@@ -217,7 +217,7 @@ class Client
]);
]);
if
(
!
$conn
->
connect
())
{
if
(
!
$conn
->
connect
())
{
throw
new
ClientException
(
"Unable to connect to
rpc server.
{
$srv
[
'host'
]
}
:
{
$srv
[
'port'
]
}
"
);
throw
new
ClientException
(
"Unable to connect to
RPC server
{
$srv
[
'host'
]
}
:
{
$srv
[
'port'
]
}
"
);
}
}
$connections
[
$instance
->
rpcServer
]
=
$conn
;
$connections
[
$instance
->
rpcServer
]
=
$conn
;
...
...
src/base/JsonRpc.php
View file @
f0ed7539
...
@@ -194,13 +194,13 @@ class JsonRpc
...
@@ -194,13 +194,13 @@ class JsonRpc
}
}
}
}
public
function
invoke
(
$method
,
$params
,
$id
=
null
)
public
function
invoke
(
$method
,
$params
)
{
{
$data
=
[
$data
=
[
'jsonrpc'
=>
'2.0'
,
'jsonrpc'
=>
'2.0'
,
'method'
=>
$method
,
'method'
=>
$method
,
'params'
=>
$params
,
'params'
=>
$params
,
'id'
=>
$id
'id'
=>
uniqid
()
];
];
$json
=
json_encode
(
$data
);
$json
=
json_encode
(
$data
);
...
@@ -213,9 +213,14 @@ class JsonRpc
...
@@ -213,9 +213,14 @@ class JsonRpc
$ret
=
json_decode
(
$response
,
true
);
$ret
=
json_decode
(
$response
,
true
);
if
(
$ret
[
'id'
]
!=
$data
[
'id'
])
{
$this
->
_error
(
'Request id not matched.'
);
throw
new
ApiException
(
'Request id not matched.'
);
}
if
(
!
empty
(
$ret
[
'error'
]))
{
if
(
!
empty
(
$ret
[
'error'
]))
{
$this
->
_error
(
$ret
[
'error'
][
'message'
]);
$this
->
_error
(
$ret
[
'error'
][
'message'
]);
throw
new
ApiException
(
$ret
[
'error'
][
'message'
],
$ret
[
'error'
][
'
code'
]
);
throw
new
ApiException
(
$ret
[
'error'
][
'message'
],
$ret
[
'error'
][
'
data'
][
'code'
]
??
0
);
}
}
return
$ret
[
'result'
];
return
$ret
[
'result'
];
...
...
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