2

我从供应商 API 获得以下信息: 在此处输入图像描述

我需要使用 php 创建一个 Soap 调用。我该怎么做呢?到目前为止,我有这个:但它不起作用:

private function booking_soap_connect() {
        // the wsdl URL of your service to test 
        $serviceWsdl = 'https://apitest.com/bookingapi.asmx?WSDL';

        // the parmeters to initialize the client with 
        $serviceParams = array(
            'login' => 'un',
            'password' => 'pw'
        );

        // create the SOAP client 
        $client = new SoapClient($serviceWsdl, $serviceParams);

        $data['Brand'] = "All";
        $data['TourCode'] = "QBE";
        $data['DepartureCode'] = "8000321";
        $data['VendorId'] = "test";
        $data['VendorPassword'] = "test";

        $results = $client->GVI_DepartureInfo($data)
        echo $results;
    }

请帮忙

4

3 回答 3

12

已解决:我终于用以下代码实现了这一点:

class WsseAuthHeader extends SoapHeader {

    private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';

    function __construct($user, $pass, $ns = null) {
        if ($ns) {
            $this->wss_ns = $ns;
        }

        $auth = new stdClass();
        $auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
        $auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);

        $username_token = new stdClass();
        $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);

        $security_sv = new SoapVar(
                new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns), SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
        parent::__construct($this->wss_ns, 'Security', $security_sv, true);
    }

}

$username = 'test';
$password = 'test123';
$wsdl = 'https://yoururl.com/api.asmx?WSDL';

$wsse_header = new WsseAuthHeader($username, $password);

$client = new SoapClient($wsdl, array(
    //"trace" => 1,
    //"exceptions" => 0
        )
);

$client->__setSoapHeaders(array($wsse_header));


$request = array(
    "functionResponseName" => array(
        'param1' => "string",
        "param2" => "string"
    )
);

$results = $client->FunctionName($request);

var_dump($results);
于 2014-03-13T20:40:05.707 回答
-1

看看我之前在Send XML with php via post上的回答。应该有在 php 中处理 SOAP 所需的一切。

于 2014-03-12T19:01:43.643 回答
-1

使用 Nusoap 代替您的 Soap 客户端可能不适用于您的 php 版本。

于 2014-03-12T18:58:07.860 回答