From 24a1a67e274c3dcbe6b825ab0e0e9af9b886adf9 Mon Sep 17 00:00:00 2001 From: Anyon Date: Mon, 16 Dec 2019 11:43:34 +0800 Subject: [PATCH] ComposerUpdate --- composer.lock | 8 +-- vendor/composer/installed.json | 8 +-- vendor/services.php | 2 +- .../src/service/JsonRpcClientService.php | 69 +++++-------------- .../src/service/JsonRpcServerService.php | 42 +++++------ 5 files changed, 46 insertions(+), 83 deletions(-) diff --git a/composer.lock b/composer.lock index 207ccdb8a..1937e5ed5 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 190f64007..c1875a43e 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -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": { diff --git a/vendor/services.php b/vendor/services.php index 0d1ff6d57..e1f479a33 100644 --- a/vendor/services.php +++ b/vendor/services.php @@ -1,5 +1,5 @@ 'think\\app\\Service', diff --git a/vendor/zoujingli/think-library/src/service/JsonRpcClientService.php b/vendor/zoujingli/think-library/src/service/JsonRpcClientService.php index b3b794a70..bcfc0af70 100644 --- a/vendor/zoujingli/think-library/src/service/JsonRpcClientService.php +++ b/vendor/zoujingli/think-library/src/service/JsonRpcClientService.php @@ -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']}"); } } } \ No newline at end of file diff --git a/vendor/zoujingli/think-library/src/service/JsonRpcServerService.php b/vendor/zoujingli/think-library/src/service/JsonRpcServerService.php index 3a2900ab2..9441783fd 100644 --- a/vendor/zoujingli/think-library/src/service/JsonRpcServerService.php +++ b/vendor/zoujingli/think-library/src/service/JsonRpcServerService.php @@ -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 "

method {$method}()

"; - 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 "

" . get_class($object) . "

"; + foreach (get_class_methods($object) as $method) { + if ($method[0] !== '_') echo "

method {$method}()

"; } - } 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')); } } \ No newline at end of file