定制 phpinfo/smsfeedback 二次开发

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

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

phpinfo/smsfeedback

Composer 安装命令:

composer require phpinfo/smsfeedback

包简介

SmsFeedback simple SDK

关键字:

README 文档

README

This component allows you to simply work with smsfeedback.ru base API.

See service API documentation for more detailed information.

Installation

composer require phpinfo/smsfeedback

Simple Usage

The best way to instantiate API client is to use ApiClientBuilder:

$client = ApiClientFactory::createApiClient('login', 'password');

$client->send('71234567', 'Some SMS Text');

You can specify connection timeout (in msec) or API base URI:

$client = ApiClientFactory::createApiClient('login', 'password', 'https://service.mock', 3000);

Logging Requests

SDK builder supports psr/logger. Monolog usage example:

use Monolog\Handler\StreamHandler;
use Monolog\Logger;

$handler = new StreamHandler(STDOUT);
$logger  = new Logger('SmsFeedback', [$handler]);
        
$client = ApiClientFactory::createApiClient('login', 'password', null, null, $logger);
$client->balance();

Will output:

[2019-05-19 20:21:34] SmsFeedback.INFO: GET /messages/v2/balance HTTP/1.1 200 [] []

Symfony 4

See SmsFeedback Symfony Bundle for easy integration.

You can use ApiClientFactory in your DI container as well:

SmsFeedback\ApiClientInterface:
    factory: ['SmsFeedback\Factory\ApiClientFactory', 'createApiClient']
    arguments:
        $login: '%env(SMSFEEDBACK_LOGIN)%'
        $password: '%env(SMSFEEDBACK_PASSWORD)%'

Sending SMS

Simply sends SMS:

$message = $client->send('79161234567', 'SMS Text');
Argument Type Description Example
phone string Phone number 79161234567
text string SMS Text Some SMS Text
sender ?string Sender short name SENDER
statusQueueName ?string SMS status queue name my-queue
scheduleTime ?string Scheduled time to send message (UTC only) 2009-01-01T12:30:01+00:00

Response object:

{
    "id": "A133541BC",
    "status": "accepted"
}

Retrieving SMS status

$statuses = $client->status(['5169837636', '5169837647']);
[
    {
        "id": "5169837636",
        "status": "delivered"
    },
    {
        "id": "5169837647",
        "status": "delivery error"
    }
]

Retrieving balance

$balances = $client->balance();
[
    {
        "type": "RUB",
        "amount": 385.5,
        "credit": 0.0
    }
]

Retrieving senders

$senders = $client->senders();
[
    {
        "name": "SENDER",
        "status": "active",
        "comment": "Some sender comment"
    }
]

Manual control

SDK uses Guzzle 6 under the hood. You can specify Guzzle params directly:

$client = ApiClientBuilder::create('login', 'password')
    ->setHttpClientParams(
        [
            'base_uri' => 'https://my-domain.com',
            'timeout'  => 5.2,
        ]
    )
    ->getApiClient();

Note: Guzzle params will completely override timeout, base URI, logger and authorization features. You have to specify everything manually. In some cases it might be useful.

AuthorizationMiddleware

$stack = HandlerStack::create();

$stack->push(function (callable $handler) use ($login, $password) {
    return new AuthorizationMiddleware($handler, $login, $password);
});

$client = ApiClientBuilder::create()
    ->setHttpClientParams(
        [
            'base_uri' => 'http://api.smsfeedback.ru',
            'timeout'  => 5.0,
            'handler'  => $stack,
        ]
    )
    ->getApiClient();

Custom authorization middleware

$stack = HandlerStack::create();

$stack->push(function (callable $handler) use ($login, $password) {
    return function (RequestInterface $request, array $options) use ($handler, $login, $password) {
        $fn = $handler;

        $authHeader = sprintf('Basic %s', base64_encode($login . ':' . $password));
        $request = $request->withHeader('Authorization', $authHeader);

        return $fn($request, $options);
    };
});

$client = ApiClientBuilder::create()
    ->setHttpClientParams(
        [
            'base_uri' => 'http://api.smsfeedback.ru',
            'timeout'  => 5.0,
            'handler'  => $stack,
        ]
    )
    ->getApiClient();

Logger middleware

$stack = HandlerStack::create();

$logger    = new Logger('SmsFeedback', [$handler]);
$formatter = new MessageFormatter(MessageFormatter::SHORT);

$stack->push(Middleware::log($logger, $formatter));

$client = ApiClientBuilder::create()
    ->setHttpClientParams(
        [
            'base_uri' => 'http://api.smsfeedback.ru',
            'timeout'  => 5.0,
            'handler'  => $stack,
        ]
    )
    ->getApiClient();

phpinfo/smsfeedback 适用场景与选型建议

phpinfo/smsfeedback 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 05 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 phpinfo/smsfeedback 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-19