根级别的数据是无效的PHP SoapClient

时间:2016-10-04 11:13:10

标签: php soap

我必须创建一个SOAP标头,如:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <AuthHeader xmlns="URL">
      <Username>string</Username>
      <Password>string</Password>
      <PublicKey>string</PublicKey>
      <NewPassword>string</NewPassword>
      <UserType>string</UserType>
    </AuthHeader>
  </soap:Header>
  <soap:Body>
    <getClients xmlns="URL" />
  </soap:Body>
</soap:Envelope>

使用sesion()连接,它什么都不返回,但是当XML包含某些内容时,我就会收到错误。

这是我的代码:

$wsdl= "URL?wsdl';

$options = array(
        'uri'=>'http://schemas.xmlsoap.org/soap/envelope/',
        'style'=>SOAP_RPC,
        'use'=>SOAP_ENCODED,
        'soap_version'=>SOAP_1_1,
        'cache_wsdl'=>WSDL_CACHE_NONE,
        'connection_timeout'=>15,
        'trace'=>true,
        'encoding'=>'UTF-8',
        'exceptions'=>true,
    );


try {
    $soap = new SoapClient($wsdl, $options);
    $valor = $soap->getPublicKey();
}

catch(Exception $e) {
    die($e->getMessage());
}

$key=$valor->getPublicKeyResult->any;
$endpoint = 'url';
$user;
$password;
$password64 = mb_convert_encoding($password,'UCS-2LE','auto');
$rsa = new Crypt_RSA();
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$rsa->loadKey($key);
$rsa->setPublicKey($key);
$ciphertext = $rsa->encrypt($password64);
$cipher64 = base64_encode($ciphertext);

$headerbody = array(
'PublicKey'=>$rsa->getPublicKey(),
'Username'=>$user,
'Password'=>$cipher64,
'NewPassword'=>'',
'UserType'=>'U'
);

$header = new SOAPHeader($endpoint, 'AuthHeader', $headerbody);
$soap->__setSoapHeaders($header);


try {
    $data = $soap->sesion();
    $data = $soap->getClients();
}

catch(Exception $e) {
    die($e->getMessage());
}
var_dump($soap->__getTypes());
echo "REQUEST:\n" . htmlentities($soap->__getLastRequest()) . "\n";    
echo "RESPONSE:\n" .  htmlentities($soap->__getLastResponse()) . "\n";
var_dump($data);
die;

形成的标题:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="URL">
  <SOAP-ENV:Header>
    <ns1:AuthHeader>
      <ns1:Username>$user</ns1:Username>                   
      <ns1:Password>$password</ns1:Password>
      <ns1:PublicKey>-----BEGIN PUBLIC KEY-----&#13; PUBLIC KEY#13; -----END PUBLIC KEY-----</ns1:PublicKey>
      <ns1:NewPassword></ns1:NewPassword>
      <ns1:UserType>U</ns1:UserType>
    </ns1:AuthHeader>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <ns1:getClients/>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我尝试了各种解决方案,但没有一个能够正常工作,我无法在信封中包含xlms:xsi,xlms:xsd。我认为这就是我的需要。

0 个答案:

没有答案