a2zi / ovh-sms-bundle
Symfony Bundle,可轻松使用Ovh API发送短信
dev-master
2018-10-18 08:21 UTC
Requires
- php: >=5.3.3
- ovh/ovh: dev-master
- symfony/symfony: ~2.6,>=2.6.0,<4.0.0
This package is auto-updated.
Last update: 2024-09-07 02:29:05 UTC
README
获取凭证
在此页面上生成您的API凭证: https://eu.api.ovh.com/createToken/ 您必须至少添加以下权限
- GET
/sms/
- POST
/sms/*/jobs/
使用Composer安装
将以下内容添加到您的 composer.json
文件
// composer.json
{
// ...
"repositories": [
// ...
{
"type": "vcs",
"url": "git@sv5.a2zi.fr:a2zi/ovh_sms_bundle.git"
}
],
// ...
"require":{
// ...
"a2zi/ovh-sms-bundle": "dev-master"
}
}
运行命令 composer update
在您的 AppKernel.php 文件中注册该Bundle
<?php
// in AppKernel::registerBundles()
$bundles = array(
// ...
new \A2zi\OvhSmsBundle\A2ziOvhSmsBundle(),
);
配置
在 config.yml 中配置 OvhSmsBundle
a2zi_ovh_sms:
application_key: "your_application_key"
application_secret: "your_application_secret"
consumer_key: "your_application_consumer_key"
endpoint: "endpoint_for_your_region"
sms_service_id: "your_service_id"
sender: "default_sender_name"
必填参数
参数 application_key、application_secret、consumer_key 由Ovh提供。因此,您需要在此页面上生成您的API凭证: https://eu.api.ovh.com/createToken/
可选参数
- endpoint:设置API端点(默认为
ovh-eu
) sms_service_id 如果未设置,服务将调用Ovh API以获取第一个可用的短信服务,并在发送消息时调用API的另一个调用。当设置此参数时,只需调用API一次即可发送消息。
sender:为消息设置默认的发送者名称。它必须与您帐户中定义的发送者相匹配。要访问可用发送者的列表,您可以从Ovh控制台调用Ovh API:https://api.ovh.com/console/#/sms/{serviceName}/senders#GET
基本用法
在控制器文件中,您可以使用以下代码发送短信
$smsService = $this->get('ovh_sms');
$sms = $smsService
->addReceiver('+33601010101')
->setMessage('Hello World !')
->send();