0
您好,我在集成支付網關時遇到問題,網關需要XML格式的請求,我的網站和購物車位於PHP,我想要一個解決方案將我的HTML表單值XML格式的服務器,服務器需要下列XML格式:將數據以XML格式發送到服務器通過HTML表格
<html>
<head>
</head>
<body>
<form method="POST" action="https://3ds.cps.lv/GatorServo/request">
<input name="type" value="sendForAuth">
<textarea name="xml">
<?xml version="1.0" encoding="UTF-8" ?>
<cpsxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.cps.lv/xml/ns/cpsxml
https://3ds.cps.lv/GatorServo/Gator_SendForAuth.xsd"
xmlns="http://www.cps.lv/xml/ns/cpsxml">
<header xmlns="">
<responsetype>direct</responsetype>
<user>test_sign</user>
<type>sendForAuth</type>
<transType>DB</transType>
<digiSignature>XXXXXXXXXXXXXXXXXXXXXXX</digiSignature>
</header>
<request xmlns="">
<orderNumber></orderNumber>
<cardholder>
<firstName>FirstName</firstName>
<lastName>LastName</lastName>
<street>Street</street>
<zip>54321</zip>
<city>City</city>
<country>LV</country>
<email>[email protected]</email>
<ip>123.124.125.126</ip>
</cardholder>
<amount>
<value>1000</value>
<currency>USD</currency>
</amount>
<product>
<productName>Product Name</productName>
<productUrl>www.test.com</productUrl>
</product>
</request>
</cpsxml>
</textarea>
<input type="submit" value="Send">
</form>
</body>
</html>
這裏是我的PHP文件,我一直在使用json2xml嘗試,但至今沒有運氣
<?php
require_once('../assist/cart-load.php');
if(isset($_POST) && isset($_POST['assist'])){
$order_id= $_REQUEST['order_id'];
$a_amount = $_REQUEST['a_total'];
$c_amount = $_REQUEST['c_total'];
$admin_curr = $_REQUEST['a_curr'];
$chk_curr = $_REQUEST['c_curr'];
$checksum = $_SESSION['basket']['security'];
$checksum2 = $_SESSION['basket']['security2'];
}
?>
<html>
<head><title>Complete Your Payment</title>
<script src="json2xml.js" type="text/javascript"></script>
<script type="text/javascript">
var formjson = $('form#payment_form').serializeArray();
//var formxml = $.compactJSON(mjson);
var formxml = json2xml(formjson);
alert(formxml);
$.post("/collect.cgi", { 'data': formxml }, function (data){ });
</script>
</head>
<body>
<form method="post" id="payment_form" name="payment_form" action="https://3ds.cps.lv/GatorServo/request">
<input type="hidden" name="responsetype" value="direct">
<input type="hidden" name="user" value="test_pasta_sign">
<input name="type" type="hidden" value="sendForAuth">
<input type="hidden" name="transType" value="DB">
<input type="hidden" name="digisignature" value="XXXXXXXXXXXXXXXXXXXXXXX">
<p>Order Number</p>
<input type="text" readonly name="orderNumber" value="<?php echo $order_id; ?>">
<p>F Name</p>
<input type="text" name="firstname" value="">
<p>L Name</p>
<input type="text" name="lastname" value="">
<p>Street Address</p>
<input type="text" name="street" value="">
<p>Zip</p>
<input type="text" name="zip" value="">
<p>City</p>
<input type="text" name="city" value="">
<p>Country</p>
<input type="text" name="country" value="">
<p>Email</p>
<input type="text" name="email" value="[email protected]">
<input type="hidden" name="ip" value="123.124.125.126">
<p>Enter Card No.</p>
<input type="text" name="cardNumber" value="">
<p>Enter CVV</p>
<input type="text" name="cvv" value="">
<p>Card Expiry</p>
<input type="text" name="expires" value="">
<p>Amount</p>
<input type="text" name="value" readonly value="<?php echo $a_amount; ?>">
<input type="hidden" name="currency" value="USD">
<p>Product Name</p>
<input type="text" name="productName" value="Product Name" readonly>
<input type="hidden" name="productUrl" value="http://www.test.com">
<input type="submit" value="Send">
</form></body></html>
請給我提供了這個更好的解決方案問題。提前致謝!
UPDATE:現在我已刪除了jsontoxml現在使用jquery.ajax,這裏是腳本
<script type="text/javascript">
var ajaxurl="https://3ds.cps.lv/GatorServo/request";
var str="";
for(i=0; i<document.payment_form.elements.length; i++)
{
var fieldName = document.payment_form.elements[i].name;
var fieldValue = document.payment_form.elements[i].value;
str += "<" + fieldName + ">" ;
str += fieldValue ;
str += "</" + fieldName + ">" ;
}
$.ajax({
url: ajaxurl,
data: str,
type: 'POST',
contentType: "text/xml",
dataType: "xml",
success : parse_result,
error : show_error
});
function parse_result(xml){
//
}
function show_error(){
//
}
</script>
但現在我得到錯誤:從服務器「畸形XML請求」。
任何解決方案?
使用'json2xml'的結果是什麼? – madfriend
無效的參數 – Henry