0

嗨,我正在使用 twilio 发送和接收来自我的客户的 SMS。发送短信工作正常。

收到短信后,我想将其保存fromBody我的数据库中。它不起作用。这是我的代码。

控制器

function  receive(){
    $post_data['from']       =  $this->input->post('From');
    $post_data['body']       =  $this->input->post('Body');

    if($post_data['from'] && $post_data['body']){
        $this->receive->insert_received_message($post_data);
    }

}

模型

function insert_received_message($data){

     $sms['pone_number']    = $data['from'];
     $sms['message_type']   = 2;
     $sms['body']           = $data['body'];

     $results = $this->db->insert('Sms_message', $sms); 
     return $results;
}

我像这样将网址添加到我的号码中

在此处输入图像描述

已接收日志中的错误消息

在此处输入图像描述

有人可以帮我解决这个问题。TNX。

4

1 回答 1

2

您的数据未保存到数据库中确保您的文件名在您的数组中正确

控制器

function receive() {
    $from = $this->input->post('From');
    $body = $this->input->post('Body');

    if (isset($from) && isset($body)) { //create your insert array like that
        $sms = array(
            'pone_number' => $from,
            'message_type' => 2,
            'body' => $body
        );

        $this->receive->insert_received_message($sms);
    }
}

模型

function insert_received_message($data){

     $this->db->insert('Sms_message', $data); 
     if($this->db->insert_id()>0)// check last insert id
     {
         return $this->db->insert_id();
     }
     else{
         return FALSE;
     }

}

以下链接还演示了如何与收到的消息进行交互。

https://www.twilio.com/docs/quickstart/php/sms/replying-to-sms-messages

于 2015-06-10T07:48:33.547 回答