예제 #1
0
        public string ToXMLString()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";

            xml += "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><Request xmlns=\"http://ctrip.com/\"><requestXML>";
            xml += "<![CDATA[<Request>";
            string head    = RequestXmlWrapper.ToXml(this.Header);
            string body    = "<HotelRequest><RequestBody xmlns:ns=\"http://www.opentravel.org/OTA/2003/05\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
            string content = RequestXmlWrapper.ToXml(this.RequestBody);

            if (this.RequestBody.GetType() != typeof(HotelDescriptiveRequest) && this.RequestBody.GetType() != typeof(D_HotelOrderMiniInfoRequest) && this.RequestBody.GetType() != typeof(D_GetCtripOrderIDRequest))
            {
                content = content.Replace("<", "<ns:").Replace("<ns:/", "</ns:");
            }
            content = content.Replace("\"True\"", "\"true\"").Replace("\"False\"", "\"false\"");
            body   += content;
            body   += "</RequestBody></HotelRequest>";
            if (this.RequestBody.GetType() == typeof(D_HotelOrderMiniInfoRequest) || this.RequestBody.GetType() == typeof(D_GetCtripOrderIDRequest))
            {
                body = content;
            }
            xml += (head + body);
            xml += "</Request>]]></requestXML></Request></soap:Body></soap:Envelope>";
            return(xml);
        }
