使用 Php soapClient 的 Travelport uAPI

Travelport uAPI using Php soapClient

使用 php soapClient 访问 Travelport uAPI 时出现问题。

能够使用 Curl 取回数据,但无法使用 Air.wsdl 文件访问 Travelport。

目前使用的是 2015 年 7 月 1 日发布的最新 Air.wsdl 文件。

有人有关于如何完成的工作示例吗?

TravelportProvider:


namespace Providers;

use Providers\Clients\SoapClient;

class TravelportProvider extends SoapClient
{

    public function __construct() {
        parent::__construct(config('travelport.airWsdl'), config('travelport.endpoint'));
    }

    public function search()
    {
        return $this->service();
    }


    public function service() {

        $parameters = array(
            'BillingPointOfSaleInfo' => array(
                'OriginApplication' => 'UAPI'
            ),
            'AirPricingSolution' => array(
                'Key' => 1
            ),
            'legs' => array(
                'Key' => 1,
                'Group' => 1,
                'Origin' => 'BNE',
                'Destination' => 'SYD',
                'departureDate' => '2015-07-23',
                'cabinClass' => 'Economy',
                'validationPassed:protected' => '1',
                'validationErrors:protected' => ''
            )
        );
        $response = $this->__soapCall('service', array($parameters));
        return $response;
    }
}

SoapClient:


namespace Providers\Clients;


abstract class SoapClient extends \SoapClient
{
    /**
     * Configuration Array
     *
     * @var array
     */
    protected $config = null;

    /**
     * Options Array
     *
     * @var array
     */
    protected $options = null;

    public function __construct($wsdl, $endpoint, $options = null) {

        // Set Soap Config
        $this->setConfig($wsdl, $endpoint);

        // Set Soap Context
        $this->setContext();

        // Create Classmap Array
//        $this->setClassmap();

        // Set Soap options
        $this->setOptions($this->config, $this->context);

        // Set the WSDL endpoint
        $this->__setLocation($endpoint);

        // Create the SoapClient
        parent::__construct($wsdl, $this->options);
    }

    /**
     * Set Soap Config
     *
     * @param string $wsdl
     * @param string $endpoint
     * @return array $config
     */
    protected function setConfig($wsdl, $endpoint) {
        // Check WSDL
        if ($wsdl == null) {
            throw new \SoapException("WSDL cannot be null");
        }

        // Credentials
        $this->config = array(
            'username' => config('travelport.username'),
            'password' => config('travelport.password'),
            'credentials' => config('travelport.credentials'),
            'wsdl' => $wsdl,
            'endpoint' => $endpoint
        );

        // Setting config
        return $this->config;
    }

    /**
     * Set Soap Context
     *
     * @return array $context
     */
    protected function setContext() {
        $this->context = array(
            'http' => array(
                'header' => array(
                    'Content-Type: text / xml; charset = UTF-8',
                    'Accept-Encoding: gzip, deflate',
                    'SOAPAction: ""'
                )),
            'ssl' => array(
                'ciphers' => 'RC4-SHA'
            )
        );
        return $this->context;
    }

    /**
     * Set Soap Options
     *
     * @param array $config
     * @param array $context
     * @return array $options
     */
    protected function setOptions($config, $context)
    {
        $this->options = array(
            'soap_version' => 'SOAP_1_1',
            'encoding' => 'UTF-8',
            'exceptions' => true,
            'stream_context' => stream_context_create($context),
            'trace' => true,
            'login' => $config['username'],
            'password' => $config['password']
        );

        // Setting options
        return $this->options;
    }
}

我发现有趣的是最新的 Air.wsdl 文件具有相同的操作名称 "service" 和相同的 input/output 名称。我要搜索 LowFareSearch,如何选择目标?

我做了一个 $this->__getfunction() 并且得到了以下结果


