0

我需要将 SOAP 标头设置为这种格式:

<soapenv:Header>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsse:UsernameToken wsu:Id="UsernameToken-45">
            <wsse:Username>XXXXX</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XXXXXXX</wsse:Password>
            <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">OxWtCYYj1cX7HiZeMEqorw==</wsse:Nonce>
            <wsu:Created>2013-09-18T07:25:50.227Z</wsu:Created>
        </wsse:UsernameToken>
    </wsse:Security>
</soapenv:Header>

我尝试使用下面的代码验证 Web 服务,但没有成功。

$momurl = "https://integrationdev.momentum.co.za/sales/CRMService/CRMLeadService_v1_0/";

$client = new SoapClient(
    "$momurl",
    array(
        'trace' => 1,
        'login' => $username,
        'password' => $password
    )
);

任何帮助,将不胜感激。提前致谢。

4

1 回答 1

5

你需要使用SoapClient::__setSoapHeader(). 像这样:

$security = array(
    'Username'=>'XXXXX',
    'Password'=>'XXXXX',
    'Nonc'=> 'OxWtCYYj1cX7HiZeMEqorw==',
    'Created' => '2013-09-18T07:25:50.227Z',
    'UsernameToken' => NULL
);

$header = new SoapHeader('wsse','Security',$security, false);
$client->__setSoapHeaders($header);
于 2013-09-19T09:36:09.577 回答