tourze/json-rpc-http-direct-call-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tourze/json-rpc-http-direct-call-bundle

最新稳定版本:1.1.0

Composer 安装命令:

composer require tourze/json-rpc-http-direct-call-bundle

包简介

JsonRPC另外一种调用方式

README 文档

README

English | 中文

Latest Version Total Downloads PHP Version Require License codecov

A Symfony bundle that provides HTTP direct call functionality for JSON-RPC services. This bundle offers an alternative approach to JSON-RPC invocation through HTTP endpoints.

Features

  • HTTP direct calls to JSON-RPC services
  • Request/response encryption and decryption support
  • Multiple calling interface forms
  • Automatic route loading with attributes
  • Built-in error handling and logging
  • Support for prefixed and non-prefixed endpoints

Requirements

  • PHP 8.2 or higher
  • Symfony 7.3 or higher
  • ext-json

Installation

composer require tourze/json-rpc-http-direct-call-bundle

Configuration

Add the bundle to your config/bundles.php file:

return [
    // ...
    Tourze\JsonRPCHttpDirectCallBundle\JsonRPCHttpDirectCallBundle::class => ['all' => true],
];

Quick Start

Direct Call Endpoint

Send POST requests to JSON-RPC methods using these endpoints:

# With prefix
POST /json-rpc/{prefix}/{method}.aspx

# Without prefix (CP endpoint)
POST /cp/json-rpc/{method}.aspx

Example request:

curl -X POST http://localhost/json-rpc/user/getInfo.aspx \
  -H "Content-Type: application/json" \
  -H "request-id: unique-request-id" \
  -d '{"userId": 123}'

Direct POST Endpoint

Send POST requests directly to methods:

POST /json-rpc/call/{method}

Example request:

curl -X POST http://localhost/json-rpc/call/getUser \
  -d "userId=123&includeProfile=true"

Usage

Controllers

The bundle provides two main controllers:

  1. DirectCallController - Handles requests to /json-rpc/{prefix}/{method}.aspx and /cp/json-rpc/{method}.aspx
  2. DirectPostController - Handles requests to /json-rpc/call/{method}

Encryption Support

The bundle supports request/response encryption when the encryptor service detects encrypted endpoints:

// Automatic encryption detection based on request path
if ($this->encryptor->shouldEncrypt($request)) {
    $decryptedContent = $this->encryptor->decryptByRequest($request, $content);
    // Process decrypted content...
}

Request ID Handling

The bundle automatically handles request IDs:

  • Uses request-id header if provided
  • Generates UUID v4 if not provided
  • Prefixes with endpoint prefix for tracking

Architecture

src/
├── Controller/
│   ├── DirectCallController.php    # Main JSON-RPC endpoint controller
│   └── DirectPostController.php    # Direct POST endpoint controller
├── DependencyInjection/
│   └── JsonRPCHttpDirectCallExtension.php  # Service configuration
├── Exception/
│   └── UnexpectedControllerException.php   # Custom exceptions
├── Service/
│   └── AttributeControllerLoader.php       # Route auto-loader
└── JsonRPCHttpDirectCallBundle.php         # Bundle class

Testing

Run tests from the project root directory:

./vendor/bin/phpunit packages/json-rpc-http-direct-call-bundle/tests

Test coverage includes:

  • Unit tests for all components
  • Integration tests for complete workflows
  • Mock services for dependencies

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-27