定制 leandro980/skebby-bundle 二次开发

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

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

leandro980/skebby-bundle

Composer 安装命令:

composer require leandro980/skebby-bundle

包简介

A bundle to send SMS through Skebby service

README 文档

README

This is an unofficial Symfony5 bundle for the Skebby sms service provider.

Installation

The suggested installation method is via composer:

$ composer require leandro980/skebby-bundle

Configuration

Enable the bundle in config/bundles.php

return [
    // ...
    // ...
    Szopen\SkebbyBundle\SkebbyBundle::class => ['all' => true],
];

In your config/packages/skebby_bundle.yaml:

skebby:

  # Add your Skebby account credentials
  username: 'yourskebbyusername'
  password: 'yourskebbypassword'
  
  # Skebby provides two kinds of authentication:
  #   - Getting a Session Id that expires in 5 minutes if no request is sent
  #   - Getting a Token always valid
  # Allowed values are: 
  #   - token (default)
  #   - session
  #
  # auth_type: 'token'
  
  # You can choose which kind of sms send between:
  #   - "GP" for Classic+ (limited to 1530 chars, delivery warranty, delivery report)
  #   - "TI" for Classic (limited to 1530 chars, delivery warranty)
  #   - "SI" for Basic (limited to 160 chars, no delivery warranty)
  #
  # message_type: 'TI'
  
  # You can also add a default sender alias used to send SMS.
  # This overrides the default alias set in Skebby account but must be one of the alias 
  # already registered. 
  # If the message type allows a custom TPOA and the field is left empty, the user’s preferred TPOA
  # is used. Must be empty if the message type does not allow a custom TPOA.
  #
  # default_sender_alias: ""

Simple Symfony Usage

You have access to the SkebbyManager service in your controller.

Check your account status

use Szopen\SkebbyBundle\Model\Manager\SkebbyManager;

// ..

/**
 * @Route("/skebby/status", name="skebby.status")
 */
public function statusAction(SkebbyManager $skebby)
{

    $s = $skebby->getStatus();

    return $this->render('skebby/index.html.twig', [
        'status' => $s,
    ]);
}

SkebbyManager::getStatus returns a Szopen\SkebbyBundle\Model\Response\Status

Send an SMS

use Szopen\SkebbyBundle\Model\Manager\SkebbyManager;
use Szopen\SkebbyBundle\Model\Data\Recipient;

// ..

/**
 * @Route("/skebby/send", name="skebby.sendsms")
 */
public function sendSmsAction(SkebbyManager $skebby)
{

    $sms = $skebby->createDefaultSms('Hello, this is a test message',
    [new Recipient('3331234567'), new Recipient('3207654321')]);

    $response = $skebby->sendSms($sms);

    return $this->render('skebby/index.html.twig', [
        'response' => $response,
    ]);
}

SkebbyManager::sendSms returns a Szopen\SkebbyBundle\Model\Response\SmsResponse

Documentation

The Skebby bundle uses a set of clients classes that perform their specific API calls. The SkebbyManager is a service that wraps all the clients methods. Please refer to Official Skebby Developer Documentation for further info.

Authenticators

You can choose which kind of authentication to use by AuthenticatorFactory class.

use Szopen\SkebbyBundle\Model\Auth\AuthenticatorFactory;

//..

// Token authentication
$auth = AuthenticatorFactory::create('token')
// Session authentication
// $auth = AuthenticatorFactory::create('session')

// Used to authenticate in later API calls
$arrayAccess = $auth->login('username', 'password');

Session authentication lasts 5 minutes if no API call is performed.

UserClient

Class dedicated to the User/Account API calls.

use Szopen\SkebbyBundle\Model\Auth\AuthenticatorFactory;
use Szopen\SkebbyBundle\Model\Client\UserClient;

//..

// Token authentication
$auth = AuthenticatorFactory::create('token')

$userClient = new UserClient('username', 'password', $auth);

You can read more on methods comments of Szopen\SkebbyBundle\Model\Client\UserClient

