raigu/x-road-soap-envelope-builder

用于生成 X-Road SOAP 封装的 PHP 库。

v2.0.0 2023-05-28 08:03 UTC

This package is auto-updated.

Last update: 2024-08-28 10:54:39 UTC


README

Latest Stable Version License: MIT Build Status codecov Scrutinizer

x-road-soap-envelope-builder

用于生成 X-Road 请求 SOAP 封装的 PHP 库。

要求

  • php ^8.0
  • DOM 扩展

(对于 PHP ^PHP7.2 使用版本 1.1.1)

安装

$ composer require raigu/x-road-soap-envelope-builder

用法

为 X-Road 请求构建 SOAP 封装

$builder = \Raigu\XRoad\SoapEnvelope\SoapEnvelopeBuilder::create()
    ->withService('EE/GOV/70008440/rr/RR437/v1')
    ->withClient('EE/COM/12213008/gathering')
    ->withBody(<<<EOD
        <prod:RR437 xmlns:prod="http://rr.x-road.eu/producer">
            <request>
                <Isikukood>00000000000</Isikukood>
            </request>
        </prod:RR437>
EOD;
    );

$envelope = $builder->build();

echo $envelope;

方法的 withBody 输入参数可以通过使用像 WSDL AnalyzerSOAP UI 这样的免费工具从 WSDL 生成。WSDL 可以在 X-Road 目录 中找到。

查看简短(1:34)演示视频,了解如何获取 WSDL 和生成请求体 视频

构建器方法

制作 X-Road 请求

在以下示例中,将您的 X-Road 安全服务器 URL 分配给 $securityServerUrl

使用 Guzzle

$client = new \Guzzle\Http\Client();
$request = $client->post(
    $securityServerUrl,
    [ 
        'Content-Type' => 'text/xml',
        'SOAPAction' => ''
    ],
    $envelope
);

$response = $client->send($request);

echo $response->getBody();

使用 curl

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $securityServerUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $envelope);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Content-Type' => 'text/xml',
        'SOAPAction' => ''
    ]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$output = curl_exec($ch);

curl_close($ch);

echo $output;

参考