ComposerUpdate

This commit is contained in:
Anyon 2019-12-16 11:43:34 +08:00
parent 6cb1f12827
commit 24a1a67e27
5 changed files with 46 additions and 83 deletions

8
composer.lock generated
View File

@ -909,12 +909,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "211f7afd9d19f9165989a5ecea78a828996e9c3f"
"reference": "ca6df0b64b3d22c210260a218bb31134661c881d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/211f7afd9d19f9165989a5ecea78a828996e9c3f",
"reference": "211f7afd9d19f9165989a5ecea78a828996e9c3f",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/ca6df0b64b3d22c210260a218bb31134661c881d",
"reference": "ca6df0b64b3d22c210260a218bb31134661c881d",
"shasum": "",
"mirrors": [
{
@ -958,7 +958,7 @@
],
"description": "ThinkPHP v6.0 Development Library",
"homepage": "http://framework.thinkadmin.top",
"time": "2019-12-16T02:57:39+00:00"
"time": "2019-12-16T03:27:06+00:00"
},
{
"name": "zoujingli/wechat-developer",

View File

@ -935,12 +935,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "211f7afd9d19f9165989a5ecea78a828996e9c3f"
"reference": "ca6df0b64b3d22c210260a218bb31134661c881d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/211f7afd9d19f9165989a5ecea78a828996e9c3f",
"reference": "211f7afd9d19f9165989a5ecea78a828996e9c3f",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/ca6df0b64b3d22c210260a218bb31134661c881d",
"reference": "ca6df0b64b3d22c210260a218bb31134661c881d",
"shasum": "",
"mirrors": [
{
@ -956,7 +956,7 @@
"ext-json": "*",
"topthink/framework": "^6.0"
},
"time": "2019-12-16T02:57:39+00:00",
"time": "2019-12-16T03:27:06+00:00",
"type": "library",
"extra": {
"think": {

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php
// This file is automatically generated at:2019-12-16 11:11:22
// This file is automatically generated at:2019-12-16 11:42:37
declare (strict_types = 1);
return array (
0 => 'think\\app\\Service',

View File

@ -25,12 +25,6 @@ use think\admin\Service;
*/
class JsonRpcClientService extends Service
{
/**
* 调式状态
* @var boolean
*/
private $debug;
/**
* 服务端地址
* @var string
@ -41,37 +35,20 @@ class JsonRpcClientService extends Service
* 请求ID
* @var integer
*/
private $requestId;
/**
* 通知状态
* @var boolean
*/
private $notification = false;
private $requestid;
/**
* 创建连接对象
* @param string $proxy
* @param boolean $debug
* @return $this
*/
public function create($proxy, $debug = false)
public function create($proxy)
{
$this->proxy = $proxy;
$this->debug = empty($debug) ? false : true;
$this->requestId = CodeExtend::uniqidNumber();
$this->requestid = CodeExtend::uniqidNumber();
return $this;
}
/**
* 设置对象的通知状态(在此状态下,将执行通知而不是请求)
* @param boolean $notification
*/
public function setRpcNotification($notification)
{
$this->notification = empty($notification) ? false : true;
}
/**
* 执行 JsonRCP 请求
* @param string $method
@ -81,53 +58,39 @@ class JsonRpcClientService extends Service
*/
public function __call($method, $params)
{
// check
if (!is_scalar($method)) {
throw new \think\Exception('Method name has no scalar value');
}
// check
if (is_array($params)) {
// no keys
$params = array_values($params);
} else {
throw new \think\Exception('Params must be given as array');
}
// sets notification or request task
$currentId = $this->notification ? null : $this->requestId;
// prepares the request
$request = json_encode(['method' => $method, 'params' => $params, 'id' => $currentId], JSON_UNESCAPED_UNICODE);
$this->debug && $this->debug .= '***** Request *****' . "\n" . $request . "\n" . '***** End Of request *****' . "\n\n";
// performs the HTTP POST
$options = ['http' => ['method' => 'POST', 'header' => 'Content-type: application/json', 'content' => $request]];
$options = [
'http' => [
'method' => 'POST', 'header' => 'Content-type: application/json',
'content' => json_encode(['method' => $method, 'params' => $params, 'id' => $this->requestid], JSON_UNESCAPED_UNICODE),
],
];
if ($fp = fopen($this->proxy, 'r', false, stream_context_create($options))) {
$response = '';
while ($row = fgets($fp)) $response .= trim($row) . "\n";
$this->debug && $this->debug .= '***** Server response *****' . "\n" . $response . '***** End of server response *****' . "\n";
fclose($fp);
$response = json_decode($response, true);
} else {
throw new \think\Exception("Unable to connect to {$this->proxy}");
}
// debug output
if ($this->debug) {
echo nl2br($this->debug);
}
// final checks and return
if ($this->notification) {
return true;
} else {
// check
if ($response['id'] != $currentId) {
throw new \think\Exception("Incorrect response id (request id: {$currentId}, response id: {$response['id']}");
}
if (!is_null($response['error'])) {
throw new \think\Exception("Request error: {$response['error']}");
}
if ($response['id'] != $this->requestid) {
throw new \think\Exception("Incorrect response id (request id: {$this->requestid}, response id: {$response['id']}");
}
if (is_null($response['error'])) {
return $response['result'];
} else {
throw new \think\Exception("Request error: {$response['error']}");
}
}
}

View File

@ -28,35 +28,35 @@ class JsonRpcServerService extends Service
/**
* 设置监听对象
* @param mixed $object
* @return boolean
* @throws \think\Exception
*/
public function handle($object)
{
// Checks if a JSON-RCP request has been received
if ($this->app->request->method() !== "POST" || $this->app->request->contentType() != 'application/json') {
foreach (get_class_methods($object) as $method) echo "<p>method {$method}()</p>";
return false;
}
// Reads the input data
$request = json_decode(file_get_contents('php://input'), true);
if (empty($request['id'])) {
throw new \think\Exception('JsonRpc Request id cannot be empty');
}
// Executes the task on local object
try {
if ($result = call_user_func_array([$object, $request['method']], $request['params'])) {
$response = ['id' => $request['id'], 'result' => $result, 'error' => null];
} else {
$response = ['id' => $request['id'], 'result' => null, 'error' => 'unknown method or incorrect parameters'];
echo "<h2>" . get_class($object) . "</h2>";
foreach (get_class_methods($object) as $method) {
if ($method[0] !== '_') echo "<p>method {$method}()</p>";
}
} catch (\Exception $e) {
$response = ['id' => $request['id'], 'result' => null, 'error' => $e->getMessage()];
} else {
// Reads the input data
$request = json_decode(file_get_contents('php://input'), true);
if (empty($request['id'])) {
throw new \think\Exception('JsonRpc Request id cannot be empty');
}
// Executes the task on local object
try {
if ($result = @call_user_func_array([$object, $request['method']], $request['params'])) {
$response = ['id' => $request['id'], 'result' => $result, 'error' => null];
} else {
$response = ['id' => $request['id'], 'result' => null, 'error' => 'unknown method or incorrect parameters'];
}
} catch (\Exception $e) {
$response = ['id' => $request['id'], 'result' => null, 'error' => $e->getMessage()];
}
// Output the response
throw new HttpResponseException(json($response)->contentType('text/javascript'));
}
// Output the response
throw new HttpResponseException(json($response)->contentType('text/javascript'));
}
}