Laravel 5.1 使用控制器和模型使用 soap wsdl 服务

Laravel 5.1 consuming soap wsdl service using controller and model

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

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

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

编辑:

<?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'));
});
}
}

来自 laravel-soap 我找不到有关如何在任何其他请求之前发送登录参数的教程。在示例中 'using the added service' 我看到了登录凭据,但它不起作用。

这就是我在 Laravel 5.1

中使用肥皂的方式
  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

  5. 中创建一条路线

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

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