Этот пример является собственным проектом, который находится в производстве.Я надеюсь, что смогу вам помочь.
$context = stream_context_create([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'local_cert' => LOCAL_CERT,
'passphrase' => PRIVATE_KEY_PASSPHRASE
]
]);
$client = new BinarySignedSoapClient($wsdl , ['trace' => 1, 'stream_context' => $context]);
Позвоните:
class BinarySignedSoapClient extends \SoapClient
{
function __construct($wsdl, $context, $params) {
$this->crt_cert_file = array_key_exists('crt_cert_file', $params) ? $params['crt_cert_file'] : null;
$this->private_key_passphrase = array_key_exists('private_key_passphrase', $params) ? $params['private_key_passphrase'] : null;
$this->private_key_file = array_key_exists('private_key_file', $params) ? $params['private_key_file'] : null;
parent::__construct($wsdl, $context);
}
public function __doRequest($request, $location, $saction, $version, $one_way = 0)
{
$doc = new \DOMDocument('1.0');
$doc->loadXML($request);
$objWSSE = new \WSSESoap($doc);
/* add Timestamp with no expiration timestamp */
$objWSSE->addTimestamp();
/* create new XMLSec Key using RSA_SHA1 and type is private key */
$objKey = new \XMLSecurityKey(\XMLSecurityKey::RSA_SHA1, ['type' => 'private']);
/* load the private key from file - last arg is bool if key in file (true) or is string (false) */
$objKey->passphrase = $this->private_key_passphrase;
$objKey->loadKey(__DIR__ ."/../localssl/". $this->private_key_file, true, false);
/* Sign the message - also signs appropiate WS-Security items */
$options = array("insertBefore" => false);
$objWSSE->signSoapDoc($objKey, $options);
/* Add certificate (BinarySecurityToken) to the message */
$token = $objWSSE->addBinaryToken(file_get_contents(__DIR__ ."/../localssl/". $this->crt_cert_file));
/* Attach pointer to Signature */
$objWSSE->attachTokentoSig($token);
$retVal = parent::__doRequest($objWSSE->saveXML(), $location, $saction, $version);
$doc = new \DOMDocument();
$doc->loadXML($retVal);
$options = ["keys" => ["private" => ["key" => __DIR__ . $this->private_key_file, "isFile" => true, "isCert" => false]]];
$objWSSE->decryptSoapDoc($doc, $options);
return $doc->saveXML();
}
}