fillup/nexmo

使用Guzzle Web Service描述构建的Nexmo API客户端

2.0 2017-04-28 18:14 UTC

This package is auto-updated.

Last update: 2024-09-06 08:23:14 UTC


README

用于与Nexmo API交互的PHP客户端

该库是作为教程的一部分开发的,您可以从以下部分开始教程:

使用Guzzle Web Service客户端创建PHP Nexmo API客户端 – 第1部分

该库现在涵盖了Nexmo的所有RESTful出站API,所以无论您是否对教程感兴趣,都可以使用该库与Nexmo进行集成。

安装

使用composer安装非常简单。只需将"fillup/nexmo": "dev-master"添加到您的composer.json的require部分并更新即可。

使用方法/示例

所有类都在Nexmo\命名空间中

use Nexmo\Developer;
use Nexmo\Insight;
use Nexmo\Sms;
use Nexmo\Verify;
use Nexmo\Voice;

/**
 * Load config, expecting an array with:
 * api_key, api_secret, to, from, text
 */
$config = include __DIR__.'/../../config-local.php';

/**
 * Get an SMS client object
 */
$sms = new Sms($config);

/**
 * Send a message
 */
$results = $sms->send([
    'from' => $config['from'],
    'to' => $config['to'],
    'text' => $config['text'],
]);

/**
 * Dump out results
 */
print_r($results);
// Array
// (
//    [statusCode] => 200
//    [message-count] => 1
//    [messages] => Array
// (
//    [0] => Array
//    (
//        [to] => 14085559876
//                    [message-id] => 0300000071BCAA3C
//                    [status] => 0
//                    [remaining-balance] => 15.23280000
//                    [message-price] => 0.00480000
//                    [network] => US-VOIP
//                )
// 
//        )
// 
// )

所有API调用都需要一个api_keyapi_secret。最佳实践是将这些内容保留在代码之外,例如配置文件或环境变量中,不应包含在源代码中。只需像上面的示例一样,将包含api_keyapi_secret键的数组传递给每个类的构造函数即可。