WS-Security C#到PHP

WS-Security C#到PHP,c#,php,soap,C#,Php,Soap,我有一个C#代码,它生成一个二进制base64用户名令牌来连接到wsdl var client = new StandardApiClient(); var credentials = client.ClientCredentials.UserName; credentials.UserName = "myusername"; credentials.Password = "mypassword"; 这将创建以下xml <wsse:Security xmlns:wsse="http:/

我有一个C#代码,它生成一个二进制base64用户名令牌来连接到wsdl

var client = new StandardApiClient();
var credentials = client.ClientCredentials.UserName;
credentials.UserName = "myusername";
credentials.Password = "mypassword";
这将创建以下xml

 <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <wsse:UsernameToken wsu:Id="UsernameToken-29" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsse:Username>myusername</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">mypassword</wsse:Password>
        <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">bLW62fQBaMG77CELiw11dg==</wsse:Nonce>
        <wsu:Created>2016-01-22T18:14:02.430Z</wsu:Created>
      </wsse:UsernameToken>
    </wsse:Security> 

我的用户名
我的密码
大厦62FQBAMG77CELIW11DG==
2016-01-22T18:14:02.430Z
我在网上试过几个例子,但都是无效的。 这就是我现在拥有的

protected function getHeaderXml()
    {
        $dateCreated = date('Y/m/d H:i:s');

        $nonce = base64_encode(sha1((mt_rand() . $dateCreated . self::PASSWORD)));

        return ' 
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://cdx.XXXXX.com/Api/0.99/" xmlns:deal="http://schemas.datacontract.org/2004/07/XXX.BaseApi" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
        <soapenv:Header>
                    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                      <wsse:UsernameToken wsu:Id="UsernameToken-29" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                        <wsse:Username>'.self::USERNAME.'</wsse:Username>
                        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">'.urlencode(self::PASSWORD).'</wsse:Password>
                        <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">'.$nonce.'</wsse:Nonce>
                        <wsu:Created>'.$dateCreated.'</wsu:Created>
                      </wsse:UsernameToken>
                    </wsse:Security>
                  </soapenv:Header>
                  <soapenv:Body>';
    }
受保护的函数getHeaderXml() { $dateCreated=日期('Y/m/d H:i:s'); $nonce=base64_编码(sha1((mt_rand().$dateCreated.self::PASSWORD)); 返回' “.self::USERNAME。” “.urlencode(self::PASSWORD)。” “.$nonce。” “.$dateCreated。” '; }