mocean / symfony-mocean-bundle
适用于Symfony框架的Mocean API
v2.0.0
2019-06-24 10:05 UTC
Requires
- mocean/client: ^2.0
- symfony/framework-bundle: ^3.0.0|^4.0.0
Requires (Dev)
- phpunit/phpunit: ~4.5
This package is auto-updated.
Last update: 2024-09-29 05:02:15 UTC
README
Symfony Mocean API集成
安装
要安装库,请在终端中运行此命令
composer require mocean/symfony-mocean-bundle
将以下内容添加到config.yml
mocean: defaults: main # define the account to use here accounts: # here is where you define multiple accounts main: api_key: mainAccountApiKey api_secret: mainAccountApiSecret secondary: api_key: secondaryAccountApiKey api_secret: secondaryAccountApiSecret
Symfony 4
将bundle添加到config/bundles.php
return [ //... framework bundles MoceanSymBundle\MoceanBundle::class => ['all' => true], ];
Symfony 3
将bundle添加到app/AppKernel.php
$bundles = array( //... framework bundles new MoceanSymBundle\MoceanBundle(), );
使用方法
通过依赖注入使用(symfony 4及以上版本)
在服务yaml中绑定mocean管理类
# config/services.yaml services: App\Controller\YourController: bind: $mocean: '@mocean_manager'
使用自动注入
# config/services.yaml services: MoceanSymBundle\Services\MoceanManager: '@mocean_manager'
在控制器中
class YourController extends AbstractController { /** * @Route("/") */ public function index(MoceanSymBundle\Services\MoceanManager $mocean) { $res = $mocean->message()->send([ 'mocean-to' => '60123456789', 'mocean-from' => 'MOCEAN', 'mocean-text' => 'Hello World' ]); } }
通过容器使用
class YourController extends Controller { /** * @Route("/") */ public function index() { $mocean = $this->container->get('mocean_manager'); $res = $mocean->message()->send(...); } }
上述示例将使用默认中定义的账户。
如果您在配置中定义了多个账户,可以使用如下方式
$mocean->using('secondary')->message()->send(...); $mocean->using('third')->message()->send(...);
许可证
Laravel Mocean遵循MIT许可证