目前我正在使用 php 和 nusoap,并想将其转换为 Laravel。
创建soap调用时,我使用mysql数据库中的数据。
所以我认为我需要一个模型(来获取我的数据)和一个 Controller (来创建请求)。
编辑:
<?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我找不到有关如何在任何其他请求之前发送登录参数的教程。在“使用添加的服务”示例中,我看到了登录凭据,但它不起作用。
最佳答案
这就是我如何让 SOAP 在 Laravel 5.1 中工作
- 全新安装 Laravel 5.1
- 安装artisaninweb/laravel-soap
创建 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中创建路由
Route::get('/demo', ['as' => 'demo', 'uses' => 'SoapController@demo']);
如果需要,您还可以使用模型扩展,如here所述。
关于mysql - Laravel 5.1 使用 Controller 和模型使用 SOAP wsdl 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33314045/