【发布时间】:2018-04-23 06:18:04
【问题描述】:
我的控制器中有一个函数可以从回调 url 中获取一些数据。并且数据将自动在数据库中更新。
我的回调地址是http://example.com/API/sendSMSCallback
这是我在 API 控制器中的 sendSMSCallback 函数
public function sendSMSCallback() {
$json = file_get_contents('php://input');
$data = array('value' => $json, 'date' => date('Y-m-d h:i:s'));
$this->db->insert('test', $data); // for testing
$json = urldecode($json);
$obj = json_decode($json,TRUE);
$reqID = $obj['req_id'];
$status = $obj['status'];
$mobile = $obj['msisdn'];
$this->db->where('UniqueID', $reqID);
$this->db->where('MobileNo', $mobile);
$this->db->set('ResponseStatus', $status);
$this->db->update('smslog_tbl');
// for testing
$this->load->helper('file');
if ( ! write_file(base_url().'test.txt', $json)){
echo 'Unable to write the file';
}
else{
echo 'File written!';
}
}
预期的json形式的数据如下
{"result":{"status":"success","req_id":"0d0dd0ce8-dadf-49fd-a49e-9845787e0507","msisdn":"91xxxxxxx, "}}
但 smslog_tbl 表中不会更新任何内容,并且 test.txt 为空。 test 表中插入了新行,但 value 字段为空。请帮我找出解决方案。提前致谢
更新: 表结构:测试
`id` int(11) NOT NULL,
`value` text COLLATE latin1_general_ci NOT NULL,
`date` datetime NOT NULL
【问题讨论】:
-
请测试表结构
-
在我的问题中更新
-
在
$json = file_get_contents('php://input');之后尝试执行var_dump($json);并查看是否有任何数据实际出现?
标签: php json codeigniter callback file-get-contents