PHP编写的JSON RPC库:jsonrpc
jopen
11年前
jsonrpc是一个用PHP编写的JSON RPC库。它支持自定义传输(一个cURL实现)和定制编解码器,(JSON RPC1.0)。
<?php use \FritzPayment\JsonRpc\Rpc\Codec\JsonRpc10; use \FritzPayment\JsonRpc\Client\Transport\Curl; // initialize JSON RPC 1.0 Codec $codec = new JsonRpc10(); // initialize cURL transport $transport = new Curl(); // initialize client $client = new \FritzPayment\JsonRpc\Client('http://www.example.com', $codec, $transport); // create a new request /* @var $request \FritzPayment\JsonRpc\Rpc\Codec\JsonRpc10\Request */ $request = $client->newRequest(); $request->setMethod('test.echo') ->setId('1'); $request->setParams(array('test message')); // send request $response = $client->exec($request); if ($response === false) { // failed } else { if ($response->isError()) { // JSON RPC error echo $response->getError()->error(); } else { var_dump($response->getResult()); } }