php - 任何人都知道如何使用 nexmo 短信 api 接收短信到 php 脚本

标签 php mysql api sms vonage

我正在尝试实现 nexmo 短信 api 以从手机接收短信并保存到 mysql 表。我考虑了nexmo。我检查了文档。但不知道如何使用它

https://docs.nexmo.com/messaging/sms-api
am trying to implement nexmo sms api to receive sms from phone and save to mysql table. i took account in nexmo. i ckeched the documentation. but confused how to use it

任何人都知道如何从手机发送短信时接收短信到我的脚本,请帮助我 我想获取短信到脚本并保存到 mysql 表

public function myinformation() {
   $request = array_merge($_GET, $_POST);

// Check that this is a delivery receipt.
if (!isset($request['messageId']) OR !isset($request['status'])) {
    error_log('This is not a delivery receipt');
    return;
}

//Check if your message has been delivered correctly.
if ($request['status'] == 'delivered') {
    error_log("Your message to {$request['msisdn']} (message id {$request['messageId']}) was delivered.");
    error_log("The cost was {$request['price']}.");
     $From = $this->input->post('saleena@gmail.com');
        $ToEmail = $this->input->post('saleena@gmail.com');
        $message = "Results: " . print_r( $request, true );
           $this->load->library('email');
        $subject = 'My Attempt';

        // Get full html:
        $body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=' . strtolower(config_item('charset')) . '" />
    <title>' . html_escape($subject) . '</title>
    <style type="text/css">
        body {
            font-family: Arial, Verdana, Helvetica, sans-serif;
            font-size: 16px;
        }
    </style>
</head>
<body>
' . $message . '
</body>
</html>';
      $result = $this->email
                ->from($From)
                // Optional, an account where a human being reads.
                ->to($ToEmail)
                ->subject($subject)
                ->message($body)
                ->send();

        var_dump($result);
        echo $this->email->print_debugger();
        exit;      

} elseif ($request['status'] != 'accepted') {
    error_log("Your message to {$request['msisdn']} (message id {$request['messageId']}) was accepted by the carrier.");
    error_log("The cost was {$request['price']}.");
} else {
    error_log("Your message to {$request['msisdn']} has a status of: {$request['status']}.");
    error_log("Check err-code {$request['err-code']} against the documentation.");
}
    }

我试过这个代码。但是我没有收到任何邮件到我的邮箱

最佳答案

您可以使用 Nexmo 的 SMS API,它允许您通过简单的 HTTP 调用在 200 多个国家/地区发送文本。

您可以注册一个虚拟号码,该号码允许您发送短信和接收传入消息。

对于 2FA,您可以使用 Verify API 对特定设备的用户进行身份验证。

这种方法比使用 SMS API 和自己随机生成号码更安全。然后,最终用户将输入 PIN 并由 Verify API 进行检查。

使用这些 API 中的任何一个都需要几行代码。下面是一段 PHP 代码,它允许您使用 SMS API 发送文本。

关于php - 任何人都知道如何使用 nexmo 短信 api 接收短信到 php 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40542510/

相关文章:

javascript - Magento Paypalplus - 通过 PHP 停用付款方式

java - 为大量外部 API 请求扩展软件/硬件?

mysql - 选择mysql记录最多的公司

javascript - 为什么 api 调用在 gh-pages 上不起作用

api - 使用 bing api xslt

PHP:递归修改数组?

javascript - 在服务器上处理 cloneNode

javascript - 我的对话框是第一次打开但不是第二次?

MySQL 检索行并将它们转换为列

php - 拉维尔 5.8 : Display eloquent items sorted based on timestamp