我正在使用php (yii2),我想实现与服务器的SOAP通信。我有下面的SOAP指南:
客户的系统使用客户的私钥来发出数字签名。应用程序请求(ApplicationRequest)和SOAP消息都必须在WSC中单独签名。签名使用私钥执行。签名系统必须包括签名和证书。此证书包含与签名中使用的私钥相对应的公钥。接收方使用公钥来验证签名。
以及:
下一步:用发件人证书的私钥对整个SOAP消息进行数字签名(分离型XML数字签名),并将签名放入SOAP-头中
所以,我有自己的private.key,public.key和certificate.cer
我的代码看起来像
$client = new SoapClient($wdsl, ['trace' => true]);
$arguments = ['DownloadFileListRequest' => $dflr];
$appResponse = $client->__call('downloadFileList', $arguments);但我得到了预期的错误:
SOAP signature error
我要做什么,怎么签这个肥皂?
发布于 2017-03-12 11:30:41
XMLSecurityDSig帮助(https://github.com/robrichards/xmlseclibs)
$dom = new DOMDocument('1.0', 'UTF-8');
$ar = $dom->createElementNS('http://bxd.fi/xmldata/', 'ApplicationRequest');
$dom->appendChild($ar);
$ar->appendChild($dom->createElement('CustomerId', $this->userID));
...
$ar->appendChild($dom->createElement('Content', $contentBase64));
$objDSig = new XMLSecurityDSig();
$objDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);
$objDSig->addReference(
$dom,
XMLSecurityDSig::SHA256,
['http://www.w3.org/2000/09/xmldsig#enveloped-signature'],
['force_uri' => true]
);
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, ['type'=>'private']);
$objKey->loadKey($this->privateKeyPath, true);
$objDSig->sign($objKey);
$objDSig->add509Cert(base64_encode(file_get_contents($this->certificatePath)), false);
$objDSig->appendSignature($dom->documentElement);
$xmlRaw = $dom->saveXML();https://stackoverflow.com/questions/36773869
复制相似问题