crboy/nexmo-php-lib

此包的最新版本(dev-master)没有可用的许可证信息。

dev-master 2014-04-02 10:31 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:34:09 UTC


README

安装

[user@project_path]$ composer require crboy/nexmo-php-lib

快速示例

  1. 发送短信

    $sms = new NexmoMessage('account_key', 'account_secret');
    $sms->sendText('+886900000000', 'MyApp', 'Hello world!');
    
  2. 接收短信

    $sms = new NexmoMessage('account_key', 'account_secret');
    if ($sms->inboundText()) {
        $sms->reply('You said: ' . $sms->text);
    }
    
  3. 接收消息回执

    $receipt = new NexmoReceipt();
    if ($receipt->exists()) {
        switch ($receipt->status) {
            case $receipt::STATUS_DELIVERED:
                // The message was delivered to the handset!
                break;
            case $receipt::STATUS_FAILED:
            case $receipt::STATUS_EXPIRED:
                // The message failed to be delivered
                break;
        }
    }
    
  4. 列出账户中购买的号码

    $account = new NexmoAccount('account_key', 'account_secret');
    $numbers = $account->numbersList();
    

常见问题

发送消息返回false。

这通常是因为您的Web服务器无法向Nexmo发送请求。请确保以下条件满足

  1. 对于您的PHP安装,已启用CURL或已将PHP选项 'allow_url_fopen' 设置为1(默认)。
  2. 您没有防火墙阻止对rest.nexmo.com/sms/json在端口443的访问。

您的消息似乎已发送,但您没有收到。

运行包含的example.php文件。这将显示从Nexmo返回的任何错误。