cspoo/symfony-sms-bundle

symfony短信包

dev-master 2015-04-07 10:02 UTC

This package is auto-updated.

Last update: 2024-09-07 15:17:59 UTC


README

支持短信的symfony2包

激活包

在您的AppKernel

    new cspoo\SmsBundle\cspooSmsBundle(),

配置示例

# config.yml
cspoo_sms:
    default_transport: winic
    transports:
        -
            name: winic
            type: winic
            username: foo
            password: bar

在控制器中的使用

        $smsSender = $this->container->get('sms');
        $sms = $smsSender->createSms($phone, $token);
        $smsSender->sendSms($sms);

添加您自己的提供者

如果您有一个需要用户名/密码的提供者,您可以通过以下步骤简单地添加它

创建一个传输类

在传输文件夹中添加一个名为MyOwnTransport.php的类,并在其中放入以下内容

<?php

namespace cspoo\SmsBundle\Transport;

use cspoo\SmsBundle\Model\Sms;

class WinicTransport extends BaseTransport
{

    public function getName()
    {
        return 'name of the provider';
    }

    public function sendSms(Sms $sms)
    {
        $id = urlencode($this->getUsername());
        $password = urlencode($this->getPassword());
        $to = urlencode($sms->getRecipient());
        $content = urlencode($sms->getMessage());

        // your provider specific code

        // return whatever you want
        return 42;
    }
}

在SMS工厂中添加您的传输类

Services文件夹中,您可以通过编辑SmsFactory.php来向loadTransport方法添加您的新类

在可能的配置参数列表中添加您的传输名称

DependencyInjection/Configuration.php中,您可以在可能的条目列表中提供名称