ovh / php-ovh-sms
OVH SMS API SDK
Requires
- ovh/ovh: ~1.1.1
Requires (Dev)
This package is auto-updated.
Last update: 2024-08-28 18:00:26 UTC
README
使用OVH SMS优惠直接从您的代码中发送短信。
<?php /** * # Instantiate. Visit https://api.ovh.com/createToken/index.cgi?GET=/sms&GET=/sms/*&PUT=/sms/*&DELETE=/sms/*&POST=/sms/* * to get your credentials */ require __DIR__ . '/vendor/autoload.php'; use \Ovh\Sms\SmsApi; $Sms = new SmsApi( $applicationKey, $applicationSecret, $endpoint, $consumer_key); print_r($Sms->getAccounts()); ?>
安装
要下载此SDK并将其集成到您的PHP应用程序中,您可以使用 Composer。
在您的 composer.json 文件中添加存储库,或者如果您还没有此文件,请将其创建在项目的根目录下,内容如下
{ "name": "Example Application", "description": "This is an example of OVH SMS APIs SDK usage", "require": { "ovh/php-ovh-sms": "dev-master" } }
然后,您可以使用以下命令安装OVH SMS API SDK及其依赖项
php composer.phar install
这将安装 ovh/php-ovh-sms
到 ./vendor
,包括 autoload.php
等其他依赖项。
配置
要使用此SDK,您需要API凭据。API凭据允许您登录并管理OVH产品,而无需存储密码。
更好的是,凭据可以配置为仅允许访问某些特定功能。在这种情况下,我们只想让脚本访问SMS功能。
要生成访问所有SMS功能的凭据,您只需访问 https://api.ovh.com/createToken/index.cgi?GET=/sms&GET=/sms/*&PUT=/sms/*&DELETE=/sms/*&POST=/sms/ *
然后,您可以在应用程序中使用生成的凭据。
有关更高级的使用案例,请参阅 php-ovh 或 python-ovh 包装器。
使用php-ovh-sdk发送不带指定发送者的测试消息
此示例将创建一个新的SDK实例,将其配置为向法国号码发送消息而不声明发送者(将使用随机简码)。然后,它将使用此实例在将来使用它找到的第一个账户计划消息。
为了避免意外消费任何信用,它将在实际发送之前删除消息。
<?php require __DIR__ . '/vendor/autoload.php'; use \Ovh\Sms\SmsApi; // Informations about your application // You may set them to 'NULL' if you are using // a configuraton file $applicationKey = "your_app_key"; $applicationSecret = "your_app_secret"; $consumerKey = "your_consumer_key"; $endpoint = 'ovh-eu'; // Init SmsApi object $Sms = new SmsApi( $applicationKey, $applicationSecret, $endpoint, $consumerKey ); // Get available SMS accounts $accounts = $Sms->getAccounts(); // Set the account you will use $Sms->setAccount($accounts[0]); // Create a new message that will allow the recipient to answer (to FR receipients only) $Message = $Sms->createMessage(true); $Message->addReceiver("+33601020304"); $Message->setIsMarketing(false); // Plan to send it in the future $Message->setDeliveryDate(new DateTime("2018-02-25 18:40:00")); $Message->send("Hello world!"); // Get all planned messages $plannedMessages = $Sms->getPlannedMessages(); // Delete all planned messages foreach ($plannedMessages as $planned) { $planned->delete(); } ?>https://api.ovh.com/createToken/index.cgi
使用事先声明的发送者发送测试消息
此示例将创建一个新的SDK实例,将其配置为发送消息。然后,它将使用此实例在将来使用它找到的第一个账户和账户中找到的第一个发送者作为消息发送者来计划消息。
为了避免意外消费任何信用,它将在实际发送之前删除消息。
<?php require __DIR__ . '/vendor/autoload.php'; use \Ovh\Sms\SmsApi; // Informations about your application // You may set them to 'NULL' if you are using // a configuraton file $applicationKey = "your_app_key"; $applicationSecret = "your_app_secret"; $consumerKey = "your_consumer_key"; $endpoint = 'ovh-eu'; // Init SmsApi object $Sms = new SmsApi( $applicationKey, $applicationSecret, $endpoint, $consumerKey ); // Get available SMS accounts $accounts = $Sms->getAccounts(); // Set the account you will use $Sms->setAccount($accounts[0]); // Get declared senders $senders = $Sms->getSenders(); // Create a new message $Message = $Sms->createMessage(); $Message->setSender($senders[0]); $Message->addReceiver("+33601020304"); $Message->setIsMarketing(false); // Plan to send it in the future $Message->setDeliveryDate(new DateTime("2018-02-25 18:40:00")); $Message->send("Hello world!"); // Get all planned messages $plannedMessages = $Sms->getPlannedMessages(); // Delete all planned messages foreach ($plannedMessages as $planned) { $planned->delete(); } ?>https://api.ovh.com/createToken/index.cgi
黑客攻击
获取代码:
$ git clone https://github.com/ovh/php-ovh-sms.git
$ cd php-ovh-sms
提交您的更改:
$ git commit -sam "change some feature because it makes my life easier"
$ git push
并访问Github提交您的更改! https://github.com/ovh/php-ovh-sms/pulls
相关链接
- 订购短信信用: https://www.ovhtelecom.fr/sms/
- 获取API凭据: https://api.ovh.com/createToken/index.cgi
- 贡献: https://github.com/ovh/php-ovh-sms
- 报告错误: https://github.com/ovh/php-ovh-sms/issues
- 官方OVH PHP包装器: https://github.com/ovh/php-ovh