fritz-payment / jsonrpc
通用的 JSON RPC 客户端。
0.1.0
2013-05-17 09:22 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-23 14:03:08 UTC
README
PHP 通用 JSON RPC 实现。
- 支持不同的传输方式(目前有 cURL 实现)。
- 不同的 JSON RPC 编解码器(目前实现了由 http://json-rpc.org/wiki/specification 定义的 JSON RPC 版本 1.0;JSON RPC 2.0 将很快支持)。
- 干净的 API。
项目 Wiki
新功能
版本 0.2.0
- 实现了 JSON RPC 2.0 编解码器。
版本 0.1.0
- 完成基本实现。
入门
安装
您可以使用 Composer (http://www.getcomposer.org) 安装 JSON RPC 库。
{
"require": {
"fritz-payment/jsonrpc": "dev-master"
}
}
用法
以下示例使用 cURL 在 URL http://www.example.com 上调用 JSON RPC 1.0 方法 "test.echo"。
<?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());
}
}
扩展库
可以创建自己的传输和编解码器实现。
抽象的传输和编解码器类以及现有的实现应能为您提供一些思路。