定制 gsmservice-pl/messaging-sdk-php 二次开发

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

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

gsmservice-pl/messaging-sdk-php

Composer 安装命令:

composer require gsmservice-pl/messaging-sdk-php

包简介

README 文档

README

Packagist Version GitHub License Static Badge

SzybkiSMS.pl Messaging REST API SDK for PHP (powered by GSMService.pl)

This package includes Messaging SDK for PHP (>8.2) to send SMS & MMS messages directly from your app via https://szybkisms.pl messaging platform.

Additional documentation:

A documentation of all methods and types is available below in section Available Resources and Operations .

Also you can refer to the REST API documentation for additional details about the basics of this SDK.

Table of Contents

SDK Installation

The SDK relies on Composer to manage its dependencies.

To install the SDK and add it as a dependency to an existing composer.json file:

composer require "gsmservice-pl/messaging-sdk-php"

Requeirements:

  • Minimal PHP version: 8.2

SDK Example Usage

Sending single SMS Message

This example demonstrates simple sending SMS message to a single recipient:

declare(strict_types=1);

require 'vendor/autoload.php';

use Gsmservice\Gateway;
use Gsmservice\Gateway\Models\Components;

$sdk = Gateway\Client::builder()
    ->setSecurity(
        '<YOUR API ACCESS TOKEN>'
    )
    ->build();

$request = new Components\SmsMessage(
    recipients: '+48999999999',
    message: 'This is SMS message content.',
    unicode: true,
);

$response = $sdk->outgoing->sms->send(
    request: $request
);

if ($response->messages !== null) {
    // handle response
}

Sending single MMS Message

This example demonstrates simple sending MMS message to a single recipient:

declare(strict_types=1);

require 'vendor/autoload.php';

use Gsmservice\Gateway;
use Gsmservice\Gateway\Models\Components;

$sdk = Gateway\Client::builder()
    ->setSecurity(
        '<YOUR API ACCESS TOKEN>'
    )
    ->build();

$request = new Components\MmsMessage(
    recipients: '+48999999999',
    subject: 'This is a subject of the message',
    message: 'This is MMS message content.',
    attachments: '<file body in base64 format>',
);

$response = $sdk->outgoing->mms->send(
    request: $request
);

if ($response->messages !== null) {
    // handle response
}

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

Name Type Scheme
bearer http HTTP Bearer

To authenticate with the API the bearer parameter must be set when initializing the SDK. For example:

declare(strict_types=1);

require 'vendor/autoload.php';

use Gsmservice\Gateway;

$sdk = Gateway\Client::builder()
    ->setSecurity(
        '<YOUR API ACCESS TOKEN>'
    )
    ->build();



$response = $sdk->accounts->get(

);

if ($response->accountResponse !== null) {
    // handle response
}

Available Resources and Operations

Available methods

Accounts

Common

  • ping - Checks API availability and version

Incoming

  • list - List the received SMS messages
  • getByIds - Get the incoming messages by IDs
  • removeByIds - Remove the incoming messages from your inbox

Outgoing

  • getByIds - Get the messages details and status by IDs
  • cancelScheduled - Cancel a scheduled messages
  • list - Lists the history of sent messages

Outgoing.Mms

  • getPrice - Check the price of MMS Messages
  • send - Send MMS Messages

Outgoing.Sms

  • getPrice - Check the price of SMS Messages
  • send - Send SMS Messages

Senders

  • list - List allowed senders names
  • add - Add a new sender name
  • delete - Delete a sender name
  • setDefault - Set default sender name

Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide an Options object built with a RetryConfig object to the call:

declare(strict_types=1);

require 'vendor/autoload.php';

use Gsmservice\Gateway;
use Gsmservice\Gateway\Utils\Retry;

$sdk = Gateway\Client::builder()
    ->setSecurity(
        '<YOUR API ACCESS TOKEN>'
    )
    ->build();



$response = $sdk->accounts->get(
    options: Utils\Options->builder()->setRetryConfig(
        new Retry\RetryConfigBackoff(
            initialInterval: 1,
            maxInterval:     50,
            exponent:        1.1,
            maxElapsedTime:  100,
            retryConnectionErrors: false,
        ))->build()
);

if ($response->accountResponse !== null) {
    // handle response
}

If you'd like to override the default retry strategy for all operations that support retries, you can pass a RetryConfig object to the SDKBuilder->setRetryConfig function when initializing the SDK:

declare(strict_types=1);

require 'vendor/autoload.php';

use Gsmservice\Gateway;
use Gsmservice\Gateway\Utils\Retry;

$sdk = Gateway\Client::builder()
    ->setRetryConfig(
        new Retry\RetryConfigBackoff(
            initialInterval: 1,
            maxInterval:     50,
            exponent:        1.1,
            maxElapsedTime:  100,
            retryConnectionErrors: false,
        )
  )
    ->setSecurity(
        '<YOUR API ACCESS TOKEN>'
    )
    ->build();



$response = $sdk->accounts->get(

);

if ($response->accountResponse !== null) {
    // handle response
}

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.

By default an API error will raise a Errors\SDKException exception, which has the following properties:

Property Type Description
$message string The error message
$statusCode int The HTTP status code
$rawResponse ?\Psr\Http\Message\ResponseInterface The raw HTTP response
$body string The response content

When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the get method throws the following exceptions:

Error Type Status Code Content Type
Errors\ErrorResponse 401, 403, 4XX application/problem+json
Errors\ErrorResponse 5XX application/problem+json

Example

declare(strict_types=1);

require 'vendor/autoload.php';

use Gsmservice\Gateway;
use Gsmservice\Gateway\Models\Errors;

$sdk = Gateway\Client::builder()
    ->setSecurity(
        '<YOUR API ACCESS TOKEN>'
    )
    ->build();

try {
    $response = $sdk->accounts->get(

    );

    if ($response->accountResponse !== null) {
        // handle response
    }
} catch (Errors\ErrorResponseThrowable $e) {
    // handle $e->$container data
    throw $e;
} catch (Errors\ErrorResponseThrowable $e) {
    // handle $e->$container data
    throw $e;
} catch (Errors\SDKException $e) {
    // handle default exception
    throw $e;
}

Server Selection

Select Server by Name

You can override the default server globally using the setServer(string $serverName) builder method when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers:

Name Server Description
prod https://api.szybkisms.pl/rest Production system
sandbox https://api.szybkisms.pl/rest-sandbox Test system (SANDBOX)

Example

declare(strict_types=1);

require 'vendor/autoload.php';

use Gsmservice\Gateway;

$sdk = Gateway\Client::builder()
    ->setServer('prod')
    ->setSecurity(
        '<YOUR API ACCESS TOKEN>'
    )
    ->build();



$response = $sdk->accounts->get(

);

if ($response->accountResponse !== null) {
    // handle response
}

Override Server URL Per-Client

The default server can also be overridden globally using the setServerUrl(string $serverUrl) builder method when initializing the SDK client instance. For example:

declare(strict_types=1);

require 'vendor/autoload.php';

use Gsmservice\Gateway;

$sdk = Gateway\Client::builder()
    ->setServerURL('https://api.szybkisms.pl/rest')
    ->setSecurity(
        '<YOUR API ACCESS TOKEN>'
    )
    ->build();



$response = $sdk->accounts->get(

);

if ($response->accountResponse !== null) {
    // handle response
}

Development

Maturity

This SDK is in continuous development and there may be breaking changes between a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.

gsmservice-pl/messaging-sdk-php 适用场景与选型建议

gsmservice-pl/messaging-sdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 465 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 10 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 gsmservice-pl/messaging-sdk-php 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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