jeydo / php-ovh-sms
OVH SMS API SDK
Requires
- ovh/ovh: ~1.1.1
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-18 18:54:40 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产品,而无需存储您的密码。
更好的是,凭证可以配置为仅允许访问一些特定功能。在这种情况下,我们只想让脚本访问短信功能。
要生成访问所有短信功能的凭证,您可以简单地访问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