所以我想要做的是解析响应中的每个“节点”,因为缺少更好的单词。它应该回显“标签”,然后是“:”然后是值。我试过的是“代码”部分。从当前代码返回的内容位于“响应”部分。我正在尝试从其他代码中学习,这是“用于调试和认证目的的显示标题/正文/响应”代码的来源。我只是试图修改它以回应解析后的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);
?>
答案 0 :(得分:1)
你需要从http正文中单独的http标题。这是一个"\r\n\r\n"
snting。所以你可以这样找到它:
$p = strpos($rawResponse, "\r\n\r\n");
if( $p !== false ) {
$rawHeades = substr($rawResponse, 0, $p);
$rawBody = substr($rawResponse, $p + 4);
}
你需要print curl_error($ch);
之后的一些东西 - 在这种情况下,$ rawResponse中没有任何真实的数据