m-rubin-itmegastar-com / sms-bundle
支持不同提供商的短信发送系统
1.2.1
2018-10-01 08:38 UTC
Requires
- php: >=7.1.0
- guzzlehttp/guzzle: ^6.3
- symfony/framework-bundle: ~3.3|^4.0
Requires (Dev)
- phpunit/phpunit: ^7.2
- symfony/console: ^4.0
This package is auto-updated.
Last update: 2024-09-29 05:41:42 UTC
README
此包可以帮助您将短信消息集成到项目中
安装
您可以通过以下命令安装此包
$ composer require itmegastar/sms-bundle ^1.2
配置
您可以定义任意多的提供商配置。可用的提供商有
- Message Bird [messagebird.com]
- Sms Ru [sms.ru]
- Sms Aero [smsaero.ru]
- Sms Discount [iqsms.ru]
- Sms Center [smsc.ru]
使用方法
在您的控制器中
<?php // src/Controller/FooController.php namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use ITMegastar\Bundle\SmsBundle\Service\ProviderManager; use ITMegastar\Bundle\SmsBundle\Sms\Sms; class FooController extends Controller { public function barAction(ProviderManager $providerManager) { $sms = new Sms('+12345678900', 'The cake is a lie'); $provider = $providerManager->getProvider('your_provider_name'); $provider->send($sms); } }
如果您想安排短信发送
<?php // src/Controller/FooController.php namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use ITMegastar\Bundle\SmsBundle\Service\ProviderManager; use ITMegastar\Bundle\SmsBundle\Sms\Sms; class FooController extends Controller { public function barAction(ProviderManager $providerManager) { // Your selected sms provider $provider = $providerManager->getProvider('your_provider_name'); // Date of sms delivery $worldCupStartDate = (new \DateTime("2018:06:30 00:00:00"))->setTimezone(new \DateTimeZone('Europe/London')); $remindDate = (new \DateTime())->add(new \DateInterval('PT5M')); // Create new delayed sms $worldCupStartSms = new Sms('+12345678900', '2018 FIFA World Cup started!', $worldCupStartDate); $remindSms = new Sms('+12345678900', 'I will remind you of football', $remindDate); // Send delayed delivery to provider $provider->send($worldCupStartSms); // will be sent at 2018:06:30 00:00:00 $provider->send($remindSms); // will be sent after 5 minutes } }
提示
您可以通过以下命令检查短信发送
$ php bin/console itmegastar:sms:delivery:test [your_provider_name] [your_phone_number] [your_message_text]