2013-08-27 21 views
1

我正在嘗試使viapost的登錄部分能夠正常工作。將nusoap與XML文檔API一起使用

我現在用的是API的這一部分:https://api.viapost.com/viapostcustomer.asmx?op=SignIn

這裏是我的那個片段的版本:

  <?php 
      require_once('lib/nusoap.php'); 

      $endpoint = "http://api.viapost.com/SignIn"; 

      $client = new nusoap_client($endpoint, false); 

      $xml ='<?xml version="1.0" encoding="utf-8"?> 
      <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
       <soap:Body> 
       <SignIn xmlns="http://api.viapost.com"> 
        <sUserName>[email protected]</sUserName> 
        <sPassword>passwordhere</sPassword> 
        <sReturnMessage>Logged in Successfully</sReturnMessage> 
       </SignIn> 
       </soap:Body> 
      </soap:Envelope>'; 

      $msg = $client->serializeEnvelope($xml); 

      $result=$client->send($msg, $endpoint); 

      print_r($result); 

      ?> 

密碼本身在這裏更換,但我知道100%的防雷工程登錄到網站。

當我訪問此頁面時,我得不到回報。只是空白頁

回答

1

嘗試使用SoapClient

<?php 
class ViaPost 
{ 
    private $wsdl = 'https://api.viapost.com/viapostcustomer.asmx?wsdl'; 
    private $client; 
    private $token; 

    public function __construct() 
    { 
    $this->client = new SoapClient($this->wsdl, array('trace' => true, 'soap_version' => SOAP_1_2)); 
    } 

    public function SignIn($username, $password) 
    { 
    $result = $this->client->SignIn(array ('sUserName' => $username, sPassword => $password)); 
    $this->token = $result->sLoginToken; 
    } 
} 

$viaPost = new ViaPost(); 
$viaPost->SignIn('[email protected]', 'YourPassword'); 
?> 
+0

此外,還發現[ViaPost在GitHub上的回購](https://github.com/JANorman/Codeigniter-ViaPost-API)。 – pritaeas