Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OTA XML标准:第1列第2行出错:在PHP中获取POST的文档XML末尾有额外内容_Php_Xml_Ota - Fatal编程技术网

OTA XML标准:第1列第2行出错:在PHP中获取POST的文档XML末尾有额外内容

OTA XML标准:第1列第2行出错:在PHP中获取POST的文档XML末尾有额外内容,php,xml,ota,Php,Xml,Ota,我有两天的时间尝试用以下XML代码修复此错误: `<OTA_VehResRQ Version="1.00"> <POS> <Source><RequestorID ID="22" Type="90"></RequestorID></Source> </POS> <BookingReferenceID> <UniqueID_Type

我有两天的时间尝试用以下XML代码修复此错误:

    `<OTA_VehResRQ Version="1.00">
    <POS>
        <Source><RequestorID ID="22" Type="90"></RequestorID></Source>
    </POS>
    <BookingReferenceID>
        <UniqueID_Type ID="338964670"></UniqueID_Type>
    </BookingReferenceID>
    <VehResRQCore>
        <VehRentalCore PickUpDateTime="2017-01-10T10:00:00" ReturnDateTime="2017-01-11T16:00:00">
            <PickUpLocation LocationCode="88" ExtendedLocationCode="CUN01"></PickUpLocation>
            <ReturnLocation LocationCode="89" ExtendedLocationCode="CUN"></ReturnLocation>
        </VehRentalCore>
        <VehPref VendorCarType="MCMR">
            <VehClass>MCMR</VehClass>
            <VehType>Chevrolet Matiz</VehType>
        </VehPref>
        <RateQualifier VendorRateID="90" RateAuthorizationCode="51 || 52" PromotionCode=""/>
        <Customer>
            <Primary>
                <PersonName>
                    <NamePrefix>Mr</NamePrefix>
                    <GivenName>Carlos</GivenName>
                    <Surname>Gomez</Surname>
                </PersonName>
                <Telephone PhoneTechType="001.PTT" PhoneNumber="01 123 4567"></Telephone>
                <Telephone PhoneTechType="005.PTT" PhoneNumber="041 234 5678"></Telephone>
                <Email>
                    <Value>xmlbooking@somedomain.com</Value>
                </Email>
                <Address>
                    <CityName>Cancun</CityName>
                    <StateProv>Quintana Roo</StateProv>
                    <CountryName>New Zealand</CountryName>
                </Address>
            </Primary>
        </Customer>
        <Fees>
            <Fee Description="10% Airport fee" Purpose="049.VCP" Amount=""></Fee>
        </Fees>
        <VehicleCharges Purpose="022.VCP">
            <VehicleCharge CurrencyCode="USD" >
                <Calculation Quantity="4" UnitName="Day" UnitCharge="120" total="480"></Calculation>
                <TaxAmounts>
                    <TaxAmount Description="IVA Tax" TaxCode="IVA" Total=""></TaxAmount>
                </TaxAmounts>
            </VehicleCharge>
        </VehicleCharges>
        <TPA_Extensions>
            <SOE_ExtrasRequest>
                <Extra Code="1" Quantity="1" Amount="26.25" Period="11"></Extra>
                <Extra Code="2" Quantity="1" Amount="37.50" Period="NA"></Extra>
                <Extra Code="3" Quantity="1" Amount="90"    Period="NA"></Extra>
            </SOE_ExtrasRequest>
            <SOE_Comments>
                <Comment Name="optional info 1">
                    <Text>Any other relevant information such as flight no</Text>
                </Comment>
            </SOE_Comments>
        </TPA_Extensions>
    </VehResRQCore>
    <SpecificFlightInfoType>
        <FlightNumber>123</FlightNumber>
        <Airline>British airline</Airline>
    </SpecificFlightInfoType>
</OTA_VehResRQ>
我加载了一个名为:

