paycore / xmldsig
根据UOC规则签名的XML请求库
v0.0.2
2019-05-27 11:00 UTC
Requires
- php: >=7.1
Suggests
- ext-openssl: The OpenSsl Extension
This package is auto-updated.
Last update: 2024-09-09 13:58:43 UTC
README
它是 https://github.com/greenter/xmldsig 的分支,对UPC的签名请求做了少量修改。
XmlDSig - Greenter
此库用于根据UPC规则签名请求。
需要 .PEM 证书,您可以使用以下示例将 .PFX 证书转换为所需的格式。
安装
从 packagist 使用Composer进行安装。
composer require paycore/xmldsig
示例
use Greenter\XMLSecLibs\Sunat\SignedXml; require 'vendor/autoload.php'; $xmlData = file_get_contents('path-dir/20600995805-01-F001-1.xml'); $certPath = 'path-dir/SFSCert.pem'; // Convertir pfx to pem $signer = new SignedXml(); $signer->setCertificateFromFile($certPath); // You can also use $signer->setCertificate ($certData); $xmlSigned = $signer->signXml($xmlData); header('Content-Type: text/xml'); echo $xmlSigned;
结果
之前
<ext:UBLExtensions> <ext:UBLExtension> <ext:ExtensionContent></ext:ExtensionContent> </ext:UBLExtension> </ext:UBLExtensions>
之后
<ext:UBLExtensions> <ext:UBLExtension> <ext:ExtensionContent> <ds:Signature Id="SignIMM"> <ds:SignedInfo> <ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/> <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/> <ds:Reference URI=""> <ds:Transforms> <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/> </ds:Transforms> <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> <ds:DigestValue>IwJuNQGQaHmmm3iv2jj8JDv70Ow=</ds:DigestValue> </ds:Reference> </ds:SignedInfo> <ds:SignatureValue> nLaghokzMNrmrfPnbIg9b........wzZ2CgLTVjWQUAQ4wDAYDVQQIEwVNYWluZTE1UiLFwZXXXPUlf2o= </ds:SignatureValue> <ds:KeyInfo> <ds:X509Data> <ds:X509Certificate> MIIFhzCCA3OgAwI......MIIEVDCCAzygAwIBAgIJAPTrkMJbCOr1MA0GCSqGSIb3DQEBBQUAMHkxCzAJBgNVBAYTAlVTVQQIEwVNYWluZTEgMOiRJ00nE= </ds:X509Certificate> </ds:X509Data> </ds:KeyInfo> </ds:Signature> </ext:ExtensionContent> </ext:UBLExtension> </ext:UBLExtensions>