francoisburdy / php-ovh-sms
OVH SMS API SDK
Requires
- ovh/ovh: ~1.1.1
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-17 09:46:49 UTC
README
从使用 Guzzle 7 支持的 ovh/php-ovh-sms 分支而来。
使用 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": { "francoisburdy/php-ovh-sms": "dev-master" } }
然后,您可以使用以下命令安装 OVH SMS API SDK 及其依赖项
php composer.phar install
这将安装 francoisburdy/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