2016-09-21 62 views
1

我有以下請求發送到XML。我想用PHP發送它。你能幫我怎麼寫php curl函數發送下面的xml嗎?如何編寫php curl請求securetrading.com支付網關

POST /xml/ HTTP/1.0 
Content-Type: text/xml;charset=utf-8 
Content-Length: 839 
Accept: text/xml 
Accept-Encoding: gzip 
Authorization: <BASIC AUTH CREDENTIALS HERE> 
User-Agent: <YOUR SOFTWARE VERSION HERE> 
Host: webservices.securetrading.net 
Connection: close 

<requestblock version="3.67"> 
    <alias>[email protected]</alias> 
    <request type="AUTH"> 
    <operation> 
     <sitereference>test_site12345</sitereference> 
     <accounttypedescription>ECOM</accounttypedescription> 
    </operation> 
    <merchant> 
     <orderreference>Example AUTH</orderreference> 
     <termurl>https://www.example.com/termurl.cgi</termurl> 
     <name>Test Merchant</name> 
    </merchant> 
    <customer> 
     <ip>1.2.3.4</ip> 
    </customer> 
    <billing> 
     <amount currencycode="GBP">2115</amount> 
     <town>Bangor</town> 
     <country>GB</country> 
     <payment type="VISA"> 
     <expirydate>10/2031</expirydate> 
     <pan>4111111111111111</pan> 
     <securitycode>123</securitycode> 
     </payment> 
    </billing> 
    <settlement/> 
    </request> 
</requestblock> 

需要來自php專業人士的幫助。

+0

對不起爲XML數據發送,但SO是_not_一個免費的編碼服務。我建議你聘請一名程序員爲你完成這項工作。 – arkascha

+0

我看過代碼,我們可以直接在curl中發送xml,但是我再也找不到那個url。 – user3264863

+0

只需看一看php curl文檔,它帶有簡單的例子。 XML沒什麼特別的,只是一個字符串。你只需要做一個捲曲POST請求。你一定能弄清楚。走! – arkascha

回答

1

這是樣品,你可以使用curl

$url="http://"; // Enter url here 
$curl = curl_init(); 
curl_setopt_array($curl, array(
    CURLOPT_URL => $url, 
    CURLOPT_RETURNTRANSFER => true, 
    CURLOPT_TIMEOUT => 30, 
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 
    CURLOPT_CUSTOMREQUEST => "POST", 
    CURLOPT_POSTFIELDS => "<requestblock version=\"3.67\">\r\n <alias>[email protected]</alias>\r\n <request type=\"AUTH\">\r\n <operation>\r\n  <sitereference>test_site12345</sitereference>\r\n  <accounttypedescription>ECOM</accounttypedescription>\r\n </operation>\r\n <merchant>\r\n  <orderreference>Example AUTH</orderreference>\r\n  <termurl>https://www.example.com/termurl.cgi</termurl>\r\n  <name>Test Merchant</name>\r\n </merchant>\r\n <customer>\r\n  <ip>1.2.3.4</ip>\r\n </customer>\r\n <billing>\r\n  <amount currencycode=\"GBP\">2115</amount>\r\n  <town>Bangor</town>\r\n  <country>GB</country>\r\n  <payment type=\"VISA\">\r\n  <expirydate>10/2031</expirydate>\r\n  <pan>4111111111111111</pan>\r\n  <securitycode>123</securitycode>\r\n  </payment>\r\n </billing>\r\n <settlement/>\r\n </request>\r\n</requestblock>", 
    CURLOPT_HTTPHEADER => array(
     "accept-encoding: application/gzip",   
     "content-type: text/xml" 
    ), 
)); 
$response = curl_exec($curl); 
$err = curl_error($curl); 
curl_close($curl); 
if ($err) { 
    echo "cURL Error #:" . $err; 
} else { 
    echo $response; 
} 
+0

謝謝rakeshbhai – user3264863

+1

謝謝。我只是需要一些代碼。現在我將能夠解決問題。 – user3264863