tourze / json-rpc-http-direct-call-bundle
JsonRPC另外一种调用方式
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.1
- ext-json: *
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-foundation: ^6.4
- symfony/http-kernel: ^6.4
- symfony/routing: ^6.4
- symfony/uid: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/backtrace-helper: ~0.0.5
- tourze/json-rpc-core: ^0.0.6
- tourze/json-rpc-encrypt-bundle: 0.1.*
- tourze/json-rpc-endpoint-bundle: 0.1.*
- tourze/symfony-routing-auto-loader-bundle: 0.0.*
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
README
JsonRPC另外一种调用方式,为Symfony应用提供JSON-RPC HTTP直接调用功能。
特性
- 支持HTTP直接调用JSON-RPC服务
- 支持加密和解密请求/响应
- 提供多种调用接口形式
安装
composer require tourze/json-rpc-http-direct-call-bundle
配置
将Bundle添加到你的config/bundles.php
文件中:
return [ // ... Tourze\JsonRPCHttpDirectCallBundle\JsonRPCHttpDirectCallBundle::class => ['all' => true], ];
使用方法
通过HTTP POST调用JSON-RPC方法
// 发送POST请求到 /json-rpc/{前缀}/{方法名}.aspx // 或者 /cp/json-rpc/{方法名}.aspx
通过直接POST调用
// 发送POST请求到 /json-rpc/call/{方法名}
单元测试
在项目根目录执行以下命令运行单元测试:
./vendor/bin/phpunit packages/json-rpc-http-direct-call-bundle/tests
测试架构
测试目录结构与源代码目录结构保持一致:
tests/
├── Controller/ # 控制器测试
├── DependencyInjection/ # 依赖注入扩展测试
├── Integration/ # 集成测试
├── Service/ # 服务测试
└── .gitignore # Git忽略配置
开发说明
-
主要类和功能:
JsonRPCHttpDirectCallBundle
- 主Bundle类JsonRpcController
- 提供直接调用JSON-RPC服务的控制器AttributeControllerLoader
- 自动加载控制器路由的服务
-
控制器提供两种调用方式:
directCall
- 通过/json-rpc/{prefix}/{method}.aspx
或/cp/json-rpc/{method}.aspx
路径调用directPost
- 通过/json-rpc/call/{method}
路径调用
-
支持加密请求和响应,通过
encryptor
服务处理加密和解密