我一直在尝试实现一个函数,从我们发送到Plivo的短信中检索数据。目前在我的网站上,我可以发送短信,检查状态,但我希望用户能够响应这些短信并将这些数据存储到我的数据库中。我按照这里的文档进行操作我有这个控制器:
<?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 日志上,我写了指向这个控制器的 URL。
知道吗?
您可以按照以下步骤调试此问题:
- 检查 Plivo 应用程序的消息 URL 是否与您的号码设置正确。
- 将消息方法设置为开机自检。它与CodeIgniter相关。
- 在配置/配置上启用 CI 错误日志.php并将以下代码放入控制器方法以记录所有请求。
log_message('error', "Plivo Responses: " .print_r($_REQUEST,真实) .'"'");
- 接收测试消息(或者您可以通过添加 SMS 字段来运行简单的 HTML 表单)。
- 检查您的 CI 日志。