SmsClient

Class dedicated to the Sms API calls.

Sending a Simple Sms.

use Szopen\SkebbyBundle\Model\Auth\AuthenticatorFactory;
use Szopen\SkebbyBundle\Model\Client\SmsClient;
use Szopen\SkebbyBundle\Model\Data\Recipient;

//..

// Token authentication
$auth = AuthenticatorFactory::create('token')

$smsClient = new SmsClient('username', 'password', $auth);

// Creating an sms
// You must choose which kind of SMS type to send 
$sms = new Sms(Sms::SMS_CLASSIC_KEY);

// Add a message
// SmsClient choose wich kind of encoding to use, between UCS2 and GSM, 
// authomatically parsing the message.
// It also counts chars available based on encoding, if the ength of the message exceeds the limit
// it raises a MessageLengthException
$sms->setMessage("Hello, this is a GSM encoded message");
// Substitutes message
$sms->setMessage("Hello, this is a UCS2 encoded message because of ç char");

// Set sender
// You can add sender only if your not using BASIC SMS and the aliasis registered to your account
$sms->setSender('YourAlias');

// Creating and adding a Recipient
// When you create a "Recipient" it parses the phone number, if it's not valid it raises
// a \libphonenumber\NumberParseException 
$recipient = new Recipient("+393211234567");
$sms->addRecipient($recipient);

// Sending SMS
$smsResponse = $smsClient->sendSms($sms);
// You can choose to allow invalid recipients (that means that an invalid recipient 
// won't block the entire operation) and if you want have the remaining sms and credit
$smsResponse = $smsClient->sendSms($sms, 
    true, // Allow invalid recipients
    true, // Return remaining
    true, // Return credit
    );

You can send Sms to groups. In this case the recipients must be of type Group

use Szopen\SkebbyBundle\Model\Auth\AuthenticatorFactory;
use Szopen\SkebbyBundle\Model\Client\SmsClient;
use Szopen\SkebbyBundle\Model\Data\Group;

//..

// Creating and adding a recipient
$recipient = new Group("groupname");
$sms->addRecipient($recipient);

// Sending SMS
$smsResponse = $smsClient->sendGroupSms($sms);
// You can choose to allow invalid recipients (that means that an invalid recipient 
// won't block the entire operation) and if you want have the remaining sms and credit
$smsResponse = $smsClient->sendGroupSms($sms, 
    true, // Allow invalid recipients
    true, // Return remaining
    true, // Return credit
    );

Sending messages with parameters is also possible. You can't send parametric sms to groups

// Adds a message with parameters
// The system recognizes the parameters in the text 
$sms->setMessage('Hello ${name}, i know your surname is ${surname}');

// Creating and adding a Recipient with parameters
$recipient = new Recipient("+393211234567");
$recipient->addVariable('name', 'John');
$recipient->addVariable('surname', 'Dorian');
$sms->addRecipient($recipient);

// Sending SMS
// If just a Recipient does'nt contains all the parameters defined in message 
// it raises a MissingParameterException 
$smsResponse = $smsClient->sendSms($sms);

You can read more on methods comments of Szopen\SkebbyBundle\Model\Client\SmsClient

SkebbyManager

This class is configured as a Symfony5 service and wraps all the clients methods. It adds the SkebbyManager::createDefaultSms that returns an Sms using all the default parameters configured in the yaml file.

$sms = $skebby->createDefaultSms('Hello, this is a test message');
$sms->addRecipient(new Recipient("+393211234567"));
    
// You can also add recipients in constructor
$sms = $skebby->createDefaultSms('Hello, this is a test message',
    [new Recipient('3331234567'), new Recipient('3207654321')]);

You can read more on methods comments of Szopen\SkebbyBundle\Model\Manager\SkebbyManager

License

MIT License, please see LICENSE for more information.

leandro980/skebby-bundle 适用场景与选型建议

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

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

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

围绕 leandro980/skebby-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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