radomirradojevic / yii2-wss-soap
为默认 SoapClient 提供的 Yii2 包装器
1.0
2019-05-16 16:24 UTC
Requires
- ext-soap: *
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-09-29 05:09:27 UTC
README
此扩展是 PHP 中默认 SoapClient 的包装器。
安装
安装此扩展的最佳方式是通过 composer。
运行以下命令之一:
composer require radomirradojevic/yii2-wss-soap "1.0"
或者
"radomirradojevic/yii2-wss-soap": "1.0"
将以下内容添加到 composer.json 的 require 部分中。
使用方法
您需要在配置文件的 'components' 部分中添加此扩展
'components' => [ 'soapClient' => [ 'class' => \radomirradojevic\soap\SoapClientWrapper::className(), 'url' => '<SOAP_WSDL_URL>', // SoapClient options 'options' => [ 'cache_wsdl' => WSDL_CACHE_NONE, 'debug' => true, ], // SopaClient headers, object or closure 'headers' => function() { $headers = new stdClass(); $headers->authDetails = new stdClass(); // This is node in SOAP Header where the login and password. $headers->authDetails->wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'; $headers->authDetails->login = '<LOGIN>'; $headers->authDetails->password = '<PASSWORD>'; return $headers; } ], ... ]
现在您可以使用此扩展,例如:
try { $soap = Yii::$app->soapClient; $result = $soap->makeSmb(['arg1' => 'foo', 'arg2' => 'bar']); } catch (SoapClientWrapperException $e) { return ['request' => $soap->getLastRequest(), 'response' => $soap->getLastResponse()]; }