akanunov/easy-sms-bundle

将easy-sms库集成到您的Symfony项目中。

安装: 43

依赖: 0

建议者: 0

安全性: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

v0.0.3 2024-03-24 19:35 UTC

This package is auto-updated.

Last update: 2024-09-24 20:56:29 UTC


README

步骤 1:下载Bundle

打开命令行控制台,进入您的项目目录,并执行以下命令以下载此bundle的最新稳定版本

$ composer require akanunov/easy-sms-bundle

此命令需要您已全局安装Composer,如Composer文档中的安装章节所述。

步骤 2:启用Bundle

然后,通过将其添加到项目中注册的bundle列表中来启用bundle,在您的项目的app/AppKernel.php文件中

// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...
            new Akanunov\EasySmsBundle\AkanunovEasySmsBundle(),
        ];

        // ...
    }

    // ...
}

步骤 3:配置您的短信网关

# app/config/config.yml
akanunov_easy_sms:
    gateways:
      aliyun:
        access_key_id:        "%aliyun_access_key%"
        access_key_secret:    "%aliyun_key_secret%"
        sign_name:            "%aliyun_sign_name%"
    default:
        gateways: ['aliyun']

有关其他参数的更多详细信息,请参阅Easy SMS文档

步骤 4:配置自定义短信网关

更新配置文件

# app/config/config.yml
akanunov_easy_sms:
    gateways:
        mygateway:
            api_key: "%mygateway_api_key%"
    default:
        gateways: ['mygateway']
    custom_gateways:  
        mygateway:
          gateway_class: App\EasySms\Gateways\MyGateway
          configuration_factory_class: App\DependencyInjection\Factory\Gateway\MyGatewayFactory

创建网关配置工厂

<?php

namespace App\DependencyInjection\Factory\Gateway;

use Akanunov\EasySmsBundle\DependencyInjection\Factory\GatewayFactoryInterface;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;

class MyGatewayFactory implements GatewayFactoryInterface
{
    public function addConfiguration(NodeDefinition $node)
    {
        $node
            ->children()
                ->scalarNode('api_key')
                    ->isRequired()
                    ->cannotBeEmpty()
                ->end()
            ->end()
        ;
    }
}