在 PHP 中处理服务器回调数据


Process server callback data in PHP

我在处理从我用于我的应用程序(http://Cameratag.com(的服务发送的回调时遇到问题。

我只是试图获取从Cameratag发送的数据并使用它做一些事情。

下面是我正在尝试工作的"测试"脚本。但是我有一个可怕的时间试图找出什么不起作用。

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Process_video_test extends CI_Controller {
function __construct()
 { 
  parent::__construct();
  $this->load->library('email');
 }
public function index()
 {
    $raw = file_get_contents('php://input');
    $json = json_decode($raw, true);
    $uuid = $json["uuid"];
    $this->email->from('Senders@email.com', 'Senders Name');
    $this->email->to('Recievers@email.com'); 
    $this->email->subject($uuid);
    $this->email->message($uuid);   
    $this->email->send(); 
 }
}

当我将数据重新发送到此脚本时,没有任何反应。即使您访问或卷曲此脚本的 url,它也会发送一封空白电子邮件。当我重新发送回调时,我什么也得不到。

回调服务器肯定也在发布数据,我可以在我的服务器日志中找到以下内容:

54.224.22.73 - - [09/Oct/2013:07:07:50 -0500] "POST /process_video_test?uuid=59fbe950-0150-0131-7bd6-22000a8fabd6&camera_uuid=732c58e0-ea3f-0130-73d4-22000aecbdd8&created_at=2013-09-16%2022%3A50%3A47%20UTC&percent_complete=100&short_code=eMOhvg&metadata[email]=Coeyman%40gmail.com&state=published&recorded_from=http%3A%2F%2Fjordan.crowdengage.com%2F&publish_type=webcam&formats[][name]=vga&formats[][width]=640&formats[][height]=480&formats[][video_url]=http%3A%2F%2Fcameratag.com%2Fvideos%2F59fbe950-0150-0131-7bd6-22000a8fabd6%2Fvga%2Fmp4&formats[][mp4_url]=http%3A%2F%2Fcameratag.com%2Fvideos%2F59fbe950-0150-0131-7bd6-22000a8fabd6%2Fvga%2Fmp4&formats[][webm_url]=http%3A%2F%2Fcameratag.com%2Fvideos%2F59fbe950-0150-0131-7bd6-22000a8fabd6%2Fvga%2Fwebm&formats[][thumbnail_url]=http%3A%2F%2Fcameratag.com%2Fvideos%2F59fbe950-0150-0131-7bd6-22000a8fabd6%2Fvga%2Fthumb&formats[][small_thumbnail_url]=http%3A%2F%2Fcameratag.com%2Fvideos%2F59fbe950-0150-0131-7bd6-22000a8fabd6%2Fvga%2Fsmall_thumb&formats[][state]=COMPLETED&formats[][completed_at]=2013-09-16%2022%3A51%3A57%20UTC&formats[][name]=360p&formats[][width]=480&formats[][height]=360&formats[][video_url]=http%3A%2F%2Fcameratag.com%2Fvideos%2F59fbe950-0150-0131-7bd6-22000a8fabd6%2F360p%2Fmp4&formats[][mp4_url]=http%3A%2F%2Fcameratag.com%2Fvideos%2F59fbe950-0150-0131-7bd6-22000a8fabd6%2F360p%2Fmp4&formats[][webm_url]=http%3A%2F%2Fcameratag.com%2Fvideos%2F59fbe950-0150-0131-7bd6-22000a8fabd6%2F360p%2Fwebm&formats[][thumbnail_url]=http%3A%2F%2Fcameratag.com%2Fvideos%2F59fbe950-0150-0131-7bd6-22000a8fabd6%2F360p%2Fthumb&formats[][small_thumbnail_url]=http%3A%2F%2Fcameratag.com%2Fvideos%2F59fbe950-0150-0131-7bd6-22000a8fabd6%2F360p%2Fsmall_thumb&formats[][state]=COMPLETED&formats[][completed_at]=2013-09-16%2022%3A51%3A58%20UTC&formats[][name]=qvga&formats[][width]=320&formats[][height]=240&formats[][video_url]=http%3A%2F%2Fcameratag.com%2Fvideos%2F59fbe950-0150-0131-7bd6-22000a8fabd6%2Fqvga%2Fmp4&formats[][mp4_url]=http%3A%2F%2Fcameratag.com%2Fvideos%2F59fbe950-0150-0131-7bd6-22000a8fabd6%2Fqvga%2Fmp4&formats[][webm_url]=http%3A%2F%2Fcameratag.com%2Fvideos%2F59fbe950-0150-0131-7bd6-22000a8fabd6%2Fqvga%2Fwebm&formats[][thumbnail_url]=http%3A%2F%2Fcameratag.com%2Fvideos%2F59fbe950-0150-0131-7bd6-22000a8fabd6%2Fqvga%2Fthumb&formats[][small_thumbnail_url]=http%3A%2F%2Fcameratag.com%2Fvideos%2F59fbe950-0150-0131-7bd6-22000a8fabd6%2Fqvga%2Fsmall_thumb&formats[][state]=COMPLETED&formats[][completed_at]=2013-09-16%2022%3A51%3A56%20UTC HTTP/1.1" 403 18156 "-" "-"

编辑:

我尝试使用以下代码作为我的索引文件:

类 Process_video_test 扩展CI_Controller {

public function index() 
 {
    $debug_me = 1;
    $raw = file_get_contents('php://input');
    $json = json_decode($raw, true);
    if ($debug_me) {
        ob_start();
        var_dump('raw:', $raw, 'json:', $json);
        log_message('info', ob_get_contents());
        ob_end_clean();
    }
}

在我的日志文件中如下:

DEBUG - 2013-10-09 10:01:12 --> Config Class Initialized
DEBUG - 2013-10-09 10:01:12 --> Hooks Class Initialized
DEBUG - 2013-10-09 10:01:12 --> Utf8 Class Initialized
DEBUG - 2013-10-09 10:01:12 --> UTF-8 Support Enabled
DEBUG - 2013-10-09 10:01:12 --> URI Class Initialized
DEBUG - 2013-10-09 10:01:12 --> Router Class Initialized
DEBUG - 2013-10-09 10:01:12 --> No URI present. Default controller set.
DEBUG - 2013-10-09 10:01:12 --> Output Class Initialized
DEBUG - 2013-10-09 10:01:12 --> Security Class Initialized
DEBUG - 2013-10-09 10:01:12 --> Input Class Initialized
DEBUG - 2013-10-09 10:01:12 --> Global POST and COOKIE data sanitized
DEBUG - 2013-10-09 10:01:12 --> Language Class Initialized
DEBUG - 2013-10-09 10:01:12 --> Loader Class Initialized
DEBUG - 2013-10-09 10:01:12 --> Helper loaded: utility_helper
DEBUG - 2013-10-09 10:01:12 --> Helper loaded: url_helper
DEBUG - 2013-10-09 10:01:12 --> Helper loaded: menu_helper
DEBUG - 2013-10-09 10:01:13 --> Database Driver Class Initialized
DEBUG - 2013-10-09 10:01:13 --> Config file loaded: application/config/ion_auth.php
DEBUG - 2013-10-09 10:01:13 --> Email Class Initialized
DEBUG - 2013-10-09 10:01:13 --> Language file loaded: language/english/ion_auth_lang.php
DEBUG - 2013-10-09 10:01:13 --> Helper loaded: cookie_helper
DEBUG - 2013-10-09 10:01:13 --> Helper loaded: language_helper
DEBUG - 2013-10-09 10:01:13 --> Session Class Initialized
DEBUG - 2013-10-09 10:01:13 --> Helper loaded: string_helper
DEBUG - 2013-10-09 10:01:13 --> A session cookie was not found.
DEBUG - 2013-10-09 10:01:13 --> Session routines successfully run
DEBUG - 2013-10-09 10:01:13 --> Model Class Initialized
DEBUG - 2013-10-09 10:01:13 --> Model Class Initialized
DEBUG - 2013-10-09 10:01:13 --> Helper loaded: date_helper
DEBUG - 2013-10-09 10:01:13 --> REST Class Initialized
DEBUG - 2013-10-09 10:01:13 --> cURL Class Initialized
DEBUG - 2013-10-09 10:01:13 --> Controller Class Initialized
DEBUG - 2013-10-09 10:01:13 --> File loaded: application/views/includes/header.php
DEBUG - 2013-10-09 10:01:13 --> File loaded: application/views/landing.php
DEBUG - 2013-10-09 10:01:13 --> File loaded: application/views/includes/footer.php
DEBUG - 2013-10-09 10:01:13 --> File loaded: application/views/includes/template.php
DEBUG - 2013-10-09 10:01:13 --> Final output sent to browser
DEBUG - 2013-10-09 10:01:13 --> Total execution time: 0.3939
步骤

0。确保您的类被调用

正如我从日志中看到的:DEBUG - 2013-10-09 10:01:12 --> No URI present. Default controller set..这意味着Process_video_test没有加载到runnig。另外,刚刚从服务器的日志中看到:*.*.*.* - - [09/Oct/2013:07:07:50 -0500] "POST /process_video_test?*** HTTP/1.1" 403 18156 "-" "-" .这意味着,您的第三方已收到HTTP错误403 Forbidden。看起来您的服务器返回 403 错误并且不加载 URL /process_video_test

第 1 步。启用日志记录

打开application/config/config.php文件log_threshold参数设置为3(信息性消息(:

$config['log_threshold'] = 3;

确保log_path参数设置为''并检查默认情况下日志文件的存储位置(只需阅读上面的评论log_path在您的config.php,它以"错误日志记录目录路径"为标题(。

$config['log_path'] = '';

例如,在 CodeIgniter 2.1.4 中,默认日志文件位置为 application/logs/

第 2 步。捕获变量值

为了捕获错误,您可以记录一些调试信息并检查它。例如,您可以稍微重写一下index()

public function index() {
    $debug_me = 1;
    $raw = file_get_contents('php://input');
    $json = json_decode($raw, true);
    if ($debug_me) {
        ob_start();
        var_dump('raw:', $raw, 'json:', $json);
        log_message('info', ob_get_contents());
        ob_end_clean();
    }
    //$uuid = $json["uuid"];
    //$this->email->from('Senders@email.com', 'Senders Name');
    //$this->email->to('Recievers@email.com'); 
    //$this->email->subject($uuid);
    //$this->email->message($uuid); 
    //$this->email->send(); 
}

打开日志文件。现在,您可以检查$raw内部的内容并$json变量。这不是最后一步。如果您要调试,请使用记录的调试信息更新您的问题,以便我们将尝试查找您的脚本存在的问题。

待续...

建议您查看此链接。尝试记录错误。

如果您要发布数据,那么为什么要使用$raw = file_get_contents('php://input');?只需像这样从post中获取数据:

$uuid = $this->input->post('uuid') //or $this->input->get('uuid'); try both once.