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
cbef3fb7
Commit
cbef3fb7
authored
Dec 04, 2019
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hyperf jsonrpc 调用服务
parent
e1e305a4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
223 additions
and
3 deletions
+223
-3
ucenter_basic.php
example/ucenter_basic.php
+7
-2
Client.php
src/base/Client.php
+20
-0
HyperfJsonRpc.php
src/base/HyperfJsonRpc.php
+184
-0
client_config_dev.php
src/client_config_dev.php
+2
-1
Member.php
src/ucenter/Member.php
+10
-0
No files found.
example/ucenter_basic.php
View file @
cbef3fb7
...
...
@@ -18,11 +18,16 @@ Member::setDebug();
//Member::updateAvatar(12, 'jpg', base64_encode($bin));
//$ret = Member::getWechatInfoFromCode('dasfasdfsdaf');
$ret
=
Member
::
getMemberInfo
(
793
,
[
'basic'
,
'vip'
,
'verify'
]);
print_r
(
$ret
);
//
$ret = Member::getMemberInfo(793, ['basic', 'vip', 'verify']);
//
print_r($ret);
//$info = Member::getMemberInfo(12);
// $info = Member::getInfoByMobile('15395081586');
//$info = Member::getSyncByMobile('13000000002');
//$info = Member::getSyncByUid(514);
//print_r($info);
//$rt = Member::invol('hello world, blabl blasdfjiasdpjf -saduf0 asdupf0ashd- sajdgm 0df9n2i-df0m9gp-dfs0kgi-90skmjikg-0jsk-fkgdfg');
$rt
=
Member
::
retrive
();
print_r
(
$rt
);
src/base/Client.php
View file @
cbef3fb7
...
...
@@ -26,6 +26,7 @@ class Client
protected
$clientSecret
;
protected
$apiUrl
;
protected
$remoteIp
;
protected
$rpcServer
;
protected
static
$instance
=
[];
protected
static
$config
=
[];
...
...
@@ -201,6 +202,25 @@ class Client
return
$client
->
put
(
1024
,
0
,
60
,
json_encode
(
$msg
,
JSON_UNESCAPED_UNICODE
));
}
protected
static
function
invoke
(
$method
,
$params
=
[],
$id
=
null
)
{
static
$connections
=
[];
$instance
=
self
::
getInstance
();
if
(
!
isset
(
$connections
[
$instance
->
rpcServer
]))
{
$srv
=
parse_url
(
$instance
->
rpcServer
);
$conn
=
new
HyperfJsonRpc
([
'host'
=>
$srv
[
'host'
],
'port'
=>
$srv
[
'port'
]
]);
$conn
->
connect
();
$connections
[
$instance
->
rpcServer
]
=
$conn
;
}
return
$connections
[
$instance
->
rpcServer
]
->
invoke
(
$method
,
$params
,
$id
);
}
/**
* 对请求进程签名
*
...
...
src/base/HyperfJsonRpc.php
0 → 100644
View file @
cbef3fb7
<?php
/**
* Created by PhpStorm.
* User: pader
* Date: 2019/12/4
* Time: 17:26
*/
namespace
internalApi\base
;
use
RuntimeException
;
class
HyperfJsonRpc
{
/**
* Holds a boolean indicating whether a connection to the server is
* currently established or not.
*
* @var boolean
*/
public
$connected
=
false
;
/**
* Holds configuration values.
*
* @var array
*/
protected
$_config
=
[];
/**
* The current connection resource handle (if any).
*
* @var resource
*/
protected
$_connection
;
public
function
__construct
(
array
$config
=
[])
{
$defaults
=
[
'persistent'
=>
true
,
'host'
=>
'127.0.0.1'
,
'port'
=>
11300
,
'timeout'
=>
1
,
'logger'
=>
null
];
$this
->
_config
=
$config
+
$defaults
;
}
/**
* Destructor, disconnects from the server.
*
* @return void
*/
public
function
__destruct
()
{
$this
->
disconnect
();
}
/**
* Initiates a socket connection to the beanstalk server. The resulting
* stream will not have any timeout set on it. Which means it can wait
* an unlimited amount of time until a packet becomes available. This
* is required for doing blocking reads.
*
* @see \internalApi\base\Beanstalk::$_connection
* @see \internalApi\base\Beanstalk::reserve()
* @return boolean `true` if the connection was established, `false` otherwise.
*/
public
function
connect
()
{
if
(
isset
(
$this
->
_connection
))
{
$this
->
disconnect
();
}
$function
=
$this
->
_config
[
'persistent'
]
?
'pfsockopen'
:
'fsockopen'
;
$params
=
[
$this
->
_config
[
'host'
],
$this
->
_config
[
'port'
],
&
$errNum
,
&
$errStr
];
if
(
$this
->
_config
[
'timeout'
])
{
$params
[]
=
$this
->
_config
[
'timeout'
];
}
$this
->
_connection
=
@
call_user_func_array
(
$function
,
$params
);
if
(
!
empty
(
$errNum
)
||
!
empty
(
$errStr
))
{
$this
->
_error
(
"
{
$errNum
}
:
{
$errStr
}
"
);
}
$this
->
connected
=
is_resource
(
$this
->
_connection
);
if
(
$this
->
connected
)
{
stream_set_timeout
(
$this
->
_connection
,
-
1
);
}
return
$this
->
connected
;
}
/**
* Closes the connection to the beanstalk server by first signaling
* that we want to quit then actually closing the socket connection.
*
* @return boolean `true` if diconnecting was successful.
*/
public
function
disconnect
()
{
if
(
!
is_resource
(
$this
->
_connection
))
{
$this
->
connected
=
false
;
}
else
{
$this
->
connected
=
!
fclose
(
$this
->
_connection
);
if
(
!
$this
->
connected
)
{
$this
->
_connection
=
null
;
}
}
return
!
$this
->
connected
;
}
/**
* Pushes an error message to the logger, when one is configured.
*
* @param string $message The error message.
* @return void
*/
protected
function
_error
(
$message
)
{
if
(
$this
->
_config
[
'logger'
])
{
$this
->
_config
[
'logger'
]
->
error
(
$message
);
}
}
/**
* Writes a packet to the socket. Prior to writing to the socket will
* check for availability of the connection.
*
* @param string $data
* @return integer|boolean number of written bytes or `false` on error.
*/
protected
function
_write
(
$data
)
{
if
(
!
$this
->
connected
)
{
$message
=
'No connecting found while writing data to socket.'
;
throw
new
RuntimeException
(
$message
);
}
$data
.=
"
\r\n
"
;
return
fwrite
(
$this
->
_connection
,
$data
,
strlen
(
$data
));
}
/**
* Reads a packet from the socket. Prior to reading from the socket
* will check for availability of the connection.
*
* @param integer $length Number of bytes to read.
* @return string|boolean Data or `false` on error.
*/
protected
function
_read
()
{
if
(
!
$this
->
connected
)
{
$message
=
'No connection found while reading data from socket.'
;
throw
new
RuntimeException
(
$message
);
}
return
stream_get_line
(
$this
->
_connection
,
16384
,
"
\r\n
"
);
}
public
function
invoke
(
$method
,
$params
,
$id
=
null
)
{
$data
=
[
'jsonrpc'
=>
'2.0'
,
'method'
=>
$method
,
'params'
=>
$params
,
'id'
=>
$id
];
$json
=
json_encode
(
$data
);
$this
->
_write
(
$json
);
$response
=
$this
->
_read
();
if
(
!
$response
)
{
return
false
;
}
$ret
=
json_decode
(
$response
,
true
);
if
(
!
empty
(
$ret
[
'error'
]))
{
$this
->
_error
(
$ret
[
'error'
][
'message'
]);
return
false
;
}
return
$ret
[
'result'
];
}
}
\ No newline at end of file
src/client_config_dev.php
View file @
cbef3fb7
...
...
@@ -10,7 +10,8 @@ return [
'ucenter'
=>
[
'apiUrl'
=>
'http://u.yunya.com/api/server'
,
'clientId'
=>
'common'
,
'clientSecret'
=>
'Kuy2dVHKRWKAFRXX2l6k'
'clientSecret'
=>
'Kuy2dVHKRWKAFRXX2l6k'
,
'rpcServer'
=>
'192.168.99.181:9503'
],
'xue'
=>
[
'apiUrl'
=>
'http://xue.yunya.com/api'
,
...
...
src/ucenter/Member.php
View file @
cbef3fb7
...
...
@@ -201,4 +201,14 @@ class Member extends Client
return
self
::
call
(
'member.getUidByWxhuid'
,
compact
(
'wxhuid'
));
}
public
static
function
invol
(
$say
)
{
return
self
::
invoke
(
'/test/invoid'
,
[
$say
]);
}
public
static
function
retrive
()
{
return
self
::
invoke
(
'/test/retrive'
);
}
}
\ 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