2015-09-26 179 views
-1

我正在嘗試將支付網關集成到簡單的PHP站點(我自己的站點)中,並且網關只接受SOAP格式的數據。我完全不知道SOAP是什麼,但感謝谷歌,我現在知道它是怎麼樣的(至少)。使用PHP發送SOAP請求並獲取返回的響應

基本上,我需要發送一堆客戶數據和支付數據到網關根據收到的響應行事。以下是示例請求代碼和示例響應代碼。他們只提供要發佈到的網址,即http://69.94.141.22/SaveTransactions.asmx

請求

POST /SaveTransactions.asmx HTTP/1.1 
Host: 69.94.141.22 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <SendTransactionsAction xmlns="http://tempuri.org/"> 
     <strUserName>string</strUserName> 
     <strPassword>string</strPassword> 
     <strSecureKey>string</strSecureKey> 
     <strFirstName>string</strFirstName> 
     <strLastName>string</strLastName> 
     <strPhoneNumber>string</strPhoneNumber> 
     <strStreetNumber>string</strStreetNumber> 
     <strUnitNumber>string</strUnitNumber> 
     <strStreetName>string</strStreetName> 
     <strCity>string</strCity> 
     <strState>string</strState> 
     <strZipCode>string</strZipCode> 
     <strEmailAddress>string</strEmailAddress> 
     <strBankName>string</strBankName> 
     <strRoutingNo>string</strRoutingNo> 
     <strAccountNumber>string</strAccountNumber> 
     <strCheckNo>string</strCheckNo> 
     <strAmount>string</strAmount> 
     <strNotes>string</strNotes> 
    </SendTransactionsAction> 
    </soap12:Body> 
</soap12:Envelope> 

響應

HTTP/1.1 200 OK 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <SendTransactionsActionResponse xmlns="http://tempuri.org/"> 
     <SendTransactionsActionResult>string</SendTransactionsActionResult> 
    </SendTransactionsActionResponse> 
    </soap12:Body> 
</soap12:Envelope> 

如何發佈這些到URL提供了使用PHP和如何獲取該響應SendTransactionsActionResult從返回的響應?

我不是要求你爲我做這件事,而是像代碼一樣簡單的開始會有很大的幫助。
在此先感謝

回答

0

您可以通過使用Curl,PHP soapClientNuSOAP

歸檔此下面我向您展示如何使用的NuSOAP

另外,WSDL是http://69.94.141.22/SaveTransactions.asmx?WSDL位置

$client = new nusoap_client("http://69.94.141.22/SaveTransactions.asmx?WSDL", true); // this should be the wsdl location 
    $error = $client->getError(); 
    if ($error) { 
     echo "<h2>Constructor error</h2><pre>" . $error . "</pre>"; 
    } 
    // Use basic authentication method 
    $client->setCredentials("username", "password", "basic"); //set here the credentials if need for the wsdl 
    $client->setHeaders('<SendTransactionsAction xmlns="http://tempuri.org/"> 
         <strUserName>string</strUserName> 
         <strPassword>string</strPassword> 
         <strSecureKey>string</strSecureKey> 
         <strFirstName>string</strFirstName> 
         <strLastName>string</strLastName> 
         <strPhoneNumber>string</strPhoneNumber> 
         <strStreetNumber>string</strStreetNumber> 
         <strUnitNumber>string</strUnitNumber> 
         <strStreetName>string</strStreetName> 
         <strCity>string</strCity> 
         <strState>string</strState> 
         <strZipCode>string</strZipCode> 
         <strEmailAddress>string</strEmailAddress> 
         <strBankName>string</strBankName> 
         <strRoutingNo>string</strRoutingNo> 
         <strAccountNumber>string</strAccountNumber> 
         <strCheckNo>string</strCheckNo> 
         <strAmount>string</strAmount> 
         <strNotes>string</strNotes> 
        </SendTransactionsAction> 
        '); 
    $result = ""; 
    if ($client) { 
     $result = $client->call("SendTransactionsAction"); // soap action 
    } 
    if ($client->fault) { 
     echo "<h2>Fault</h2><pre>"; 
     print_r($result); 
     echo "</pre>"; 
    } 
    else { 
     $error = $client->getError(); 
     if ($error) { 
      echo "<h2>Error</h2><pre>" . $error . "</pre>"; 
     } 
     else { 
      echo "<h2>zip code</h2><pre>"; 
      print_r($result); 
      echo "</pre>"; 
     } 
    } 
    echo "<h2>Request</h2>"; 
    echo "<pre>" . htmlspecialchars($client->request, ENT_QUOTES) . "</pre>"; 
    echo "<h2>Response</h2>"; 
    echo "<pre>" . htmlspecialchars($client->response, ENT_QUOTES) . "</pre>"; 
0

使用來自http://69.94.141.22/SaveTransactions.asmx?WSDL的WSDL,您可以從wsdltophp.com生成相應的包,以確定如何在PHP中構建您的請求,因爲每個元素都將成爲帶有setter/getters的PHP對象。它使用原生的PHP SoapClient類,因此如果您熟悉PHP

,您就可以輕鬆快速地理解發送這些請求的人員