定制 selivery/enterprise-sdk-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

selivery/enterprise-sdk-php

最新稳定版本:v2.0.0

Composer 安装命令:

composer require selivery/enterprise-sdk-php

包简介

Official PHP SDK for Selivery Enterprise API

README 文档

README

Official PHP SDK for the Selivery Enterprise API.

Installation

  • Require via Composer: composer require selivery/enterprise-sdk-php
  • Requires PHP ^8.2 with ext-openssl and ext-json.

Usage

Method: send

send(...) automatically:

  • looks up the phone's public key,
  • generates a crypto‑random vector (default 32 chars),
  • encrypts each secret value using RSA PKCS#1 v1.5 (openssl_public_encrypt) with that vector, and
  • includes the resolved key_uuid and the generated vector in the request.

No sender parameter is needed (it is derived from the template on the service).

use Selivery\Enterprise\EnterpriseClient;

$client = new EnterpriseClient(getenv('SELIVERY_SECRET') ?: '');

/** @var Selivery\Enterprise\Models\SendResult $response */
$response = $client->send(
    phone: '+12025550123',
    idTemplate: 1,
    // Vector is generated automatically and used for encryption and request body
    secrets: [
        ['placeholder' => 'code', 'values' => '123456'],
    ]
);

Method: sendLight

Difference from send:

  • send encrypts values locally in the SDK and sends only encrypted chunks to Selivery. This means even Selivery (or any intermediary) cannot read your values.
  • sendLight accepts plaintext values; Selivery encrypts them as the very first step on the server and then handles only encrypted values afterward. Both methods are secure; send offers an even stricter privacy boundary since plaintext never leaves your process.
/** @var Selivery\Enterprise\Models\SendResult $response */
$response = $client->sendLight(
    phone: '+12025550123',
    idTemplate: 1,
    secrets: [
        ['key' => 'code', 'values' => '123456'],
    ]
);

Token caching (PSR-16)

Inject any PSR-16 cache to enable automatic caching and refresh of OAuth tokens.

use Selivery\Enterprise\EnterpriseClient;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Psr16Cache;

$pool = new FilesystemAdapter(namespace: 'selivery', defaultLifetime: 0);
$psr16 = new Psr16Cache($pool);

// Options (optional):
// - base_url: override API base URL
// - timeout: request timeout in seconds
// - cache_key: override default key (default: selivery_enterprise_sdk_tokens:{sha1(baseUrl)})
// - token_safety_window: seconds before expiry to refresh (default: 60)

$client = new EnterpriseClient(
    secret: getenv('SELIVERY_SECRET') ?: '',
    cache: $psr16,
    options: [
        'token_safety_window' => 60,
        // 'cache_key' => 'custom_key_per_env',
    ]
);

// The SDK generates tokens automatically on the first request,
// then reuses and refreshes them through the cache.

Examples

  • Send message: SELIVERY_SECRET=your-secret php examples/service_send.php
  • Send light message: SELIVERY_SECRET=your-secret php examples/service_send_light.php

Notes

  • EnterpriseClient is the only public entry point. Call send(...) or sendLight(...) on it directly.
  • The SDK uses your secret only for generate-token.
  • Service requests use the generated access_token automatically.
  • If a cache is provided, the SDK stores both access and refresh tokens and refreshes the access token when needed.
  • POST endpoints accept JSON bodies; include Content-Type: application/json.
  • The sender field has been removed from SDK methods and requests; it is derived from the template server‑side.
  • Token cache key default: selivery_enterprise_sdk_tokens:{sha1(baseUrl)}. Avoid putting secrets in cache keys.
  • Safety window default: 60s. Treats token as expired when now >= expires_at - safety_window.

PSR-16 implementations

  • Symfony Cache: Psr16Cache over FilesystemAdapter (disk) or RedisAdapter (Redis).
  • Any PSR-16 provider is supported: pass your Psr\SimpleCache\CacheInterface to EnterpriseClient.

See examples:

  • Symfony filesystem cache: php examples/cache_symfony.php
  • Symfony Redis cache: php examples/cache_redis_symfony.php

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固