public function OTA_VehResRQ($XML){
        $Results = array();
        $Results['@attributes'] = array(
            'Version' => '1.00',
            'TimeStamp' => date('c')
        );


        $ctTextLoc = self::CT_TEXTLOC;
        $ctLocations = self::CT_LOCATIONS;
        $ctEstatus = self::CT_ST;


        $RateId = (int)$XML->POS->Source->RequestorID->attributes()->ID;
        $DateIn = (string)$XML->VehResRQCore->VehRentalCore->attributes()->PickUpDateTime;
        $DateOut = (string)$XML->VehResRQCore->VehRentalCore->attributes()->ReturnDateTime;
        $locpu_text = (string)$XML->VehResRQCore->VehRentalCore->PickUpLocation->attributes()->ExtendedLocationCode;
        $locdo_text = (string)$XML->VehResRQCore->VehRentalCore->ReturnLocation->attributes()->ExtendedLocationCode;

        $salutation = (string)$XML->VehResRQCore->Customer->Primary->PersonName->NamePrefix;
        $nombre     = (string)$XML->VehResRQCore->Customer->Primary->PersonName->GivenName;
        $apellidos  = (string)$XML->VehResRQCore->Customer->Primary->PersonName->Surname;
        $email      = (string)$XML->VehResRQCore->Customer->Primary->Email;
        $telefono   = ((string)$XML->VehResRQCore->Customer->Primary->Telephone->attributes()->PhoneTechType == '001.PTT')?(string)$XML->VehResRQCore->Customer->Primary->Telephone->attributes()->PhoneNumber : '';
        $ciudad     = (string)$XML->VehResRQCore->Customer->Primary->Address->CityName;
        $celular    = ((string)$XML->VehResRQCore->Customer->Primary->Telephone->attributes()->PhoneTechType == '005.PTT')?(string)$XML->VehResRQCore->Customer->Primary->Telephone->attributes()->PhoneNumber : '';
        $estado     = (string)$XML->VehResRQCore->Customer->Primary->Address->StateProv;
        $pais       = (string)$XML->VehResRQCore->Customer->Primary->Address->CountryName;

        $datePickup = date("Y-m-d", strtotime($DateIn));
        $dateDropoff = date("Y-m-d", strtotime($DateOut));
        $referencia         = (string)$XML->BookingReferenceID->UniqueID_Type->attributes()->ID;
        $tarifa_grupo       = (string)$XML->VehResRQCore->RateQualifier->attributes()->RateAuthorizationCode;
        $web_flota_acriss   = (string)$XML->VehResRQCore->VehPref->VehClass;
        $web_flota_similar  = (string)$XML->VehResRQCore->VehPref->VehType;
        $loc_pickup         = (int)$XML->VehAvailRQCore->VehRentalCore->PickUpLocation->attributes()->LocationCode;
        $loc_dropoff        = (int)$XML->VehAvailRQCore->VehRentalCore->ReturnLocation->attributes()->LocationCode;
        $loc_pickup_text    = $ctTextLoc["$locpu_text"];
        $loc_dropoff_text   = $ctTextLoc["$locdo_text"];
        $pickup_time_hr     = date("H", strtotime($DateIn));
        $pickup_time_min    = date('i', strtotime($DateIn));
        $dropoff_time_hr    = date("H", strtotime($DateOut));
        $dropoff_time_min   = date('i', strtotime($DateOut));
        $costo_dias         = (int)$XML->VehResRQCore->VehicleCharges->Vehiclecharge->Calculation->attributes()->Unitcharge;
        $costo_semana       = 0;
        $costo_horas        = 0;
        $total_dias         = (int)$XML->VehResRQCore->VehicleCharges->Vehiclecharge->Calculation->attributes()->Quantity;
        $total_semanas      = 0;
        $total_horas        = 0;
        $total_renta        = (int)$XML->VehResRQCore->VehicleCharges->Vehiclecharge->Calculation->attributes()->total;
        $total_extras       = 0;
        $imp_iva            = (int)$XML->VehResRQCore->VehicleCharges->Vehiclecharge->TaxAmounts->TaxAmount->attributes()->Total;
        $imp_aepto          = (float)$XML->VehResRQCore->Fees->Fee->attributes()->Amount;
        $total_total        = "";
        $moneda             = (string)$XML->VehResRQCore->VehicleCharge->attributes()->CurrencyCode;
        $extras             = serialize($XML->VehresRQCore->TPA_Extensions->SOE_ExtrasRequest);
        $st                 = "";
        $flight_number      = (string)$XML->SpecificFlightInfoType->FlightNumber;
        $flight_airline     = (string)$XML->SpecificFlightInfoType->Airline;
        $comments           = (string)$XML->VehresRQCore->TPA_Extensions->SOE_Comments->Comment->text;

        foreach ($XML->VehresRQCore->TPA_Extensions->SOE_ExtrasRequest->attributes()->Amount as $item => $value){
            $total_extras += $value;
        }

        $rInsert = new Reservacion;
        $cInsert = new ReservacionCliente;

        $cInsert->salutation = (string)$salutation;
        $cInsert->nombre = (string)$nombre;
        $cInsert->apellidos = (string)$apellidos;
        $cInsert->email = (string)$email;
        $cInsert->telefono = (string)$telefono;
        $cInsert->celular = (string)$celular;
        $cInsert->ciudad = (string)$ciudad;
        $cInsert->pais = (string)$pais;
        $cInsert->estado = (string)$estado;
        $cInsert->save();

        $ClienteID = $cInsert->cliente_id;

        /*if ($r["total_horas"] > 0) {
            $horas = (int) ($r["total_horas"] / $r["costo_horas"]);
        } else {
            $horas = 0;
        }*/
        $rInsert->referencia = (string)$referencia;
        $rInsert->tarifa_grupo = $tarifa_grupo;
        $rInsert->web_flota_acriss = (string) $web_flota_acriss;
        $rInsert->web_flota_similar = $web_flota_similar;
        $rInsert->web_sitio_id = 5;
        $rInsert->prefijo = "RCC";
        $rInsert->code = self::getNextId('code','web_reservacion',$condicion = array('prefijo'),$parametro = array('RCC') );
        $rInsert->web_cliente_id = $ClienteID;
        $rInsert->fecha = date("Y-m-d H:i:s");
        $rInsert->pickup = $datePickup;
        $rInsert->dropoff = $dateDropoff;
        $rInsert->loc_pickup = $ctLocations[(string) $loc_pickup];
        $rInsert->loc_dropoff = $ctLocations[(string) $loc_dropoff];
        $rInsert->loc_pickup_text = $loc_pickup_text;
        $rInsert->loc_dropoff_text = $loc_dropoff_text;
        $rInsert->pickup_time_hr = $pickup_time_hr;
        $rInsert->dropoff_time_hr = $dropoff_time_hr;
        $rInsert->pickup_time_min = $pickup_time_min;
        $rInsert->dropoff_time_min = $dropoff_time_min;
        $rInsert->costo_dias = $costo_dias;
        $rInsert->costo_semana = $costo_semana;
        $rInsert->costo_horas = $costo_horas;
        $rInsert->total_dias = (int)$total_dias;
        $rInsert->total_semanas = (int) $total_semanas;
        $rInsert->total_horas = (int) $total_horas;
        $rInsert->total_renta = $total_renta;
        $rInsert->total_extras = $total_extras;
        $rInsert->iva = $imp_iva;
        $rInsert->impuesto_aeropuerto = $imp_aepto;
        $rInsert->extras = serialize($extras);
        $rInsert->total = $total_total;
        $rInsert->moneda = $moneda;
        $rInsert->estatus = $ctEstatus[$st];
        $rInsert->flight_number = $flight_number;
        $rInsert->flight_airline = $flight_airline;
        $rInsert->dominio = "Rental Cars";
        $rInsert->agente_callcenter = 0;
        $rInsert->comments = $comments;

        if((string)$XML->VehResRQCore->VehicleCharges->attributes()->Purpose == '022.VCP'){
            $rInsert->pagada = 1;
            $rInsert->pago_fecha = date("Y-m-d H:i:s");
            $rInsert->pago_detalle = $total_renta;
            $rInsert->pago_observacion = 'Prepago de la renta, pendiente los adicionales';
        }

        if (!$rInsert->save()) {
            $Results['Success'] = 'false';
            $Results['VehResRSCore']['@attributes'] = array(
                'ReservationStatus' => 'Not Committed'
            );
        } else {
            $Results['Success'] = 'true';
            $Results['VehResRSCore']['@attributes'] = array(
                'ReservationStatus' => 'Committed'
            );
            $Results['VehResRSCore']['VehReservation']['VehSegmentCore']['ConfID']['@attributes'] = array(
                'Type' => '014.UIT',
                'ID'   => 'RCC-' . $rInsert->code
            );
        }

        $xml = Array2XML::createXML('OTA_VehResRS', $Results);
        echo str_replace("\n", "", (trim($xml->saveXML())));
    }
