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条)

报告相同问题?

悬赏问题

  • ¥15 表达式必须是可修改的左值
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题