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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。