将nusoap与XML Document API一起使用

时间:2013-08-27 12:05:29

标签: php xml nusoap

我正试图让viapost的一个登录段工作。

我正在使用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>bradlyspicer@hotmail.co.uk</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 个答案:

答案 0 :(得分: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('bradly.spicer@', 'YourPassword');
?>