2016-03-08 101 views
0

嗨我必須從使用url和登錄參數和一些XML參數作爲輸入的網站獲取信息使用PHP。我是任何API調用的新手,請解釋我如何在我的PHP代碼中使用這些參數,並向服務器發出請求以獲取信息 當我在SOAP UI中使用這些參數時,我可以獲得演示結果,我需要在PHP中構建相同。調用REST API以使用URL和參數從網站檢索數據

https://transact-prelive.litle.com/vap/communicator/online 
Username: u82917418420715660 
Password: dENteSXnXwfqKHF 
Merchant Id: 01183990 

<litleOnlineRequest version="9.4" xmlns="http://www.litle.com/schema" merchantId="01183990"> 
    <authentication> 
     <user>u82917418420715660</user> 
     <password>dENteSXnXwfqKHF</password> 
    </authentication> 
    <authorization id="834262" reportGroup="ABC Division" customerId="038945"> 
     <orderId>65347567</orderId> 
     <amount>40000</amount> 
     <orderSource>3dsAuthenticated</orderSource> 
     <billToAddress> 
      <name>John Smith</name> 
      <addressLine1>100 Main St</addressLine1> 
      <city>Boston</city> 
      <state>MA</state> 
      <zip>12345</zip> 
      <email>[email protected]</email> 
      <phone>555-123-4567</phone> 
     </billToAddress> 
     <card> 
     <type>VI</type> 
     <number>4000000000000001</number> 
     <expDate>1209</expDate> 
     <cardValidationNum>555</cardValidationNum> 
     </card> 
     <cardholderAuthentication> 
      <authenticationValue></authenticationValue> 
      <authenticationTransactionId></authenticationTransactionId> 
     </cardholderAuthentication> 
    </authorization> 
</litleOnlineRequest> 
+1

你可以使用php curl函數。看看 http://stackoverflow.com/questions/561816/php-curl-extract-an-xml-response –

回答

0

您可以使用nusoap庫在PHP中使用SOAP。這裏是一個如何使用它的例子。它與您的查詢相似。

 $this->load->library("lib_nusoap"); 
     $wsdl = "https://transact-prelive.litle.com/vap/communicator/online"; 
     $client = new nusoap_client($wsdl, 'wsdl'); 

     //$client->setCredentials($api_username,$api_password); 
     $error = $client->getError(); 
     if ($error) 
     { 
      echo "\nSOAP Error\n".$error."\n"; 
      return false; 
     } 
     else 
     { 
      $params = array ('user' => "u82917418420715660 ", 'Password' => "dENteSXnXwfqKHF "); 
      $result = $client->call('retrive', $params); 
      if ($client->fault) 
      { 
       print_r($result); 
       print $client->fault; 
      } 
      else 
      { 
       $result_arr = json_decode($result, true); 
      }  
     } 
     print_r($result_arr); 

Nusoap庫將處理CURL API調用。

+0

得到這個錯誤:致命錯誤:使用$ this,而不是在C:\ wamp \第4行的www \ test \ curl.php –

+0

@hemanthkumar庫函數必須在控制器類的某些函數中使用,並確保它正在擴展CI_Controller。 –

+0

它不在代碼點火器中。我只是使用它在平坦的PHP, –