1

我在处理从我用于我的应用程序 ( 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
4

2 回答 2

0

第 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 "-" "-". 这意味着,您的第 3 方已收到 HTTP 错误403 Forbidden。看起来您的服务器返回 403 错误并且不加载/process_video_testURL

步骤 1. 启用日志记录

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

$config['log_threshold'] = 3;

确保将log_path参数设置为''并检查默认情况下您的日志文件存储在哪里(只需阅读上面log_pathconfig.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变量里面有什么。这不是最后一步。如果您要调试,请使用记录的调试信息更新您的问题,以便我们尝试找出您的脚本有什么问题。

未完待续...

于 2013-10-09T14:05:33.203 回答
0

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

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

$uuid = $this->input->post('uuid') //or $this->input->get('uuid'); try both once.
于 2013-10-09T14:02:33.080 回答