无法在php中为用户身份验证设置soap标头



我的完整soap结构如下:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:uw="http://xmlns.oracle.com/Enterprise/HCM/services/UW_STBIO_REQ.V1">
  <soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <wsse:Security soap:mustUnderstand="1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
   <wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <wsse:Username>XXXXXXXX</wsse:Username>
    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XXXXXXXX</wsse:Password>
  </wsse:UsernameToken>
 </wsse:Security>
 </soapenv:Header>
 <soapenv:Body>
  <uw:UW_STBIO_REQ>
    <uw:EMPLID>428864</uw:EMPLID>
  </uw:UW_STBIO_REQ>
 </soapenv:Body>
</soapenv:Envelope>
我的PHP代码是:
<?php
$studentFeesInformationObj = new soapclient("wsdl/QAGetStudentBioInformation.wsdl", array('trace' => 1));
$security = array( 'UsernameToken' => array(
                                                'Username'=>'XXXXXXXX',
                                                'Password'=>'XXXXXXXX'    
                                            )
                                        );
$header = new SoapHeader('wsse','Security',$security, false);
$studentFeesInformationObj->__setSoapHeaders($header);
$params = array('EMPLID' => '428864');
try{
    $result = $studentFeesInformationObj->__soapCall('UW_STUDBIO_SO', array('parameters' => $params));
}
catch(Exception $e)
{
    echo "<pre>$e<br>";
    echo "REQUEST HEADERS:n" . $studentFeesInformationObj->__getLastRequestHeaders() . "n";
    print_r($studentFeesInformationObj);    
}
echo "<pre>";print_r($result); 
?>

现在,当我尝试使用任何其他客户端,如在我的情况下chrome插件,它的工作很好,但当我尝试使用相同的PHP,它不工作,我得到以下响应:

SoapFault exception: [soapenv:Server] BEA-380001: Internal Server Error in /var/www/html/nusoap-0.9.5/client.php:20

终于在这里找到了答案:

class WsseAuthHeader extends SoapHeader {
private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
private $wsu_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
function __construct($user, $pass) {
    $created = gmdate('Y-m-dTH:i:sZ');
    $nonce = mt_rand();
    $passdigest = base64_encode( pack('H*', sha1( pack('H*', $nonce) . pack('a*',$created).  pack('a*',$pass))));
    $auth = new stdClass();
    $auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
    $auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
    $auth->Nonce = new SoapVar($passdigest, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
    $auth->Created = new SoapVar($created, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wsu_ns);
    $username_token = new stdClass();
    $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);
    $security_sv = new SoapVar(
        new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),
        SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
    parent::__construct($this->wss_ns, 'Security', $security_sv, true);
}
}

并创建如下标题:

$client->__setSoapHeaders(Array(new WsseAuthHeader("user", "pass")));

相关内容

  • 没有找到相关文章

最新更新