veejay / jsonrpc
JSONRPC 服务器和客户端
v1.0.0
2021-02-22 18:22 UTC
Requires
- php: >=7.2.0
- ext-json: *
Requires (Dev)
- codeception/codeception: ^4.1
- codeception/module-asserts: ^1.0.0
This package is auto-updated.
Last update: 2024-09-23 02:01:33 UTC
README
Jsonrpc 2.0,用于通过 HTTP(S) 在 PHP 中。
示例
服务器
首先,您需要扩展 veejay\jsonrpc\Api 类并添加所需的方法
class MyApi extends Api { public function myMethod(array $params) { extract($params); if (!isset($myParam)) { throw new Exception(Response::INVALID_PARAMS); } return 'some result with param: ' . $myParam; } }
然后运行以下代码启动 Server
$server = new Server(new MyApi); echo $response = $server->run();
客户端
$client = new Client('https://jsonrpc/server/address'); $query = $client->query('myMethod', ['my_param' => 1]); $client->notify('myMethod'); $client->send();
您将在 $query 变量中收到 myMethod 的响应。
要求
- PHP 7.2+
安装
composer require "veejay/jsonrpc"