fza / fitsms-bundle
使用 FitSMS.de 网关服务的短信服务
v0.2.5
2014-05-09 13:53 UTC
Requires
- symfony/symfony: >=2.3
Requires (Dev)
- symfony/config: >=2.3
- symfony/dependency-injection: >=2.3
- symfony/http-kernel: >=2.3
This package is not auto-updated.
Last update: 2024-09-14 13:20:10 UTC
README
此扩展包提供了一种方便的方法,使用 FitSMS.de 网关服务发送短信。
功能
- 每个短信支持多个接收者
- 验证电话号码(发送者和接收者)
- 将电话号码扩展以满足国际标准
- 默认国家前缀可配置
- 能够检查最大短信部分数
- NumLock/IPLock 支持(请参阅 FitSMS 网关文档)
安装
将此扩展包添加到您的 composer.json 中
{ "require": { "fza/fitsms-bundle": "*" } }
运行 composer 并下载扩展包
$ php composer.phar update
在 AppKernel 中启用扩展包
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Fza\FitSmsBundle\FzaFitSmsBundle(), ); }
配置
将以下行添加到您的 config.yml 中
fza_fit_sms: default_intl_prefix: 49 username: "123456" password: "password" tracking: true # Default values are just fine here debug_test: ~ gateway_uri: ~ max_sms_part_count: ~ numlock: ~ iplock: ~
注意
default_intl_prefix: (int) 设置未检测到电话号码的国家前缀时的默认国家前缀username,password: (string) 自解释tracking: (bool) 启用在短信中传输唯一请求 ID 并记录。您还可以在 FitSMS 控制面板中查看此 ID。gateway_uri: (string) 如果网关 URI 以后更改,您可以覆盖默认值debug_test: (bool) 默认为内核环境中的调试值,并在发送短信时设置debug标志(将传输到网关,但不会实际发送)max_sms_part_count: (int) 默认为 6numlock,iplock: (bool) 使用这些来启用限制发送给接收者的短信数量/在您的服务器 IP 地址一小时内的发送数量。这些只是布尔值,数字限制需要在 FitSMS 控制面板中配置。
使用方法
use Fza\FitSmsBundle\SmsMessage; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class MyController extends Controller { public function smsAction() { // Send to multiple recipients with an array of phone numbers // Note that you should set phone numbers as strings to preserve leading zeros $recipient = '0049123456789'; $message = this->renderView('MyBundle::sms.txt.twig'); $sms = new SmsMessage($recipient, $message); $from = '0049123456789'; $timeToSend = new \DateTime('2012-01-01 14:00:00'); try { // $timeToSend parameter is optional (will send immediately) $smsSent = $this->get('fitsms.gateway')->sendMessage($sms, $from, $timeToSend); if (!$smsSent) { // Handle gateway errors (insufficient credit etc.) } } catch (\Exception $e) { // Catch exceptions (mostly due to invalid arguments) } } }