这很奇怪,因为使用另一个XML脚本可以很好地执行:

`<OTA_VehLocSearchRQ Version="1.00">
    <POS>
        <Source>`enter code here`
            <RequestorID ID="22"></RequestorID>
        </Source>
    </POS>
</OTA_VehLocSearchRQ>`
有人可以给我提示,我已经研究过了,但我什么也找不到


非常感谢。

我发现了错误,问题是“foreach”我没有很好地迭代数组

foreach($XML->VehResRQCore->Customer->Primary->Telephone as$Telephone){ 交换机((字符串)$phone['PhoneTechType']){//Obtener los atributos comoíndices del elemento 案例“001.PTT”: $telefono=$Telephone['PhoneNumber']; 打破 案例“005.PTT”: $celular=$Telephone['PhoneNumber']; 打破 } }

要序列化附加项,请执行以下操作:

foreach($XML->xpath('//Extra')作为$Extras){ 数组推送($extras,(string)$extras['Code'],(string)$extras['Amount'],(string)$extras['observations']); }

这是我第一次使用XML。。。不管怎样,我明白了!
如果对另一个问题有帮助,我会回答我的问题

我发现了错误,问题是“foreach”我没有很好地迭代数组

foreach($XML->VehResRQCore->Customer->Primary->Telephone as$Telephone){ 交换机((字符串)$phone['PhoneTechType']){//Obtener los atributos comoíndices del elemento 案例“001.PTT”: $telefono=$Telephone['PhoneNumber']; 打破 案例“005.PTT”: $celular=$Telephone['PhoneNumber']; 打破 } }

要序列化附加项,请执行以下操作:

foreach($XML->xpath('//Extra')作为$Extras){ 数组推送($extras,(string)$extras['Code'],(string)$extras['Amount'],(string)$extras['observations']); }

这是我第一次使用XML。。。不管怎样,我明白了! 如果对另一个问题有帮助,我会回答我的问题

`<OTA_VehLocSearchRQ Version="1.00">
    <POS>
        <Source>`enter code here`
            <RequestorID ID="22"></RequestorID>
        </Source>
    </POS>
</OTA_VehLocSearchRQ>`
public function OTA_VehLocSearchRQ($XML)
    {
        $Results = array();
        $Results['@attributes'] = array(
            'Version' => '1.00',
            'TimeStamp' => date('c')
        );

        if ($XML->POS->Source->RequestorID->attributes()->ID == 22) { // Sistema 22 = Rental Cars
            $XML->POS->Source->RequestorID->attributes()->ID = 16; //Proveedor 16 = Rental Cars
        }

        if (isset($XML->VehLocSearchCriterion)) {
            $Results["Success"] = true;
            $Results["VehMatchedLocs"] = array();

            $Locaciones = Yii::app()->db->createCommand()
                ->select('*, c.Name as Pais, c.Code2 as Country2L')
                ->from('cr_locaciones')
                ->join("Country c", "c.Code = locacion_pais")
                ->join("City", "ID = locacion_ciudad")
                ->where("locacion_proveedor = :proveedor AND locacion_id = :codigo", array(":proveedor" => (string)$XML->POS->Source->RequestorID->attributes()->ID, ":codigo" => $XML->VehLocSearchCriterion->RefPoint))
                ->queryAll();
        } else {
            $Results["Success"] = true;
            $Results["VehMatchedLocs"] = array();

            $Locaciones = Yii::app()->db->createCommand()
                ->select('*, c.Name as Pais, c.Code2 as Country2L')
                ->from('cr_locaciones')
                ->join("Country c", "c.Code = locacion_pais")
                ->join("City", "ID = locacion_ciudad")
                ->where("locacion_proveedor = :proveedor", array(":proveedor" => $XML->POS->Source->RequestorID->attributes()->ID))
                ->queryAll();


        }

        if (sizeof($Locaciones) > 0) {
            $Results["VehMatchedLocs"]["VehMatchedLoc"] = array();


            foreach ($Locaciones as $l) {
                $lInfo = array(
                    "LocationDetail" => array(
                        "@attributes" => array(
                            "Code" => $l["locacion_id"],
                            "Name" => $l["locacion_nombre_en"],
                            "AtAirport" => (($l["locacion_tipo"] == 2) ? true : false),
                            "CodeContext" => "PickupLocation",

                        ),
                        "Address" => array(
                            "AddressLine" => utf8_encode($l["locacion_direccion_linea_1"]),
                            "CityName" => utf8_encode($l["Name"]),
                            "PostalCode" => $l["locacion_cp"],
                            "CountryName" => array(
                                "@attributes" => array("Code" => $l["Country2L"]),
                                "@value" => $l["Pais"],
                            ),
                        ),
                        "Telephone" => array(
                            "@attributes" => array(
                                "PhoneNumber" => $l["locacion_telefono"],
                                "FormattedInd" => false,
                            ),
                        ),
                    )
                );

                array_push($Results["VehMatchedLocs"]["VehMatchedLoc"], $lInfo);
            }

        } else {
            $Results["Success"] = false;
        }


        $xml = Array2XML::createXML('OTA_VehLocSearchRS', $Results);
        echo str_replace("\n", "", (trim($xml->saveXML())));
    }