poirot/sms-clients

此包最新版本(dev-devel)的许可证信息不可用。

SMS 抽象;实现伊朗 SMS 服务提供商;[波斯 SMS,伊朗 SMS,magfa]。

dev-devel 2019-01-12 13:02 UTC

This package is auto-updated.

Last update: 2024-09-13 00:52:27 UTC


README

SMS 抽象;实现伊朗 SMS 服务提供商。

  • 一个抽象接口,多个提供商
  • 需要发送和已发送的 SMS 消息的实体模型
  • 已发送的消息是可序列化的,包括接收者和贡献者号码
  • 良好的面向对象设计,实现每个提供商使用多个平台(rest,soap,..)的能力
  • 简单易用,易于理解
  • 可用于 Poirot 模块生态系统

Poirot 模块

配置设置

return [
    \Module\SmsClients\Module::CONF_KEY =>
    [
        \Module\SmsClients\Services\ServiceSmsClient::CONF_CLIENT => [
            // 'service' => '/Registered/ServiceName'
            // 'service' => iClientOfSms
               // instance() let ioc to inject dependencies if required
               'service' => new \Poirot\Ioc\instance(
                   \Poirot\Sms\Driver\KavehNegar\Sms::class
                   , [
                       'api_key'  => 'your_api_key',
                       'platform' => new \Poirot\Ioc\instance(
                           \Poirot\Sms\Driver\KavehNegar\Rest\PlatformRest::class
                       )
                   ]
               ),
        ],
    ],
];

使用方法

// Every Where In Project

$sentSms = \Module\SmsClients\Services\IOC::Sms()->sendTo(...)

提供商

卡夫·内加尔

http://kavenegar.com/

$sms = new Poirot\Sms\Driver\KavehNegar\Sms([
    'api_key'     => 'your_api_key',
    'sender_line' => '10007770070777'
]);

try {
    $sentMessage = $sms->sendTo(['0935xxxxxxx'], new SMSMessage('Hello ...'));
} catch (exAuthNoCredit $e) {
    // There is no left credit
    echo ''.$sms->getRemainCredit();
    die();
}

// unique message id 
$messageId = $sentMessage->getUid();

if ($sentMessage->getStatus() === $sentMessage::STATUS_BANNED)
    die('User Has Banned SMS Messaging!!');

if ($sentMessage->getStatus() === $sentMessage::STATUS_FAILED)
    die('SMS Sent Successfuly But Failed Sending From Telecommunication!!');


// Sent Message is Serializable And Can Be Stored
$myPersitence->store($sentMessage);

// Later We Can Check The Status Of Message
$sentMessage = $sms->getSentMessageWithId($messageId);

异常

  • exAuthentication
  • exAuthNoCredit
  • exMessageMalformed
  • exServerBan
  • exServerError