簡體   English   中英

如何使用WSSE與SOAP API建立PHP連接

[英]How to establishing a PHP connection with SOAP API with WSSE

我需要幫助! 我搜索了幾乎所有地方,但是不幸的是,關於PHP&SOAP&WSSE的信息並不多。 我在這里發帖,看看是否有人可以幫助我。 我正在使用該庫通過WSSE連接到SOAP服務: http : //goo.gl/en7hvh這是我的連接設置: http : //pastebin.com/vc3X5aDj,但是出現此錯誤:

 Fault string: Unauthorized request. Make sure the Customer name, User and 
 Password are provided.

 Fault code: soap:Client

我已經仔細檢查了我的用戶名和密碼,它們都是正確的。 如果我調用getLastResponse和getLastReponseRequest,就會出現:

 HTTP/1.1 500 Internal Server Error Cache-Control: private Content-Type: text/xml; charset=utf-8 Server: Microsoft-IIS/7.5 X-AspNet-Version: 2.0.50727 X-Powered-By: ASP.NET Date: Thu, 20 Mar 2014 23:43:53 GMT Content-Length: 1226

 http://schemas.xmlsoap.org/ws/2004/08/addressing/faulturn:uuid:b38a9ad8-d819-463c-a801-122009040f04urn:uuid:3f9247a3-4cbd-4d0d-964a-bf9182867d4ahttp://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous2014-03-20T23:43:53Z2014-03-20T23:48:53Zsoap:ClientUnauthorized request. Make sure the Customer name, User and Password are provided.

這是我需要生成的請求: http : //pastebin.com/aRMmVMj0我不知道我在想什么。...請幫助我!

我知道你的痛苦,幸運的是我已經克服了!

class WSSEAuth {

   private $Username;
   private $Password;

   function __construct($username, $password) {
      $this->Username = $username;
      $this->Password = $password;
   }

}

class WSSEToken {

   private $UsernameToken;

   function __construct($innerVal) {
      $this->UsernameToken = $innerVal;
   }

}

class MySoapClient {

   private $username;
   private $password;
   private $options;
   private $header;
   private $wsdl;
   private $wsse;
   private $gw;
   public $start_time;

   public function getClient($wsse, $user, $pw, $wsdl, $gw) {

      $this->wsse = $wsse;
      $this->username = $user;
      $this->password = $pw;
      $this->wsdl = $wsdl;
      $this->gw = $gw;
      $this->start_time = microtime(true);

      $this->options = array(
          'trace'=>1,
          'username'=>$this->username,
          'password'=>$this->password,
          'exceptions'=>true,
          'connection_timeout'=>5,
      );

      $objSoapVarUser = new SoapVar($this->username, XSD_STRING, NULL, $this->wsse, NULL, $this->wsse);
      $objSoapVarPass = new SoapVar($this->password, XSD_STRING, NULL, $this->wsse, NULL, $this->wsse);
      $objWSSEAuth = new WSSEAuth($objSoapVarUser, $objSoapVarPass);
      $objSoapVarWSSEAuth = new SoapVar($objWSSEAuth, SOAP_ENC_OBJECT, NULL, $this->wsse, 'UsernameToken', $this->wsse);
      $objWSSEToken = new WSSEToken($objSoapVarWSSEAuth);
      $objSoapVarWSSEToken = new SoapVar($objWSSEToken, SOAP_ENC_OBJECT, NULL, $this->wsse, 'UsernameToken', $this->wsse);
      $this->header = new SoapVar($objSoapVarWSSEToken, SOAP_ENC_OBJECT, NULL, $this->wsse, 'Security', $this->wsse);
      $objSoapVarWSSEHeader[] = new SoapHeader($this->wsse, 'Security', $this->header, true, $this->gw);

      $objClient = new SoapClient($this->wsdl, $this->options);
      $objClient->__setSoapHeaders($objSoapVarWSSEHeader);

      return $objClient;
   }

}

在所有這些類之后,執行以下操作:

$var = new MySoapClient;
$var_client = $var->getClient('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'your_user', 'your_password', 'your_wsdl', 'your_gate');

然后,例如,您可以調用以下內容:

$var_client->__soapCall('Function', $soap_payload);

編輯:我修正了一些錯字!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM