/// <summary> /// 酒店静态数据查询 /// </summary> /// <returns></returns> public static OTA_HotelDescriptiveInfoReturnEntity OTA_HotelDescriptiveInfo(List<int> hotelIdList, bool sendHotelData = true, bool sendGuestRooms = true) { OTA_HotelDescriptiveInfoCallEntity callEntity = new OTA_HotelDescriptiveInfoCallEntity(); var items = from it in hotelIdList select new DescriptiveInfo() { HotelCode = it, SendHotelData = sendHotelData, SendMultimediaObjectsData = true, SendRecreations = true, SendGuestRooms = true, SendContactInfoData = true, SendAttractions = true }; callEntity.DescriptiveInfos = items.ToList(); return hotelOTAService.OTA_HotelDescriptiveInfo(callEntity); }
/// <summary> /// 根据请求的Hotel Code返回相应的酒店静态信息, /// 并根据请求返回酒店信息,酒店设施,酒店区域,酒店多媒体信息 /// </summary> /// <returns></returns> public OTA_HotelDescriptiveInfoReturnEntity OTA_HotelDescriptiveInfo(OTA_HotelDescriptiveInfoCallEntity req) { var rep = new OTA_HotelDescriptiveInfoReturnEntity(); StringBuilder reqXml = new StringBuilder(); reqXml.AppendFormat("<OTA_HotelDescriptiveInfoRQ Version=\"1.0\" xsi:schemaLocation=\"http://www.opentravel.org/OTA/2003/05 OTA_HotelDescriptiveInfoRQ.xsd\" xmlns=\"http://www.opentravel.org/OTA/2003/05\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"); reqXml.Append("<HotelDescriptiveInfos>"); foreach (var item in req.DescriptiveInfos) { reqXml.AppendFormat("<HotelDescriptiveInfo HotelCode=\"{0}\" PositionTypeCode=\"502\">", item.HotelCode); if (item.SendHotelData != null) { reqXml.AppendFormat("<HotelInfo SendData=\"{0}\"/>", item.SendHotelData.ToString().ToLower()); } if (item.SendGuestRooms != null) { reqXml.AppendFormat("<FacilityInfo SendGuestRooms=\"{0}\"/>", item.SendGuestRooms.ToString().ToLower()); } if (item.SendAttractions != null || item.SendRecreations != null) { reqXml.Append("<AreaInfo"); if (item.SendAttractions != null) { reqXml.AppendFormat(" SendAttractions=\"{0}\"", item.SendAttractions.ToString().ToLower()); } if (item.SendRecreations != null) { reqXml.AppendFormat(" SendRecreations=\"{0}\"", item.SendRecreations.ToString().ToLower()); } reqXml.Append(" />"); } if (item.SendMultimediaObjectsData != null) { reqXml.AppendFormat("<MultimediaObjects SendData=\"{0}\"/>", item.SendMultimediaObjectsData.ToString().ToLower()); } reqXml.Append("</HotelDescriptiveInfo>"); } reqXml.Append("</HotelDescriptiveInfos>"); reqXml.Append("</OTA_HotelDescriptiveInfoRQ>"); req.RequestContent = reqXml.ToString(); string repXml = HotelApiCall(req); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(repXml); GetHeaderResult(xmlDoc,rep); List<HotelDescriptiveInfo> hotelDescList = new List<HotelDescriptiveInfo>(); var descriptiveContentNodes = xmlDoc.SelectNodes("Response/HotelResponse/OTA_HotelDescriptiveInfoRS/HotelDescriptiveContents/HotelDescriptiveContent"); foreach (XmlNode descriptiveContentNode in descriptiveContentNodes) { HotelDescriptiveInfo hotelDesc = new HotelDescriptiveInfo(); XmlElement descElement = (XmlElement)descriptiveContentNode; hotelDesc.AreaID = descElement.GetAttribute("AreaID").ToInt32(); hotelDesc.BrandCode = descElement.GetAttribute("BrandCode").ToInt32(); hotelDesc.HotelCode = descElement.GetAttribute("HotelCode").ToInt32(); hotelDesc.HotelCityCode = descElement.GetAttribute("HotelCityCode").ToInt32(); hotelDesc.HotelId = hotelDesc.HotelCode; hotelDesc.HotelName = descElement.GetAttribute("HotelName").Trim(); XmlNode hotelInfoNode = descriptiveContentNode.SelectSingleNode("HotelInfo"); var dt = ((XmlElement)hotelInfoNode).GetAttribute("WhenBuilt").Trim(); hotelDesc.WhenBuild = ((XmlElement)hotelInfoNode).GetAttribute("WhenBuilt").Trim().ToDateTime(); var lastUpdate = ((XmlElement)hotelInfoNode).GetAttribute("LastUpdated"); if (string.IsNullOrEmpty(lastUpdate)) { hotelDesc.LastUpdated = DateTime.Parse("1900-1-1"); } else { hotelDesc.LastUpdated = ((XmlElement)hotelInfoNode).GetAttribute("LastUpdated").Trim().ToDateTime(); } // 地址信息 var addressNode = hotelInfoNode.SelectSingleNode("Address"); string address = ""; if(addressNode.SelectSingleNode("AddressLine")!=null) { address = addressNode.SelectSingleNode("AddressLine").InnerText; } hotelDesc.Address = address; // 区域信息 var zoneNodes = addressNode.SelectNodes("Zone"); hotelDesc.ZoneName = ""; hotelDesc.ZoneId = 0; foreach(XmlNode zn in zoneNodes) { if(zn.SelectSingleNode("ZoneCode").InnerText.Trim().ToInt32()>0) { hotelDesc.ZoneId = zn.SelectSingleNode("ZoneCode").InnerText.Trim().ToInt32(); hotelDesc.ZoneName = zn.SelectSingleNode("ZoneName").InnerText.Trim(); break; } } string postCode=""; XmlNode postCodeNode = addressNode.SelectSingleNode("PostalCode"); if(postCodeNode!=null) { postCode = postCodeNode.InnerText; } hotelDesc.PostCode = postCode; hotelDesc.HotelCityName = ""; XmlNode hotelCityNameNode = addressNode.SelectSingleNode("CityName"); if(hotelCityNameNode!=null) { hotelDesc.HotelCityName = hotelCityNameNode.InnerText.Trim(); } // 一些常用的酒店标签和分类 var segmentNodes = descriptiveContentNode.SelectNodes("HotelInfo/CategoryCodes/SegmentCategory"); if (segmentNodes != null) { List<string> segmentCategoryList = new List<string>(); foreach (XmlNode sn in segmentNodes) { segmentCategoryList.Add(sn.InnerText.Trim()); } hotelDesc.SegmentCategoryList = segmentCategoryList; } XmlNode positionNode = hotelInfoNode.SelectSingleNode("Position"); hotelDesc.Latitude = ((XmlElement)positionNode).GetAttribute("Latitude").Trim(); hotelDesc.Longitude = ((XmlElement)positionNode).GetAttribute("Longitude").Trim(); hotelDesc.PositionTypeCode = ((XmlElement)positionNode).GetAttribute("PositionTypeCode").Trim(); // 酒店服务和设备 XmlNodeList serviceNodeList = hotelInfoNode.SelectNodes("Services/Service"); List<Facility> serviceTypeList = new List<Facility>(); foreach (XmlNode node in serviceNodeList) { serviceTypeList.Add(new Facility() { ID = ((XmlElement)node).GetAttribute("ID").Trim().ToInt32(), Code = ((XmlElement)node).GetAttribute("Code").Trim().ToInt32(), DescriptiveText = node.SelectSingleNode("DescriptiveText").InnerText.Trim() }); } hotelDesc.FacilityList = serviceTypeList; // 房型信息列表 var GuestRoomNodeList = descriptiveContentNode.SelectNodes("FacilityInfo/GuestRooms/GuestRoom"); List<HotelRoom> guestRoomList = new List<HotelRoom>(); foreach (XmlNode node in GuestRoomNodeList) { HotelRoom room = new HotelRoom(); room.RoomTypeName = ((XmlElement)node).GetAttribute("RoomTypeName").Trim(); var typeNode = (XmlElement)node.SelectSingleNode("TypeRoom"); room.StandardOccupancy = typeNode.GetAttribute("StandardOccupancy").Trim().ToInt32(); room.Size = typeNode.GetAttribute("Size").Trim(); room.BedTypeCode = typeNode.GetAttribute("BedTypeCode").Trim(); room.Floor = typeNode.GetAttribute("Floor").Trim(); room.Quantity = typeNode.GetAttribute("Quantity").Trim().ToInt32(); room.RoomTypeCode = typeNode.GetAttribute("RoomTypeCode").ToInt32(); room.NonSmoking = typeNode.GetAttribute("NonSmoking").Trim().ToLower()=="false"?0:1; room.RoomSize = typeNode.GetAttribute("RoomSize").Trim().ToInt32(); // 酒店房间描述 XmlNode descriptionNode = node.SelectSingleNode("Features/Feature/DescriptiveText"); if (descriptionNode != null) { room.DescriptiveText = descriptionNode.InnerText.Trim(); } // 房间内设施 var amenityNodeList = node.SelectNodes("Amenities/Amenity"); List<RoomFacility> hotelAmenties = new List<RoomFacility>(); RoomFacility amentity = null; foreach (XmlNode an in amenityNodeList) { amentity = new RoomFacility(); amentity.Code = ((XmlElement)an).GetAttribute("RoomAmenityCode").Trim(); XmlNode descriptiveTextNode = an.SelectSingleNode("DescriptiveText"); amentity.DescriptiveText = descriptiveTextNode.InnerText; hotelAmenties.Add(amentity); } room.Amenities = hotelAmenties; // 行政区信息,地标类区域和建筑列表 var refPointNodes = descriptiveContentNode.SelectNodes("AreaInfo/RefPoints/RefPoint"); List<AreaInfo> refPoints = new List<AreaInfo>(); AreaInfo refPoint = null; foreach (XmlNode p in refPointNodes) { refPoint = new AreaInfo(); XmlElement pe = (XmlElement)p; refPoint.Distance = pe.GetAttribute("Distance").ToDecimal(); refPoint.Latitude = pe.GetAttribute("Latitude").Trim(); refPoint.Longitude = pe.GetAttribute("Longitude").Trim(); refPoint.Name = pe.GetAttribute("Name").Trim(); refPoint.RefPointCategoryCode = pe.GetAttribute("RefPointCategoryCode").Trim().ToInt32(); refPoint.RefPointName = pe.GetAttribute("RefPointName").Trim(); refPoint.UnitOfMeasureCode = pe.GetAttribute("UnitOfMeasureCode").Trim().ToInt32(); var descTextNode = p.SelectSingleNode("DescriptiveText"); refPoint.DescriptiveText = descTextNode.InnerText; refPoints.Add(refPoint); } hotelDesc.AreaInfoList = refPoints; // 酒店星级、携程星级、推荐级别 // 酒店等级、评分列表 var awardsNodes = descriptiveContentNode.SelectNodes("AffiliationInfo/Awards/Award"); foreach (XmlElement el in awardsNodes) { string provider = el.GetAttribute("Provider").Trim(); decimal rating = el.GetAttribute("Rating").Trim().ToDecimal(); switch (provider) { case "HotelStarRate": hotelDesc.HotelStarRate = rating; break; case "CtripStarRate": hotelDesc.CtripStarRate = rating; break; case "CtripUserRate": hotelDesc.CtripUserRate = rating; break; case "CtripCommRate": hotelDesc.CtripCommRate = rating; break; case "CommSurroundingRate": hotelDesc.CommSurroundingRate = rating; break; case "CommFacilityRate": hotelDesc.CommFacilityRate = rating; break; case "CommCleanRate": hotelDesc.CommCleanRate = rating; break; case "CommServiceRate": hotelDesc.CommServiceRate = rating; break; case "HotelStarLicence": hotelDesc.HotelStarLicence = rating; break; } } //hotelDesc.am guestRoomList.Add(room); } hotelDesc.HotelRoomList = guestRoomList; var hotelTextNodes = descriptiveContentNode.SelectNodes("MultimediaDescriptions/MultimediaDescription/TextItems/TextItem"); List<MultimediaTextDescription> multimediaTextList = new List<MultimediaTextDescription>(); MultimediaTextDescription multimediaText; foreach (XmlNode textNode in hotelTextNodes) { multimediaText = new MultimediaTextDescription(); multimediaText.Category = ((XmlElement)textNode).GetAttribute("Category").Trim().ToInt32(); var descNode = textNode.SelectSingleNode("Description"); if(descNode!=null) { multimediaText.Text = descNode.InnerText.Trim(); } var urlNode = textNode.SelectSingleNode("URL"); if(urlNode!=null) { multimediaText.Text = urlNode.InnerText.Trim(); } multimediaTextList.Add(multimediaText); } hotelDesc.MultimediaTextDescriptionList = multimediaTextList; var hotelImgNodes = descriptiveContentNode.SelectNodes("MultimediaDescriptions/MultimediaDescription/ImageItems/ImageItem"); List<MultimediaImgDescription> multimediaImgList = new List<MultimediaImgDescription>(); MultimediaImgDescription multimediaImg = null; foreach (XmlNode imgNode in hotelImgNodes) { multimediaImg = new MultimediaImgDescription(); multimediaImg.Category = ((XmlElement)imgNode).GetAttribute("Category").Trim(); multimediaImg.Caption = ((XmlElement)imgNode.SelectSingleNode("Description")).GetAttribute("Caption").Trim(); multimediaImg.Url = imgNode.SelectSingleNode("ImageFormat/URL").InnerText.Trim(); multimediaImg.Description = ((XmlElement)imgNode.SelectSingleNode("Description")).InnerText.Trim(); multimediaImgList.Add(multimediaImg); } hotelDesc.MultimediaImgDescriptionList = multimediaImgList; var policyNode = descriptiveContentNode.SelectSingleNode("Policies/Policy"); HotelPolicy hotelPolicy = new HotelPolicy(); List<PolicyInfoCode> policies = new List<PolicyInfoCode>(); PolicyInfoCode polocyCode; if(policyNode!=null) { var policyCodeNodes = policyNode.SelectNodes("PolicyInfoCodes/PolicyInfoCode"); if(policyCodeNodes!=null&&policyCodeNodes.Count>0) { foreach(XmlElement xe in policyCodeNodes) { polocyCode = new PolicyInfoCode(); polocyCode.Code = xe.GetAttribute("Code").Trim(); var policyDescNodes = xe.SelectNodes("Description"); List<Tuple<string, string>> descriptions = new List<Tuple<string, string>>(); if (policyDescNodes != null && policyDescNodes.Count > 0) { foreach (XmlElement pd in policyDescNodes) { descriptions.Add(new Tuple<string, string>(pd.GetAttribute("Name").Trim(), pd.SelectSingleNode("Text").InnerText.Trim())); } } polocyCode.Descriptions = descriptions; policies.Add(polocyCode); } } var polocyInfoNode = policyNode.SelectSingleNode("PolicyInfo") as XmlElement; PolicyInfo polocyInfo = new PolicyInfo(); if(polocyInfoNode!=null) { polocyInfo.CheckOutTime = polocyInfoNode.GetAttribute("CheckInTime").Trim(); polocyInfo.CheckInTime = polocyInfoNode.GetAttribute("CheckOutTime").Trim(); } hotelPolicy.PolicyInfo = polocyInfo; } hotelPolicy.PolicyInfoCodes = policies; hotelDesc.PolicyInfo = hotelPolicy; hotelDescList.Add(hotelDesc); } rep.DescriptiveInfos = hotelDescList; return rep; }