Laravel 5.1使用控制器和模型消耗Soap wsdl服务 [英] Laravel 5.1 consuming soap wsdl service using controller and model
问题描述
目前,我正在使用php和nusoap,并希望将其转换为Laravel.
Currently I'm using php and nusoap and wanted to convert it to Laravel.
在创建Soap调用时,我使用mysql数据库中的数据.
When creating the soap calls I use data out of a mysql database.
所以我认为我需要一个模型(获取我的数据)和一个控制器(创建请求).
So I think I would need a model (to get my data) and a controller (to create request).
<?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 ,我找不到有关如何先发送登录参数的教程其他任何要求.在示例使用添加的服务"中,我看到了登录凭据,但是它不起作用.
from laravel-soap I 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 5.1中使用肥皂
This is how I got soap to work in Laravel 5.1
- 全新安装laravel 5.1
- 安装 artisaninweb/laravel-soap
-
创建一个控制器SoapController.php
- clean install laravel 5.1
- install artisaninweb/laravel-soap
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'));
});
}
}
在routes.php中创建一条路由
Create a route in your routes.php
Route::get('/demo', ['as' => 'demo', 'uses' => 'SoapController@demo']);
如果需要,您还可以按照中所述使用模型扩展这里
这篇关于Laravel 5.1使用控制器和模型消耗Soap wsdl服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!