esign/laravel-plytix 问题修复 & 功能扩展

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

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

esign/laravel-plytix

Composer 安装命令:

composer require esign/laravel-plytix

包简介

A Laravel SDK for the Plytix API

关键字:

README 文档

README

Latest Version on Packagist Total Downloads GitHub Actions

This package allow you to easily interact with the Plytix API.

Installation

You can install the package via composer:

composer require esign/laravel-plytix

The package will automatically register a service provider.

Next up, you can publish the configuration file:

php artisan vendor:publish --provider="Esign\Plytix\PlytixServiceProvider" --tag="config"

The config file will be published as config/plytix.php with the following content:

<?php

return [
    /**
     * The API key to be used for authenticating with the Plytix API.
     */
    'api_key' => env('PLYTIX_API_KEY'),

    /**
     * The API password to be used for authenticating with the Plytix API.
     */
    'api_password' => env('PLYTIX_API_PASSWORD'),

    'authenticator_cache' => [
        /**
         * The key that will be used to cache the Plytix access token.
         */
        'key' => 'esign.plytix.authenticator',

        /**
         * The cache store to be used for the Plytix access token.
         * Use null to utilize the default cache store from the cache.php config file.
         * To disable caching, you can use the 'array' store.
         */
        'store' => null,
    ],

    'rate_limiting' => [
        /**
         * The cache store to be used for the Plytix rate limits.
         * Use null to utilize the default cache store from the cache.php config file.
         * To disable caching, you can use the 'array' store.
         */
        'cache_store' => null,
    ],
];

Usage

This package leverages Saloon for sending requests to the Plytix API, providing an elegant way to interact with the API.

Authentication

After configuring your API key and password in the config file, authentication tokens are automatically managed by the package. There's no need to manually handle authentication tokens.

Rate limiting

The Plytix API enforces rate limits based on the subscription plan you’re on. You can configure these rate limits in the boot method of your AppServiceProvider:

use Esign\Plytix\Facades\RateLimiter;
use Saloon\RateLimitPlugin\Limit;

public function boot(): void
{
    RateLimiter::setLimits(
        Limit::allow(20)->everySeconds(10),
        Limit::allow(5000)->everyHour(),
    );
}

Sending requests

To send requests to the Plytix API, you may use the Esign\Plytix\Plytix connector.
You can explore all the available request classes in the src/Requests directory.
Each version of the Plytix API, such as V1 or V2, has its own folder. Note that some requests are only accessible in certain versions.
Here’s an example of sending a request:

use Esign\Plytix\Plytix;
use Esign\Plytix\Requests\V2\ProductRequest;

class MyCommand
{
    public function handle(): int
    {
        $plytix = Plytix::make();
        $response = $plytix->send(new ProductRequest('583bef16-2197-46dd-90ce-9f4210bef5ef'));

        return self::SUCCESS;
    }
}

Response handling

This package uses DTOs (Data Transfer Objects) to simplify working with API responses. You can retrieve the DTO from the response like this:

$plytix = Plytix::make();
$response = $plytix->send(new ProductRequest('583bef16-2197-46dd-90ce-9f4210bef5ef'));
$product = $response->dtoOrFail();

Alternatively, you can retrieve the raw response data:

$plytix = Plytix::make();
$response = $plytix->send(new ProductRequest('583bef16-2197-46dd-90ce-9f4210bef5ef'));
$data = $response->body();

Paginating requests

For endpoints that return paginated data, you can easily paginate through the responses:

$plytix = Plytix::make();
$paginator = $plytix->paginate(new ProductSearchRequest());

foreach ($paginator as $response) {
    $products = $response->dtoOrFail();
}

Additionally, you may also traverse through these pages using the items or collect methods.
For more information, refer to the Saloon pagination documentation.

$plytix = Plytix::make();
$paginator = $plytix->paginate(new ProductSearchRequest());

foreach ($paginator->items() as $product) {
    // Do something with the product
}

$paginator->collect()->each(function ($product) {
    // Do something with the product
});

Creating requests

Extending existing requests

If you need to customize or extend an existing request, you can create your own request class by extending the base request class:

use Esign\Plytix\Requests\ProductRequest;

class MyCustomProductRequest extends ProductRequest
{
    protected function defaultQuery(): array
    {
        return [
            'customer-query-param' => 'value',
        ];
    }

}

Creating custom requests

If the request you need is not provided by the package, you can create a custom request using Saloon. First, install the Saloon Laravel plugin, then use the following command:

php artisan saloon:request Plytix MyCustomRequest
use Saloon\Enums\Method;
use Saloon\Http\Request;

class MyCustomRequest extends Request
{
    protected Method $method = Method::GET;

    public function resolveEndpoint(): string
    {
        return '/example';
    }
}

Testing

composer test

License

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

esign/laravel-plytix 适用场景与选型建议

esign/laravel-plytix 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.38k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 09 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「esign」 「plytix」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 esign/laravel-plytix 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 esign/laravel-plytix 我们能提供哪些服务?
定制开发 / 二次开发

基于 esign/laravel-plytix 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-18