Exemplo n.º 1
0
        private string ToXMLString <TResponse>(CtripRequest <TResponse> request)
            where TResponse : BaseResponse
        {
            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(request.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(request.RequestBody);

            if (request.RequestBody.GetType() != typeof(HotelDescriptiveRequest) && request.RequestBody.GetType() != typeof(D_HotelOrderMiniInfoRequest) && request.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 (request.RequestBody.GetType() == typeof(D_HotelOrderMiniInfoRequest) || request.RequestBody.GetType() == typeof(D_GetCtripOrderIDRequest))
            {
                body = content;
            }
            xml += (head + body);
            xml += "</Request>]]></requestXML></Request></soap:Body></soap:Envelope>";
            return(xml);
        }
Exemplo n.º 2
0
        private TResponse ExecutePostCheck <TResponse>(IBaseRequest <TResponse> req)
            where TResponse : BaseResponse, new()
        {
            string    path      = string.Format("Ctrip/{0}/", req.Method);
            LogWriter logWriter = new LogWriter(path);
            string    content   = string.Empty;
            TResponse res       = new TResponse();
            Guid      gid       = Guid.NewGuid();

            var request = new RequestModel(HttpVerbs.POST);

            request.ContentType = "text/xml";
            request.Url         = ApiConfigManager.BaseUrl + req.Url;
            try
            {
                if (req != null)
                {
                    var ctripRequest = new CtripRequest <TResponse>(req, Config);


                    string xml    = ToXMLString(ctripRequest);
                    string method = req.Method;

                    if (method == "OTA_Cancel" || method == "OTA_HotelResSubmit" || method == "OTA_HotelRes")
                    {
                        logWriter.Write("请求XML:\n" + xml);
                    }
                    if (!string.IsNullOrEmpty(xml))
                    {
                        request.Data        = xml;
                        content             = HttpUtility.PostHtmlCheck(request);
                        res.ResponseContent = content;
                        res.ResponseXml     = new System.Xml.XmlDocument();
                        res.ResponseXml.LoadXml(content);
                        res.ParseXml();

                        //if (new List<string> { "SubmitOrder", "SubmitOrderPayment", "CheckOrderAvail" }.Contains(req.Method))
                        //{
                        //    logWriter.Write("请求XML:\n" + content);
                        //}

                        if (res.Error != null)
                        {
                            string msg = string.Format("hk_{0}", req.Url) + "responseXML:\n" + content + "\n--->>> " + res.Error.Code + ":" + res.Error.Message;
                            if (!string.IsNullOrEmpty(res.Error.Message) && res.Error.Message.Contains("RateLimit"))
                            {
                                if (method == "OTA_Cancel" || method == "OTA_HotelResSubmit" || method == "OTA_HotelRes")
                                {
                                    logWriter.Write("响应XML:\n" + content);
                                }

                                //if (ExeRetry)
                                //{
                                //    if (zcount <= 3)
                                //    {
                                //        zcount++;
                                //        System.Threading.Thread.Sleep(zcount * 500);
                                //        Log.TFileLogManage.GetLog("xc_response_Retry").Error(zcount.ToString() + ":::" + gid.ToString());
                                //        goto zRetry;
                                //    }
                                //}
                            }
                        }
                    }
                }
                return(res);
            }
            catch (Exception ex)
            {
                res.Error         = new Error();
                res.Error.Code    = "ExecutePost_Exception";
                res.Error.Message = ex.Message;

                //log.WriteLog(ex, method);
                if (!string.IsNullOrEmpty(content))
                {
                    //log.WriteLog(content, method);
                }
                return(res);
            }
        }
Exemplo n.º 3
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);
        }