为Soap Request php创建参数数组

时间:2019-02-13 08:04:14

标签: php xml soap

我想创建一个soap请求,我有xml请求示例,但是我创建的数组结构错误。

应为我的数组的示例应为:

<soap:Envelope xmlns:xsi="XMLSchema-instance" xmlns:xsd="XMLSchema" xmlns:soap="envelope">
  <soap:Header>
    <AuthenticationSoapHeader xmlns="http://example.com/ws">
      <WSUserName>USERNAME</WSUserName>
      <WSPassword>PASSWORD</WSPassword>
    </AuthenticationSoapHeader>
  </soap:Header>
  <soap:Body>
    <SearchFlight xmlns="http://example.com/ws">
      <OTA_AirLowFareSearchRQ ProviderType="OnlyAmadeus" RefundableType="OnlyRefundable" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="0">
        <OriginDestinationInformation>
          <DepartureDateTime>2019-02-03T00:01:00</DepartureDateTime>
          <OriginLocation LocationCode="FRA" />
          <DestinationLocation LocationCode="AMS" />
        </OriginDestinationInformation>

        <TravelerInfoSummary>
          <AirTravelerAvail>
            <PassengerTypeQuantity Code="ADT" />
          </AirTravelerAvail>
        </TravelerInfoSummary>
      </OTA_AirLowFareSearchRQ>
    </SearchFlight>
  </soap:Body>
</soap:Envelope>

我尝试了以下操作:

$client = new SoapClient($soapURL,array("trace"=>1));
$auth = array(
    'WSUserName' => 'USERNAME',
    'WSPassword' => 'PASSWORD'
);
$header = new SoapHeader($location,'authentification',$auth,false);
$client->__setSoapHeaders($header);
$params = array(
    'OTA_AirLowFareSearchRQ' => array(
        '_' => array(
            'OriginDestinationInformation' => array(
                'DepartureDateTime' => '2019-02-25T00:01:00',
                'OriginLocation' => array(
                    '_' => '',
                    'LocationCode' => 'FRA'
                ),
                'DestinationLocation' => array(
                    '_' => '',
                    'LocationCode' => 'AMS'
                )
            ),
            'TravelerInfoSummary' => array(
                'AirTravelerAvail' => array(
                    'PassengerTypeQuantity' => array(
                        '_' => '',
                        'Code' => 'ADT'
                    )
                )
            )
        ),
        'ProviderType' => 'OnlyAmadeus',
        'RefundableType' => 'AllFlights'
    )
);
$searchResponse = $client->__soapCall("SearchFlight", array($params));
var_dump($client->__getLastRequest());

但是我得到了以下错误信息:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://example.com/ws" xmlns:ns2="http://example.com/ws">
    <SOAP-ENV:Header>
        <ns2:authentification>
            <item>
                <key>WSUserName</key><value>USERNAME</value>
            </item>
            <item>
                <key>WSPassword</key><value>PASSWORD</value>
            </item>
        </ns2:authentification>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <ns1:SearchFlight>
            <ns1:OTA_AirLowFareSearchRQ RefundableType="AllFlights" ProviderType="OnlyAmadeus"/>
        </ns1:SearchFlight>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我如何使它工作,请考虑示例中的标头身份验证

0 个答案:

没有答案