web服务-PHP:SOAP请求的证书链


web services - PHP: certificate chain for SOAP request

我有下面这样的示例SOAP请求消息,

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v="http://incometaxindiaefiling.gov.in/ws/ds/common/v_1_0">
<soapenv:Header/>
<soapenv:Body>
<v:DITWSAuthInfoEle>
<v:userID>xxxxxxxxxx</v:userID>
<v:password>xxxxxxxxxx</v:password>
<v:certChain>xxxxxxxxxx</v:certChain>
<v:signature>xxxxxxxxxx</v:signature>
</v:DITWSAuthInfoEle>
</soapenv:Body>
</soapenv:Envelope>

我得到了身份验证详细信息和xyz.pfx文件。通过使用这个文件,我得到了XML签名表示,并将其添加到SOAP请求中。这里我的问题是如何获取certChain(证书链)以及如何将其添加到SOAP请求中。有人能帮我吗?

使用SoapClient,默认情况下会验证服务器证书,您可以发送这样的客户端证书:

$protected_url = "https://my-server/?wsdl";
$my_cert_file = "/my/path/to/mycert.pem";
$client = new SoapClient($protected_url, array('local_cert', $my_cert_file) );

或者,如果您的证书需要密码:

$client = new SoapClient("https://url.to.service/", array(
        'local_cert' => 'client_certificate.pem', 'passphrase' => 'PASSPHRASE',
        'cache_wsdl' => WSDL_CACHE_NONE
));

然后,如果您想查看xml,可以使用__getLastRequest

还可以查看以下关于如何在PHP上使用SOAP和证书的详细答案:

使用证书创建PHP SOAP请求