Laravel SoapClient

来源:互联网 发布:每周eia数据时间 编辑:程序博客网 时间:2024/06/06 14:43

Add artisaninweb/laravel-soap as requirement to composer.json

{    "require": {        "artisaninweb/laravel-soap": "0.2.*"    }}

 "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.1.*",
"artisaninweb/laravel-soap": "0.2.*",
        "overtrue/laravel-lang": "dev-master"
 },


Add the service provider in app/config/app.php.

'Artisaninweb\SoapWrapper\ServiceProvider'

To use the facade add this to the facades in app/config/app.php.

'SoapWrapper' => 'Artisaninweb\SoapWrapper\Facades\SoapWrapper'

执行 composer update


<?phpuse Artisaninweb\SoapWrapper\Facades\SoapWrapper;class SoapController {    public function demo()    {        // Add a new service to the wrapper        SoapWrapper::add(function ($service) {            $service                ->name('currency')                ->wsdl('http://currencyconverter.kowabunga.net/converter.asmx?WSDL')                ->trace(true)                                                   // Optional: (parameter: true/false)                ->header()                                                      // Optional: (parameters: $namespace,$name,$data,$mustunderstand,$actor)                ->customHeader($customHeader)                                   // Optional: (parameters: $customerHeader) Use this to add a custom SoapHeader or extended class                                ->cookie()                                                      // Optional: (parameters: $name,$value)                ->location()                                                    // Optional: (parameter: $location)                ->certificate()                                                 // Optional: (parameter: $certLocation)                ->cache(WSDL_CACHE_NONE)                                        // Optional: Set the WSDL cache                ->options(['login' => 'username', 'password' => 'password']);   // Optional: Set some extra options        });        $data = [            'CurrencyFrom' => 'USD',            'CurrencyTo'   => 'EUR',            'RateDate'     => '2014-06-05',            'Amount'       => '1000'        ];        // Using the added service        SoapWrapper::service('currency', function ($service) use ($data) {            var_dump($service->getFunctions());            var_dump($service->call('GetConversionAmount', [$data])->GetConversionAmountResult);        });    }}





0 0
原创粉丝点击