承接 veejay/jsonrpc 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

veejay/jsonrpc

Composer 安装命令:

composer require veejay/jsonrpc

包简介

JSONRPC server and client

关键字:

README 文档

README

Jsonrpc 2.0 for PHP over HTTP(S).

License: MIT

Examples

Server

At first, you have to extend Veejay\Jsonrpc\Api class and add required methods:

<?php

use Veejay\Jsonrpc\Api;
use Veejay\Jsonrpc\Exception\InvalidParamsException;

class MyApi extends Api
{
    protected const TOKEN = 'qwerty';

    public function __call(string $name, array $arguments): mixed
    {
        if (!isset($arguments['token']) || self::TOKEN !== $arguments['token']) {
            throw new InvalidParamsException('Invalid token');
        }

        unset($arguments['token']);

        if (method_exists($this, $name)) {
            return call_user_func_array([$this, $name], $arguments);
        }

        return parent::__call($name, $arguments);
    }

    public function publicMethod(int $id): string
    {
        return 'Your id: ' . $id;
    }
    
    protected function protectedMethod()
    {
        return 'Protected';
    }
}

Then run Server with the following code:

<?php

use Veejay\Jsonrpc\Server;

$server = new Server(new MyApi);
echo $response = $server->run();

Client

<?php

use Veejay\Jsonrpc\Client;

$client = new Client('https://jsonrpc/server/address');

$query = $client->query('publicMethod', ['id' => 1]); // Your id: 1
$query = $client->query('protectedMethod', ['token' => 'qwerty']); // Protected
$client->notify('publicMethod');

$client->send();

You will receive the response from server in $query variables.

Requirements

  • PHP 8.0+

Installation

composer require "veejay/jsonrpc"

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固