所以我想要做的是解析响应中的每个“节点”,因为没有更好的词。它应该回显“标签”,后跟“:”,然后是值。我尝试过的是“代码”部分。当前代码返回的内容位于“响应”部分。我正在尝试从其他代码中学习,这就是“用于调试和认证目的的显示标题/正文/响应”代码的来源。我只是想修改它以在解析后的 rawResponse 明显不响应时回显它。
回复:
headers:
body:
rawResponse:AC700000005332001VI4788250000028291sBn551664C1A088C3242DF9CD5C92D52A8FA9EDD532D10100 N097857Approved00N013731
OrderID: sBn5
TxRefNum: 51664C1A088C3242DF9CD5C92D52A8FA9EDD532D
RespCode: 00
AVSRespCode:
CVV2RespCode: N
AuthCode: 097857
代码:
<?php
$xml_data = "<Request><NewOrder>";
$xml_data .= "<IndustryType>EC</IndustryType>";
$xml_data .= "<MessageType>AC</MessageType>";
$xml_data .= "<BIN>000002</BIN>";
$xml_data .= "<AccountNum>".$varCC."</AccountNum>";
$xml_data .= "<Exp>".$varExpiry."</Exp>";
$xml_data .= "<CardSecVal>".$varCVV."</CardSecVal>";
$xml_data .= "<OrderID>sBn5</OrderID>";
$xml_data .= "<Amount>".$varAmt."</Amount>";
$xml_data .= "</NewOrder></Request>";
$URL = "https://orbitalvar1.paymentech.net";
// Build header as array for cURL option
$header = "POST /AUTHORIZE HTTP/1.0\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-type: application/PTI46\r\n";
$header.= "Content-length: ".strlen($xml_data)."\r\n";
$header.= "Content-transfer-encoding: text\r\n";
$header.= "Request-number: 1\r\n";
$header.= "Document-type: Request\r\n";
$header.= "Interface-Version: Test 1.4\r\n";
$header.= "Connection: close \r\n\r\n";
$header.= $xml_data;
// Define cURL options, then connect to server while saving response
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$rawResponse = curl_exec($ch);
if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
}
/////////////////////////////////////////////////////////////////////////////
// Display headers / body / response for debugging and certification purposes
/////////////////////////////////////////////////////////////////////////////
echo "headers:<BR>\n";
foreach($header as $value) echo " $value<BR>\n";
echo "<BR>body:<BR>\n $body<BR><BR><HR>\n";
echo "<BR>rawResponse:<BR>\n $rawResponse<BR><BR>\n";
// Parse rawResponse XML to response array, then only display important values
$parser = xml_parser_create('UTF-8');
xml_parse_into_struct($parser, $rawResponse, $response);
//var_dump($response);
foreach($response as $value){
switch($value["tag"]){
case "ORDERID": echo "OrderID: ".$value["value"]."<BR>\n"; break;
case "RESPCODE": echo "RespCode: ".$value["value"]."<BR>\n"; break;
case "AVSRESPCODE": echo "AVSRespCode: ".$value["value"]."<BR>\n"; break;
case "CVV2RESPCODE": echo "CVV2RespCode: ".$value["value"]."<BR>\n"; break;
case "TXREFNUM": echo "TxRefNum: ".$value["value"]."<BR>\n"; break;
case "AUTHCODE": echo "AuthCode: ".$value["value"]."<BR>\n"; break;
}
}unset($value);
?>