Laravel 5.1 使用控制器和模型消费肥皂 wsdl 服务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33314045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:34:09  来源:igfitidea点击:

Laravel 5.1 consuming soap wsdl service using controller and model

mysqllaravelwsdllaravel-5.1soap-client

提问by davejal

Currently I'm using php and nusoap and wanted to convert it to Laravel.

目前我正在使用 php 和 nusoap 并想将其转换为 Laravel。

When creating the soap calls I use data out of a mysql database.

创建soap调用时,我使用mysql数据库中的数据。

So I think I would need a model (to get my data) and a controller (to create request).

所以我想我需要一个模型(来获取我的数据)和一个控制器(来创建请求)。

EDIT:

编辑:

<?php
namespace App\Http\Controllers;
use Artisaninweb\SoapWrapper\Facades\SoapWrapper;
class SoapController extends Controller {
public function demo()
{
// Add a new service to the wrapper
    SoapWrapper::add(function ($service) {
       $service
       ->name('currency')
       ->wsdl('path/to/wsdl')
       ->trace(true);
       ->options(['user' => 'username', 'pass' => 'password']);
     });

// Using the added service
SoapWrapper::service('currency', function ($service) {
var_dump($service->getFunctions());
var_dump($service->call('Otherfunction'));
});
}
}

from laravel-soapI couldn't find a tutorial on how to send login parameters prior to any other request. In the example 'using the added service' I see the login credentials but it doesn't work.

laravel-soap我找不到关于如何在任何其他请求之前发送登录参数的教程。在“使用添加的服务”示例中,我看到了登录凭据,但它不起作用。

回答by davejal

This is how I got soap to work in Laravel 5.1

这就是我如何让肥皂在 Laravel 5.1 中工作

  1. clean install laravel 5.1
  2. install artisaninweb/laravel-soap
  3. create a controller SoapController.php

    <?php
    namespace App\Http\Controllers;
    use Artisaninweb\SoapWrapper\Facades\SoapWrapper;
    class SoapController extends Controller {
    public function demo()
    {
    // Add a new service to the wrapper
        SoapWrapper::add(function ($service) {
           $service
           ->name('currency')
           ->wsdl('path/to/wsdl')
           ->trace(true);
         });
    $data = [
             'user' => 'username',
             'pass'   => 'password',
            ];
    // Using the added service
    SoapWrapper::service('currency', function ($service) use ($data) {
    
    var_dump($service->call('Login', [$data]));
    var_dump($service->call('Otherfunction'));
    });
    }
    }
    
  4. Create a route in your routes.php

  1. 全新安装 Laravel 5.1
  2. 安装artisaninweb/laravel-soap
  3. 创建一个控制器 SoapController.php

    <?php
    namespace App\Http\Controllers;
    use Artisaninweb\SoapWrapper\Facades\SoapWrapper;
    class SoapController extends Controller {
    public function demo()
    {
    // Add a new service to the wrapper
        SoapWrapper::add(function ($service) {
           $service
           ->name('currency')
           ->wsdl('path/to/wsdl')
           ->trace(true);
         });
    $data = [
             'user' => 'username',
             'pass'   => 'password',
            ];
    // Using the added service
    SoapWrapper::service('currency', function ($service) use ($data) {
    
    var_dump($service->call('Login', [$data]));
    var_dump($service->call('Otherfunction'));
    });
    }
    }
    
  4. 在你的 routes.php 中创建一个路由

Route::get('/demo', ['as' => 'demo', 'uses' => 'SoapController@demo']);

Route::get('/demo', ['as' => 'demo', 'uses' => 'SoapController@demo']);

If requered you can also use the model extension as described here

如果需要,您还可以使用此处描述的模型扩展