【问题标题】:Receive SMS with Plivo/Codeigniter使用 Plivo/Codeigniter 接收短信
【发布时间】:2016-04-25 13:52:20
【问题描述】:

我一直在尝试实现一个从我们发送到 Plivo 的 SMS 中检索数据的函数。 目前在我的网站上,我可以发送短信,检查状态,但我希望用户能够响应这些短信并将这些数据存储到我的数据库中。我followed the documentation here 我有这个控制器:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Receive extends CI_Controller {

    function __construct()
    {
        parent::__construct();

        $this->load->model('receive_model');
    }

    public function index()
    {
        // Sender's phone numer
        $from_number = $this->input->get("From");
        // Receiver's phone number - Plivo number
        $to_number = $this->input->get("To");
        // The SMS text message which was received
        $text = $this->input->get("Text");
        // Output the text which was received to the log file.
        // error_log("Message received - From: ".$from_number.", To: ".$to_number. ", Text: ".$text);
        $arr = array("from" => $from_number, "to" => $to_number, "text" => $text);
        $this->receive_model->add($arr);
    }

}

在示例中,他们使用了 $_REQUEST,但它似乎不适用于 Codeigniter,所以我尝试使用 $this->input->get("From") 但没有成功。 Plivo 收到短信,它写在 Plivo Logs 上,我写了指向这个控制器的 URL。

有什么想法吗?

【问题讨论】:

  • 在config.php中设置$config['allow_get_array'] = TRUE;
  • 它已经在 True

标签: php codeigniter plivo


【解决方案1】:

您可以按照以下步骤调试此问题:

  1. 检查 Plivo 应用程序的 Message URL 是否正确设置了您的号码。
  2. 消息方法设置为 POST。它与 CodeIgniter 相关。
  3. 在 config/config.php 上启用 CI 错误日志并将以下代码放入您的控制器方法中以记录所有请求。

log_message('error', "Plivo 响应:" . print_r($_REQUEST, true) ."\n");

  1. 接收测试消息(或者您可以通过添加 SMS 字段来运行简单的 HTML 表单)。
  2. 检查您的 CI 日志。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 2021-06-28
    • 1970-01-01
    • 2015-12-30
    • 1970-01-01
    相关资源
    最近更新 更多