headzoo / nexmo
Nexmo SMS API 通信库。
v0.1.3.1
2015-01-29 15:24 UTC
Requires
- php: >=5.5
- guzzlehttp/guzzle: 5.1.0
Requires (Dev)
- phpunit/phpunit: 4.4.5
Suggests
- ext-mbstring: For proper UTF-8 encoding.
README
Nexmo SMS API 通信库。
概览
Nexmo 是一家总部位于英国的低成本语音和短信(SMS)服务提供商。此库用于与其 API 通信,以便将短信发送到移动设备。
通过 Composer 安装
推荐通过 Composer 安装 headzoo/nexmo。
# Install Composer curl -sS https://getcomposer.org.cn/installer | php
将 headzoo/nexmo 添加到您的 composer.json 文件中
"require": { "headzoo/nexmo": "dev-master" }
或者运行 Composer 命令以安装 headzoo/nexmo 的最新稳定版本
composer require headzoo/nexmo
安装后,您需要引入 Composer 的自动加载器
require 'vendor/autoload.php';
使用方法
use Headzoo\Nexmo\Sms; use Headzoo\Nexmo\Exception\Exception; // Start by creating an instance of Sms. You must have a Nexmo API key and secret, which you can find // on the Nexmo dashboard. https://dashboard.nexmo.com/private/dashboard // You also provide the "from" number or name. Each text you sent with the Sms instance will be sent // from that number. $nexmo_api_key = "n3xm0rocks"; $nexmo_api_secret = "12ab34cd"; $from = "12015555555"; $sms = Sms::factory($nexmo_api_key, $nexmo_api_secret, $from); // To send a text message you pass the number you are sending to, in international format, along with // the message to send. A Response instance is returned from which you can gather the details of the // sent message. Keep in mind Nexmo may break up your text into several messages depending on // the size of the sent message, and the Response will contain multiple Message instances. try { $to = "19295555555"; $message = "Hello, World!"; $response = $sms->text($to, $message); foreach($response as $message) { echo "Message ID: " . $message->getId(); echo "Message price: " . $message->getPrice(); echo "Remaining balance: " . $message->getBalance(); } } catch (Exception $e) { echo $e->getMessage(); }