繁体   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