duanjian3338 2010-06-11 02:35
浏览 54
已采纳

XML回发问题

I have a script that is designed to parse XML postbacks from Ultracart, right now just dumps it into a MySQL table. The script works fine if I point it to a XML file on my localhost but using 'php://input' it doesn't seem to grabbing anything. My logs show apache returning 200 after the post so I have no idea what could be wrong or how to drill down the issue.. here's the code:

  $doc = new DOMDocument();
  $doc->loadXML($page);

  $handle = fopen("test2/".time().".xml", "w+");
  fwrite($handle,trim($page)); // it doesn't save this either :'(
  fclose();

  require_once('includes/database.php');

  $db = new Database('localhost', 'user', 'password', 'db_name');
  $data = array();

   $exports = $doc->getElementsByTagName("export");
   foreach ($exports as $export) {
     $orders = $export->getElementsByTagName("order");
     foreach($orders as $order) {
        $data['order_id'] = $order->getElementsByTagName("order_id")->item(0)->nodeValue;
        $data['payment_status'] = $order->getElementsByTagName("payment_status")->item(0)->nodeValue;
        $date_array = explode(" ",$order->getElementsByTagName("payment_date_time")->item(0)->nodeValue);

            if ($date_array[1] == 'JAN') { $date_array[1] = '01'; }
            if ($date_array[1] == 'FEB') { $date_array[1] = '02'; }
            if ($date_array[1] == 'MAR') { $date_array[1] = '03'; }
            if ($date_array[1] == 'APR') { $date_array[1] = '04'; }
            if ($date_array[1] == 'MAY') { $date_array[1] = '05'; }        // converts Ultracart date to
            if ($date_array[1] == 'JUN') { $date_array[1] = '06'; }        // MySQL date
            if ($date_array[1] == 'JUL') { $date_array[1] = '07'; }
            if ($date_array[1] == 'AUG') { $date_array[1] = '08'; }
            if ($date_array[1] == 'SEP') { $date_array[1] = '09'; }
            if ($date_array[1] == 'OCT') { $date_array[1] = '10'; }
            if ($date_array[1] == 'NOV') { $date_array[1] = '11'; }
            if ($date_array[1] == 'DEC') { $date_array[1] = '12'; }

        $data['payment_date'] = $date_array[2]."-".$date_array[1]."-".$date_array[0];
        $data['payment_time'] = $date_array[3];

        //... we'll skip this, there are 80 some elements

        $data['discount'] = $order->getElementsByTagName("discount")->item(0)->nodeValue;
        $data['distribution_center_code'] = $order->getElementsByTagName("distribution_center_code")->item(0)->nodeValue;
            }
        }
    }
        $db->insert('order_history',$data);
} else die('ERROR: Token Check Failed!');
  • 写回答

2条回答 默认 最新

  • dscizpq790832708 2010-06-11 03:13
    关注

    Without seeing the code above that point, I'd suggest that you dump the output straight out and see if you're actually receiving the XML. I doubt the problem is with your parsing, but with receiving the postback. Looking at the ultracart documentation, it looks to me like they aren't passing the the body of the xml in as a post parameter, but probably as an HTTP PUT which is fairly whacky.

    http://php.net/manual/en/features.file-upload.put-method.php

    I'd wager on most shared hosting etc, PUT support is pretty limited or not supported by default. I'd look there first.

    Josh

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?