Array
(
    [0] => AirRepriceRsp service(AirRepriceReq $parameters)
    [1] => ScheduleSearchRsp service(ScheduleSearchReq $parameters)
    [2] => LowFareSearchRsp service(LowFareSearchReq $parameters)
    [3] => LowFareSearchAsynchRsp service(LowFareSearchAsynchReq $parameters)
    [4] => RetrieveLowFareSearchRsp service(RetrieveLowFareSearchReq $parameters)
    [5] => AirPriceRsp service(AirPriceReq $parameters)
    [6] => AirFareRulesRsp service(AirFareRulesReq $parameters)
    [7] => AvailabilitySearchRsp service(AvailabilitySearchReq $parameters)
    [8] => AirFareDisplayRsp service(AirFareDisplayReq $parameters)
    [9] => SeatMapRsp service(SeatMapReq $parameters)
    [10] => AirRefundQuoteRsp service(AirRefundQuoteReq $parameters)
    [11] => AirRefundRsp service(AirRefundReq $parameters)
    [12] => AirTicketingRsp service(AirTicketingReq $parameters)
    [13] => AirVoidDocumentRsp service(AirVoidDocumentReq $parameters)
    [14] => AirRetrieveDocumentRsp service(AirRetrieveDocumentReq $parameters)
    [15] => AirExchangeRsp service(AirExchangeReq $parameters)
    [16] => AirExchangeQuoteRsp service(AirExchangeQuoteReq $parameters)
    [17] => AirExchangeTicketingRsp service(AirExchangeTicketingReq $parameters)
    [18] => AirMerchandisingOfferAvailabilityRsp service(AirMerchandisingOfferAvailabilityReq $parameters)
    [19] => AirUpsellSearchRsp service(AirUpsellSearchReq $parameters)
    [20] => FlightTimeTableRsp service(FlightTimeTableReq $parameters)
    [21] => AirPrePayRsp service(AirPrePayReq $parameters)
    [22] => EMDRetrieveRsp service(EMDRetrieveReq $parameters)
    [23] => EMDIssuanceRsp service(EMDIssuanceReq $parameters)
    [24] => AirMerchandisingDetailsRsp service(AirMerchandisingDetailsReq $parameters)
    [25] => FlightInformationRsp service(FlightInformationReq $parameters)
    [26] => FlightDetailsRsp service(FlightDetailsReq $parameters)
)

如果你想使用WSDL,你必须复制原始的WSDL文件并在其中放入一个服务的描述。为每个所需的服务执行此操作。 因此,如果您需要两个 Air.wsdl 服务,您将拥有两个单独的 WSDL 文件。 AirMerchandisingOfferAvailabilityRsp 示例:

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="AirService"
             xmlns="http://schemas.xmlsoap.org/wsdl/"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:tns="http://www.travelport.com/service/air_v32_0"
             xmlns:ns1="http://www.travelport.com/schema/air_v32_0"
             targetNamespace="http://www.travelport.com/service/air_v32_0">

    <import namespace="http://www.travelport.com/service/air_v32_0"
          location="AirAbstract.wsdl" />
    <binding name="AirMerchandisingOfferAvailabilityBinding" type="tns:AirMerchandisingOfferAvailabilityPortType">
        <soap:binding style="document"
                      transport="http://schemas.xmlsoap.org/soap/http" />
        <operation name="service">
            <soap:operation soapAction="http://localhost:8080/kestrel/AirService"/>
            <input>
                <soap:body use="literal" />
            </input>
            <output>
                <soap:body use="literal" />
            </output>
            <fault name="ErrorInfoMsg">
                <soap:fault name="ErrorInfoMsg" use="literal" />
            </fault>
        </operation>
    </binding>
    <!-- Service -->
    <service name="AirService">
        <port name="AirMerchandisingOfferAvailabilityPort"
              binding="tns:AirMerchandisingOfferAvailabilityBinding">
            <soap:address
                 location="http://localhost:8080/kestrel/AirService" />
        </port>
    </service>
</definitions>

我这样做了