예제 #2
0
        /// <summary>
        /// 提交订单
        /// </summary>
        /// <param name="corder"></param>
        /// <returns></returns>
        public ZXcResponse SubmitOrderV(XZorder corder)
        {
            ZXcResponse resp      = new ZXcResponse();
            LogWriter   logWriter = new LogWriter("Ctrip/CreateOrder");

            try
            {
                Guid gid = Guid.NewGuid();
                if (string.IsNullOrEmpty(corder.ratePlanCategory))
                {
                    corder.ratePlanCategory = "501";
                }
                string ratePlanCategory = corder.ratePlanCategory;

                HotelResSaveRequest req = new HotelResSaveRequest(Config);
                //默认是国际的账号,
                req.OTA_HotelResSaveRQ.UniqueIDList.Find(c => c.Type == "28").ID  = Config.AllianceID;
                req.OTA_HotelResSaveRQ.UniqueIDList.Find(c => c.Type == "503").ID = Config.SID;
                req.OTA_HotelResSaveRQ.UniqueIDList.Find(c => c.Type == "1").ID   = Config.UID;
                req.OTA_HotelResSaveRQ.UniqueIDList.Find(c => c.Type == "504").ID = corder.orderNo;

                Ctrip.Request.HotelReservation info = new Ctrip.Request.HotelReservation();
                RoomStay room = new RoomStay();
                room.HotelCode = corder.hotelCode;
                room.RoomTypes.NumberOfUnits = corder.roomNum;

                room.RatePlans.RatePlanCode     = corder.ratePlanCode;
                room.RatePlans.RatePlanCategory = ratePlanCategory;
                info.RoomStays.RoomStayList.Add(room);
                ResGuest guest = new ResGuest();
                foreach (var item in corder.guestNames)
                {
                    PersonName name = new PersonName()
                    {
                        Surname = item
                    };
                    guest.Profiles.ProfileInfo.Profile.Customer.PersonNameList.Add(name);
                }
                ContactPerson per = new ContactPerson();
                per.PersonName = new PersonName()
                {
                    Surname = corder.contactName
                };
                per.Email       = "*****@*****.**";
                per.PhoneNumber = "13250771589";
                per.ContactType = "email";
                guest.Profiles.ProfileInfo.Profile.Customer.ContactPerson = per;
                if (!string.IsNullOrEmpty(corder.lateArriveTime))
                {
                    string[] arr = corder.lateArriveTime.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                    if (arr.Length == 2)
                    {
                        int hour = 0;
                        int.TryParse(arr[0], out hour);
                        if (hour < 6)
                        {
                            guest.TPA_Extensions.LateArrivalTime = corder.comeDate.Date.AddDays(1).ToString("yyyy-MM-dd") + "T" + corder.lateArriveTime + ":00+08:00";
                        }
                        else
                        {
                            guest.TPA_Extensions.LateArrivalTime = corder.comeDate.Date.ToString("yyyy-MM-dd") + "T" + corder.lateArriveTime + ":00+08:00";
                        }
                    }
                }
                if (string.IsNullOrEmpty(guest.TPA_Extensions.LateArrivalTime))
                {
                    if (corder.comeDate.Date.Date < DateTime.Now.Date && DateTime.Now.Hour < 6)
                    {
                        guest.TPA_Extensions.LateArrivalTime = DateTime.Now.AddMinutes(30).ToString("yyyy-MM-ddTHH:mm:00+08:00");
                    }
                    else
                    {
                        guest.TPA_Extensions.LateArrivalTime = corder.comeDate.Date.ToString("yyyy-MM-dd") + "T23:30:00+08:00";
                    }
                }
                if (Convert.ToDateTime(guest.TPA_Extensions.LateArrivalTime) < DateTime.Now)
                {
                    if (DateTime.Now.Hour < 6)
                    {
                        guest.TPA_Extensions.LateArrivalTime = DateTime.Now.ToString("yyyy-MM-ddT03:00:00+08:00");
                    }
                    else
                    {
                        guest.TPA_Extensions.LateArrivalTime = DateTime.Now.ToString("yyyy-MM-ddT23:30:00+08:00");
                    }
                }
                info.ResGuests.ResGuestList.Add(guest);
                info.ResGlobalInfo.GuestCounts.GuestCountList.Add(new Ctrip.Request.GuestCount()
                {
                    Count = corder.guestNames.Count
                });
                info.ResGlobalInfo.StartDate = corder.comeDate.Date.ToString("yyyy-MM-ddTHH:mm:ss+08:00");
                info.ResGlobalInfo.EndDate   = corder.leaveDate.Date.ToString("yyyy-MM-ddTHH:mm:ss+08:00");
                if (!string.IsNullOrEmpty(corder.specialRequest))
                {
                    info.ResGlobalInfo.SpecialRequests.SpecialRequest.Text = corder.specialRequest;
                }

                info.ResGlobalInfo.Total.AmountBeforeTax = corder.salePrice;
                //TODO   结算价模式
                info.ResGlobalInfo.TPA_Extensions.AmountBeforeTax = corder.totalPrice;
                //info.ResGlobalInfo.Total.AmountBeforeTax = corder.price;//指导价
                //info.ResGlobalInfo.Total.AmountBeforeTax = corder.price;//卖价
                //info.ResGlobalInfo.TPA_Extensions.TotalCost.AmountBeforeTax = corder.basePrice;//底价
                req.OTA_HotelResSaveRQ.HotelReservations.HotelReservationList.Add(info);


                var ctripRequest = new CtripRequest <HotelResSaveResponse>(req, Config);

                string xml = string.Empty;
                xml += "<Request>";
                string head    = RequestXmlWrapper.ToXml(ctripRequest.Header);
                string body    = "<HotelRequest><RequestBody xmlns:ns=\"http://www.opentravel.org/OTA/2003/05\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
                string content = RequestXmlWrapper.ToXml(ctripRequest.RequestBody);
                if (ctripRequest.RequestBody.GetType() != typeof(HotelDescriptiveRequest))
                {
                    content = content.Replace("<", "<ns:").Replace("<ns:/", "</ns:");
                }
                content = content.Replace("\"True\"", "\"true\"").Replace("\"False\"", "\"false\"");
                body   += content;
                body   += "</RequestBody></HotelRequest>";
                xml    += (head + body);
                xml    += "</Request>";

                logWriter.WriteOrder(corder.orderNo, $"请求参数:{xml}");

                //CtripOrderSubmit.OTA_HotelRes request = new CtripOrderSubmit.OTA_HotelRes();
                OTA_HotelResSave request = new OTA_HotelResSave();

                string response = request.Request(xml);
                logWriter.WriteOrder(corder.orderNo, $"请求参数:{response}");
                //if (WriteLog)
                //{
                //    Log.TFileLogManage.GetLog("xc_order_req").Debug(gid.ToString() + "::req::" + xml);
                //    Log.TFileLogManage.GetLog("xc_order_req").Debug(gid.ToString() + "::resp::" + response);
                //}

                response = response.Replace("xmlns=\"http://www.opentravel.org/OTA/2003/05\"", "");
                HotelResSaveResponse res = new HotelResSaveResponse();
                res.ResponseContent = response;
                res.ResponseXml     = new System.Xml.XmlDocument();
                res.ResponseXml.LoadXml(response);
                res.ParseXML2();
                if (res.Error != null)
                {
                    resp.code   = "-1";
                    resp.errMsg = res.Error.Type + ":" + res.Error.Code + ":" + res.Error.Message;
                }
                if (res != null && !string.IsNullOrEmpty(res.CtripOrderId))
                {
                    resp.code           = "0";
                    resp.result         = new ZXcResponseResult();
                    resp.result.orderId = res.CtripOrderId;
                }
            }
            catch (Exception ex)
            {
                resp.code   = "-9";
                resp.errMsg = "ExecutePost_Exception" + ":" + ex.Message;
            }
            return(resp);
        }