致命错误:未捕获异常'Exception',消息'String无法解析为XML'payleap

时间:2013-05-14 11:00:03

标签: php curl

我已从他们的网站上获取以下代码来进行payleap结帐

以下是我的代码

    function payleap_send($packet, $url) {

$header = array("MIME-Version: 1.0","Content-type: application/x-www-form-urlencoded","Contenttransfer-encoding: text"); 
$ch = curl_init();

// set URL and other appropriate options 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); 
// Uncomment for host with proxy server
// curl_setopt ($ch, CURLOPT_PROXY, "http://proxyaddress:port"); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $packet); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 10); 

// send packet and receive response
$response = curl_exec($ch); 
curl_close($ch); 
return($response);
}

function simple_xml_find($haystack, $needle) {
// supplying a valid closing XML tag in $needle, this will return the data contained by the element
// the element in question must be a leaf, and not itself contain other elements (this is *simple*_xml_find =)

if(($end = strpos($haystack, $needle)) === FALSE)
    return("");

for($x = $end; $x > 0; $x--)
    {
    if($haystack{$x} == ">")
        return(trim(substr($haystack, $x + 1, $end - $x - 1)));
    }
return ("");
}


if(getenv("REQUEST_METHOD") == "POST")
    {
    // build the HTTP request
    $args  = "UserName=" . htmlspecialchars($_POST['txtUserName']);
    $args .= "&Password=" . htmlspecialchars($_POST['txtPassword']);
    $args .= "&Vendor=" . htmlspecialchars($_POST['txtVendor']);
    $args .= "&CustomerID=" . htmlspecialchars($_POST['txtCustomerID']);
    $args .= "&CustomerName=" . htmlspecialchars($_POST['txtCustomerName']);
    $args .= "&FirstName=" . htmlspecialchars($_POST['txtFirstName']);
    $args .= "&LastName=" . htmlspecialchars($_POST['txtLastName']);
    $args .= "&Title=" . htmlspecialchars($_POST['txtTitle']);
    $args .= "&Department=" . htmlspecialchars($_POST['txtDepartment']);
    $args .= "&Street1=" . htmlspecialchars($_POST['txtStreet1']);
    $args .= "&Street2=" . htmlspecialchars($_POST['txtStreet2']);
    $args .= "&Street3=" . htmlspecialchars($_POST['txtStreet3']);
    $args .= "&City=" . htmlspecialchars($_POST['txtCity']);
    $args .= "&StateID=" . htmlspecialchars($_POST['txtStateID']);
    $args .= "&Province=" . htmlspecialchars($_POST['txtProvince']);
    $args .= "&Zip=" . htmlspecialchars($_POST['txtZip']);
    $args .= "&CountryID=" . htmlspecialchars($_POST['txtCountryID']);
    $args .= "&Phone=" . htmlspecialchars($_POST['txtPhone']);
    $args .= "&Email=" . htmlspecialchars($_POST['txtEmail']);
    $args .= "&DayPhone=" . htmlspecialchars($_POST['txtDayPhone']);
    $args .= "&NightPhone=" . htmlspecialchars($_POST['txtNightPhone']);
    $args .= "&Fax=" . htmlspecialchars($_POST['txtFax']);
    $args .= "&Mobile=" . htmlspecialchars($_POST['txtMobile']);
    $args .= "&ContractID=" . htmlspecialchars($_POST['txtContractID']);
    $args .= "&ContractName=" . htmlspecialchars($_POST['txtContractName']);
    $args .= "&BillAmt=" . htmlspecialchars($_POST['txtBillAmt']);
    $args .= "&TaxAmt=" . htmlspecialchars($_POST['txtTaxAmt']);
    $args .= "&TotalAmt=" . htmlspecialchars($_POST['txtTotalAmt']);
    $args .= "&MaxFailures=" . htmlspecialchars($_POST['txtMaxFailures']);
    $args .= "&FailureInterval=" . htmlspecialchars($_POST['txtFailureInterval']);
    $args .= "&EmailCustomer=" . htmlspecialchars($_POST['txtEmailCustomer']);
    $args .= "&EmailMerchant=" . htmlspecialchars($_POST['txtEmailMerchant']);
    $args .= "&EmailCustomerFailure=" . htmlspecialchars($_POST['txtEmailCustomerFailure']);
    $args .= "&EmailMerchantFailure=" . htmlspecialchars($_POST['txtEmailMerchantFailure']);
    $args .= "&CcAccountNum=" . htmlspecialchars($_POST['txtCcAccountNum']);
    $args .= "&CcExpDate=" . htmlspecialchars($_POST['txtCcExpDate']);
    $args .= "&CcNameOnCard=" . htmlspecialchars($_POST['txtCcNameOnCard']);
    $args .= "&CcStreet=" . htmlspecialchars($_POST['txtCcStreet']);
    $args .= "&CcZip=" . htmlspecialchars($_POST['txtCcZip']);
    $args .= "&StartDate=" . htmlspecialchars($_POST['txtStartDate']);
    $args .= "&EndDate=" . htmlspecialchars($_POST['txtEndDate']);
    $args .= "&BillingPeriod=" . htmlspecialchars($_POST['txtBillingPeriod']);
    $args .= "&BillingInterval=" . htmlspecialchars($_POST['txtBillingInterval']);
    $args .= "&ExtData=<TrainingMode>T</TrainingMode>";

    // place against the PayLeap payment gateway
    $result = payleap_send($args, "https://uat.payleap.com/merchantservices.svc/AddRecurringCreditCard");
    $xmlData = new SimpleXMLElement(stripslashes($result));
    }

我在此行Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML'

上收到此错误$xmlData = new SimpleXMLElement(stripslashes($result));

卷曲的反应如下

<RecurringResult xmlns="http://www.payleap.com/payments" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<CcInfoKey>11111</CcInfoKey>
<Code>Ok</Code>
<ContractKey>22222</ContractKey>
<CustomerKey>33333</CustomerKey>
<Error>RecurringCreditCard Added</Error>
<UserName>API_id001111</UserName>
<Vendor>3333</Vendor>
</RecurringResult> 

有人对此有任何想法吗?

1 个答案:

答案 0 :(得分:0)

我不确定,但请尝试使用此标题而不是当前标题。

curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-type: text/xml' ));