akanunov / easy-sms-bundle
将easy-sms库集成到您的Symfony项目中。
v0.0.3
2024-03-24 19:35 UTC
Requires
- php: ^7.0|^8.1
- overtrue/easy-sms: ^1.1
- symfony/framework-bundle: ^3.4|^4.4|^5.4|^6.4
Requires (Dev)
- phpunit/phpunit: ^4.4|^9
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() ; } }