标签:
机票代理人Shoppping指令区别AV,AV指令只能查询4折以上的机票,而Shoppping可以查询所有折扣机票,所以现在把c#编写的Shoppping共享!
以post请求参数
String org;//出发地
String dst;目的地
String orgdate;出发日期
Strin DirectFlightOnly;//是否直达,传true时只能查直达的航班,传false时查询中转航班
using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Com.Travelsky.Ibe.Client; using Com.Travelsky.Util; using Com.Travelsky.Ibe.Exceptions; using System.Web.Script.Serialization; using System.Diagnostics; using Com.Travelsky.Ibe.Client.Pnr; using Com.Travelsky.Ebuild.Clientapi.FlightShoppping; using System.Collections; using System.Text; using System.Globalization; using Newtonsoft.Json; public partial class AV1 : System.Web.UI.Page { public string FFDprice = "";//所有定义价格返回字符串 protected void Page_Load(object sender, EventArgs e) { try { FlightShoppping fltshopping = new FlightShoppping(); FareInterface service = new FareInterface(); Input input = new Input(); input.SetHeaderInType(getHeaderInType()); Request request = new Request(); FlightShopRequestType flightShopRequestType = new FlightShopRequestType(); //设置OD ArrayList originDestinationInfo = new ArrayList(); originDestinationInfo.Add(getOriginDestinationInfoType()); flightShopRequestType.SetOriginDestinationInfo(originDestinationInfo); //设置AVJourney //ArrayList AVJ = new ArrayList(); //AVJ.Add(getAvJourneys(input)); //flightShopRequestType.SetAvJourneys(AVJ); //设置TravelPreferences flightShopRequestType.SetTravelPreferencesType(getTravelPreferencesType()); //设置Option flightShopRequestType.SetOption(getOption()); /*//设置AdditionalShopRQData flightShopRequestType.setAdditionalShopRQData(getAdditionalShopRQData());*/ request.SetFlightShopRequestType(flightShopRequestType); input.SetRequest(request); service.SetInput(input); //long begin = System.currentTimeMillis(); //Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); //stopwatch.Start(); // 开始监视代码 Output outT = new Output(); outT = fltshopping.DoFlightShopping(service);//查询国内Shopping //System.out.println(out); FFDprice = StringBuildera(outT);//给所有航空公司返回价格附值 //CwJgInfo(FFDprice); //Response.Write(FFDprice); PrintResult(outT); //Response.Write(StringBuildera(outT)); //stopwatch.Stop(); // 停止监视 //long Milliseconds = stopwatch.ElapsedMilliseconds; // 获取总时间 //Response.Write(Milliseconds.ToString()); } catch (IBEException ex) { Response.Write("callbackfun({ result:\"" + ex.Message.ToString() + "\"})"); } } public static HeaderInType getHeaderInType() { HeaderInType hi = new HeaderInType(); hi.SetSysCode("CRS");//ICS或者CRS //hi.SetSysType("IBE");//接入系统类型。如BLUESKY/IBE/TRAVELWEB。 hi.SetChannelID("1E");//CAET或者1E //hi.SetChannelType("B2C");//B2B或者B2C,渠道设置为 1E 下不能设置,非 1E 时根据具体情况设置 Agency agency = new Agency(); agency.SetOfficeId("<span style="font-family: Arial, Helvetica, sans-serif;">BJS999</span><span style="font-family: Arial, Helvetica, sans-serif;">");//如:代理人office号,BJS999 BJS472</span> agency.SetPid("11066");//如:20200 agency.SetCity("PEK");//代理人所在地区 //agency.setIataNum(""); //agency.setCountry(""); hi.SetAgency(agency); hi.SetLanguage("CN");//EN或者CN hi.SetCommandType("FS");// return hi; } public static OriginDestinationInfoType getOriginDestinationInfoType()//去程类 { string ori = HttpContext.Current.Request["org"];//起始地 string des = HttpContext.Current.Request["dst"];//目的地 string SetDepartureDate = HttpContext.Current.Request["orgdate"];//去程日期 DateBinding db = new DateBinding(); OriginDestinationInfoType od = new OriginDestinationInfoType(); od.SetOri(ori.Trim());//起始地 od.SetDes(des.Trim());//目的地 od.SetDepartureDate(SetDepartureDate.Trim());//起始出发日期,格式为DDMMMYY return od; } public static Option getOption() { Option op = new Option(); //op.SetFcFeature("0");//组合限制取值为0/1,默认值为0 op.SetIsAvNeeded("Y");//结果中是否需要AV信息。Y/N,缺省为Y op.SetIsPSnNeeded("Y");//结果中是否需要PS信息。Y/N,缺省为Y //op.SetIsPsAvBindsNeeded("Y");//结果中是否需要PsAvBinding信息。Y/N,缺省为Y //op.SetIsFaresNeeded("Y");//结果中是否需要fare信息。Y/N,缺省为Y //op.SetIsRefundReissueRuleNeeded("Y"); //op.SetIsRefundReissueTextRuleNeeded("Y");//需要文本退改签信息 op.SetFormat("NOR");//SIM:简化格式;NOR:正常格式,缺省为NOR //op.SetIsCompressedResultNeeded("Y");//需要压缩结果;N 不需要不压缩 string DirectFlightOnly = HttpContext.Current.Request["DirectFlightOnly"];//是否直达 if (DirectFlightOnly.Trim() == "true") { op.SetLowestOrAll("A");//L:每个航班返回最低价; A:返回所有可用舱位价格。缺省为L } else { op.SetLowestOrAll("L");//L:每个航班返回最低价; A:返回所有可用舱位价格。缺省为L } //op.SetLowestOrAll("A");//L:每个航班返回最低价; A:返回所有可用舱位价格。缺省为L //op.SetRuleTypeNeeded("ALL");//ALL:需要所有文本规则;NON:不需要文本规则;SIM:只需要文本规则前两项缺省为ALL op.SetFareSource("ALL");//PUB-查公布价, YPUB-只查Y舱公布价, ALL-包括公布价和净价。缺省为ALL //op.SetIsSpecificClassAllPriceZvalueNeeded("Y");//setIsSpecificClassAllPriceZvalueNeeded("Y"); //op.SetIsPsDateBindsNeeded("Y"); op.SetIsCabinFareNeeded("Y"); op.SetIsZKeyNeeded("Y"); return op; } public static TravelPreferencesType getTravelPreferencesType() { TravelPreferencesType tp = new TravelPreferencesType(); //tp.setCabinClass("Y");//服务等级 F/C/Y tp.SetDisplayCurrCode("CNY");//显示用货币类型 tp.SetCurrCode("CNY");//运价发布所有货币类型 string DirectFlightOnly = HttpContext.Current.Request["DirectFlightOnly"];//是否直达 if (DirectFlightOnly.Trim() == "true") { tp.SetIsDirectFlightOnly(true);//true - 只要直达航班;false - 包括非直达航班 } else { tp.SetIsDirectFlightOnly(false);//true - 只要直达航班;false - 包括非直达航班 } tp.SetJourneyType("OW");//OW - one way; RT - round trip; TS - two segments; MS - multi segment //tp.SetIsDealModel(true);//是否走产品管理(EPM) //tp.setIsGroup(false);//是否为团队 true/false ArrayList passenger = new ArrayList(); PassengerType pa = new PassengerType(); pa.SetNumber(1);//人数 pa.SetType("AD");//成人 passenger.Add(pa); tp.SetPassenger(passenger); return tp; } /*====================查询指定航空公司舱位价格===================== --例:1180.00/HU/7081/05NOV15/F/O/50.0/0.0/1350.00/CNY/0.0300,CA/C/2930.00/130.0/50.0/50.0*/ public string StringBuildera(Output output) { string str = ""; if (output.GetResult().GetFlightShopResult().GetPSn().GetPS() != null) { for (int j = 0; j < output.GetResult().GetFlightShopResult().GetPSn().GetPS().Count; j++) { PricingSolutionType fs_ps = (PricingSolutionType)output.GetResult().GetFlightShopResult().GetPSn().GetPS()[j]; CabinFare CF = (CabinFare)fs_ps.Getcabinfares().GetyCabinFare()[0]; string cabin = CF.Getcabin();//服务等级 string amount = CF.Getamount();//服务等级价格 for (int j2 = 0; j2 < fs_ps.GetRouts().Count; j2++) { Routs routs = (Routs)fs_ps.GetRouts()[j2]; for (int j21 = 0; j21 < routs.GetRout().Count; j21++) { if (cabin.Trim() != "") { str = str + amount + "/"; } else { str = str + "0" + "/"; } RoutType rout = (RoutType)routs.GetRout()[j21]; //rout.GetBkClass(); string carr = rout.GetCarr();//航空公司两字码 str = str + carr + "/"; string fltNo = rout.GetFltNo();//航班号 str = str + fltNo + "/"; string departureDate = rout.GetDepartureDate();//起飞日期 DateTime st = DateTime.Parse(departureDate); string strDate = st.ToString("ddMMMyy", DateTimeFormatInfo.InvariantInfo); str = str + strDate + "/"; string bkClass = rout.GetBkClass();//舱位 str = str + bkClass + "/"; string oI = rout.GetOI();//去程回程标志,O 代表去程,I 代表回程 str = str + oI + "/"; TaxType tax = (TaxType)fs_ps.GetTaxes().GetTax()[0]; string amt = tax.GetAmt();//机场建建设费 str = str + amt + "/"; TaxType tax_a = (TaxType)fs_ps.GetTaxes().GetTax()[1]; string amt_A = tax_a.GetAmt();//燃油费 str = str + amt_A + "/"; string disAmt = fs_ps.GetDisAmt();//机票价格 str = str + disAmt + "/"; string disCurrCode = fs_ps.GetDisCurrCode();//显示用货币类型 str = str + disCurrCode + "/"; string zValue = fs_ps.GetZValue();//退票费折扣 str = str + zValue + "/"; str = str + ","; } } } } return str; } //3个参数:所有航空公司舱位价格,所要查询的航空公司,要查询的舱位 public string CwJgInfo(string CabinPrice, string airline, string fltNo, string Scw)// { string amt = "0";//机场建建设费 string amt_A = "0";//燃油费 string disAmt = "0";//机票价格 string disCurrCode = "CNY";//显示用货币类型 string zValue = "0";//退票费折扣 string DisCount = "0";//折扣 string OI = "O";//去回程标识 string[] arrayabc = CabinPrice.Split(',');//分割 //sb.Append("价格数据量:" + arrayabc.Length); for (int jgabc = 0; jgabc < arrayabc.Length - 1; jgabc++) { string[] CwJgOne = arrayabc[jgabc].Split('/');//分割 if (airline.Trim() == CwJgOne[1].Trim() && fltNo.Trim() == CwJgOne[2].Trim() && Scw.Trim() == CwJgOne[4].Trim())// && dt == CwJgOne[2].Trim().ToUpper() { amt = CwJgOne[6].ToString();//机场建建设费 //sb.Append("机场建建设费:" + amt); amt_A = CwJgOne[7].ToString();//燃油费 //sb.Append("燃油费:" + amt_A); disAmt = CwJgOne[8].ToString();//机票价格 //sb.Append("机票价格:" + disAmt); disCurrCode = CwJgOne[9].ToString();//显示用货币类型 //sb.Append("显示用货币类型:" + disCurrCode); zValue = CwJgOne[10].ToString();//代理费折扣 //sb.Append("代理费折扣:" + zValue); if (CwJgOne[0].ToString().Trim() == "0") { DisCount = "特价";//折扣 //amount = CwJgOne[0].ToString();//Y舱位价格 } else { if (CwJgOne[0].ToString().Trim() == CwJgOne[8].ToString().Trim()) { DisCount = "全价";//折扣 //amount = CwJgOne[0].ToString();//Y舱位价格 } else { double xzjg = Convert.ToDouble(CwJgOne[8].ToString().Trim());//现有价格 double yljg = Convert.ToDouble(CwJgOne[0].ToString().Trim());//原来价格 double zk = Math.Round((xzjg / yljg) * 10, 1); if (zk > 10 || zk < 0) { DisCount = "特殊折扣"; } else { DisCount = zk.ToString();//默认为保留两位 } } } OI = CwJgOne[5].ToString();//去回程标识 } } return amt + "/" + amt_A + "/" + disAmt + "/" + disCurrCode + "/" + zValue + "/" + DisCount + "/" + OI; } public void PrintResult(Output output) { //StringBuilder sb = new StringBuilder(); List<myAvItem> list = new List<myAvItem>(); if (output.GetResult().GetFlightShopResult().GetAvJourneys() != null) { for (int i = 0; i < output.GetResult().GetFlightShopResult().GetAvJourneys().Count; i++) { AvJourneys fs_aj = (AvJourneys)output.GetResult().GetFlightShopResult().GetAvJourneys()[i]; for (int h1 = 0; h1 < fs_aj.GetAvJourney().Count; h1++) { AvailableJourneyType ajt = (AvailableJourneyType)fs_aj.GetAvJourney()[h1]; for (int h2 = 0; h2 < ajt.GetAvOpt().Count; h2++) { AvOpt avopt = (AvOpt)ajt.GetAvOpt()[h2]; for (int h3 = 0; h3 < avopt.GetFlt().Count; h3++) { FsFlightType flt = (FsFlightType)avopt.GetFlt()[h3]; Codeshare cdsh = flt.GetCodeshare(); string airlinegx = cdsh.GetAirline(); //string fltnogx = cdsh.GetFltno(); //string airline = flt.GetAirline();//航空公司 //string fltNo = flt.GetFltNo();//航班号 //Response.Write("开始--原航班号:" + airline + fltNo + ",共享航班号:" + airlinegx + fltnogx + "/----"); if (airlinegx == null || airlinegx == "") { myAvItem model = new myAvItem(); string rPH = flt.GetRPH().Substring(0, 6);//编号 string airline = flt.GetAirline();//航空公司 string fltNo = flt.GetFltNo();//航班号 Term term = new Term();//航站楼信息类 term = flt.GetTerm(); string dep = flt.GetDep();//出发地 string dep_term = term.GetDep();//出发航站楼 string arr = flt.GetArr();//目的地 string arr_term = term.GetArr();//到达航站楼 int tpm = flt.GetTpm();//里程 string dt = flt.GetDt();//出发日期 string week = flt.GetWeek();//星期 string deptm = flt.GetDeptm();//出发时间 string arrtm = flt.GetArrtm();//到达时间 int stop = flt.GetStop();//经停 string dev = flt.GetDev();//机型 string meal = flt.GetMeal();//餐食标识 /*B 早餐 C 免费酒精饮料 D 正餐 F 供采购的食物 G 供采购的食物和饮料 H 热的膳食 K 轻快早餐 L 午餐 M 膳食 N 没有饭食供应 O 冷的膳食 P 供采购的酒精饮料 R 茶点 S 快餐 V 供采购的茶点 */ model.rPH = rPH;//编号 model.dt = dt;//出发日期 model.Carrier = airline;//航空公司两字码 model.Airline = fltNo; //航班号 model.Orgcity = dep;//起飞城市 model.Deptime = deptm;//起飞时刻 model.Dstcity = arr;//到达城市 model.Arritime = arrtm;//到达时刻 model.Planestyle = dev;//机型 model.Stopnumber = stop;//经停次数 model.DepTermAndArriTerm = dep_term;//出发航站楼 model.arrTermAndArriTerm = arr_term;//到达航站楼 model.Meal = meal;//餐食 model.tpm = tpm; ////里程 for (int h4 = 0; h4 < flt.Get_Class().Count; h4++) { ClassType ct = (ClassType)flt.Get_Class()[h4]; string cwname = ct.GetName();//可用舱位名 //sb.Append("舱位名=" + cwname + ","); string av = ct.GetAv();//可用舱位数量 //sb.Append("可用舱位数量=" + av + ","); ArrayList subclass_al = new ArrayList(); subclass_al = ct.GetSubClass(); if (subclass_al.Count > 0) { for (int h5 = 0; h5 < subclass_al.Count; h5++) { string subcwname = subclass_al[h5].ToString();//子舱位名 //sb.Append("子舱位名=" + cwname + ","); if (subcwname.Trim() != cwname.Trim()) { string ThisCabinInformation = CwJgInfo(FFDprice, airline.Trim(), fltNo.Trim(), subcwname.Trim()); string[] CwJgOne = ThisCabinInformation.Split('/');//分割 myCabinPriceInfo CabinPriceInfo = new myCabinPriceInfo(); if (CwJgOne[2].ToString().Trim() != "0") { string amt = "0";//机场建建设费 string amt_A = "0";//燃油费 string disAmt = "0";//机票价格 string disCurrCode = "CNY";//显示用货币类型 string zValue = "0";//代理人Z值 string DisCount = "0";// 折扣 string OI = "O";// 去回程标识 amt = CwJgOne[0].ToString(); amt_A = CwJgOne[1].ToString(); disAmt = CwJgOne[2].ToString(); disCurrCode = CwJgOne[3].ToString(); zValue = CwJgOne[4].ToString(); DisCount = CwJgOne[5].ToString(); OI = CwJgOne[6].ToString(); CabinPriceInfo.CabinNo = subcwname.Trim();//可用舱位名 CabinPriceInfo.CabinInfo = av.Trim();//数量 CabinPriceInfo.Price = disAmt;//机票价格 CabinPriceInfo.disCurrCode = disCurrCode;//显示用货币类型 CabinPriceInfo.AirportTax = amt;//机场建建设费 CabinPriceInfo.FuelTax = amt_A;//燃油费 CabinPriceInfo.zValue = zValue;//代理人Z值 CabinPriceInfo.DisCount = DisCount;// 折扣 CabinPriceInfo.OI = OI;// 去回程标识 model.listCabinPriceInfo.Add(CabinPriceInfo); } } else { string ThisCabinInformation = CwJgInfo(FFDprice, airline.Trim(), fltNo.Trim(), cwname.Trim()); string[] CwJgOne = ThisCabinInformation.Split('/');//分割 myCabinPriceInfo CabinPriceInfo = new myCabinPriceInfo(); if (CwJgOne[2].ToString().Trim() != "0") { string amt = "0";//机场建建设费 string amt_A = "0";//燃油费 string disAmt = "0";//机票价格 string disCurrCode = "CNY";//显示用货币类型 string zValue = "0";//代理人Z值 string DisCount = "0";// 折扣 string OI = "O";// 去回程标识 amt = CwJgOne[0].ToString(); amt_A = CwJgOne[1].ToString(); disAmt = CwJgOne[2].ToString(); disCurrCode = CwJgOne[3].ToString(); zValue = CwJgOne[4].ToString(); DisCount = CwJgOne[5].ToString(); OI = CwJgOne[6].ToString(); CabinPriceInfo.CabinNo = cwname.Trim();//可用舱位名 CabinPriceInfo.CabinInfo = av.Trim();//数量 CabinPriceInfo.Price = disAmt;//机票价格 CabinPriceInfo.disCurrCode = disCurrCode;//显示用货币类型 CabinPriceInfo.AirportTax = amt;//机场建建设费 CabinPriceInfo.FuelTax = amt_A;//燃油费 CabinPriceInfo.zValue = zValue;//代理人Z值 CabinPriceInfo.DisCount = DisCount;// 折扣 CabinPriceInfo.OI = OI;// 去回程标识 model.listCabinPriceInfo.Add(CabinPriceInfo); } } } } else { string ThisCabinInformation = CwJgInfo(FFDprice, airline.Trim(), fltNo.Trim(), cwname.Trim()); string[] CwJgOne = ThisCabinInformation.Split('/');//分割 myCabinPriceInfo CabinPriceInfo = new myCabinPriceInfo(); if (CwJgOne[2].ToString().Trim() != "0") { string amt = "0";//机场建建设费 string amt_A = "0";//燃油费 string disAmt = "0";//机票价格 string disCurrCode = "CNY";//显示用货币类型 string zValue = "0";//代理人Z值 string DisCount = "0";// 折扣 string OI = "O";// 去回程标识 amt = CwJgOne[0].ToString(); amt_A = CwJgOne[1].ToString(); disAmt = CwJgOne[2].ToString(); disCurrCode = CwJgOne[3].ToString(); zValue = CwJgOne[4].ToString(); DisCount = CwJgOne[5].ToString(); OI = CwJgOne[6].ToString(); CabinPriceInfo.CabinNo = cwname.Trim();//可用舱位名 CabinPriceInfo.CabinInfo = av.Trim();//数量 CabinPriceInfo.Price = disAmt;//机票价格 CabinPriceInfo.disCurrCode = disCurrCode;//显示用货币类型 CabinPriceInfo.AirportTax = amt;//机场建建设费 CabinPriceInfo.FuelTax = amt_A;//燃油费 CabinPriceInfo.zValue = zValue;//代理人Z值 CabinPriceInfo.DisCount = DisCount;// 折扣 CabinPriceInfo.OI = OI;// 去回程标识 model.listCabinPriceInfo.Add(CabinPriceInfo); } } } //ArrayList arrl_class = new ArrayList(); //可用舱位信息 //arrl_class = flt.Get_Class(); ; //ClassType classtype = new ClassType(); //for (int cwinfo = 0; cwinfo < arrl_class.Count; cwinfo++) //{ // string[] array = arrl_class[cwinfo].ToString().Split(',');//分割 // string[] arraya = array[0].Split('='); // string[] arrayb = array[2].Split('='); // string ThisCabinInformation = CwJgInfo(FFDprice, airline.Trim(), fltNo.Trim(), arraya[1].Trim()); // string[] CwJgOne = ThisCabinInformation.Split('/');//分割 // myCabinPriceInfo CabinPriceInfo = new myCabinPriceInfo(); // if (CwJgOne[2].ToString().Trim() != "0") // { // string amt = "0";//机场建建设费 // string amt_A = "0";//燃油费 // string disAmt = "0";//机票价格 // string disCurrCode = "CNY";//显示用货币类型 // string zValue = "0";//代理人Z值 // amt = CwJgOne[0].ToString(); // amt_A = CwJgOne[1].ToString(); // disAmt = CwJgOne[2].ToString(); // disCurrCode = CwJgOne[3].ToString(); // zValue = CwJgOne[4].ToString(); // CabinPriceInfo.CabinNo = arraya[1].Trim();//可用舱位名 // CabinPriceInfo.CabinInfo = arrayb[1].Trim();//数量 // CabinPriceInfo.Price = disAmt;//机票价格 // CabinPriceInfo.disCurrCode = disCurrCode;//显示用货币类型 // CabinPriceInfo.AirportTax = amt;//机场建建设费 // CabinPriceInfo.FuelTax = amt_A;//燃油费 // CabinPriceInfo.zValue = zValue;//代理人Z值 // model.listCabinPriceInfo.Add(CabinPriceInfo); // } //} list.Add(model); } } } } } string strJson = JsonConvert.SerializeObject(list); //string strZip = ZipHelper.GZipCompressString(strJson); Response.Write(strJson); } } }
//序号 public string rPH { get; set; } //出发日期 public string dt { get; set; } //航公司两字码 public string Carrier { get; set; } //航班号 public string Airline { get; set; } //起飞城市 public string Orgcity { get; set; } //起飞时刻 public string Deptime { get; set; } //到达城市 public string Dstcity { get; set; } //到达时刻 public string Arritime { get; set; } //机型 public string Planestyle { get; set; } //经停次数 public int Stopnumber { get; set; } //起飞航站楼 public string DepTermAndArriTerm { get; set; } //达到航站楼 public string arrTermAndArriTerm { get; set; } //餐食 public string Meal { get; set; } //代码共享 public int tpm { get; set; } //舱位信息与价格信息 public List<myCabinPriceInfo> listCabinPriceInfo { get; set; }
//舱位信息与价格信息 listCabinpriceInfo类字段 /// <summary> /// 舱位编号 /// </summary> public string CabinNo { get; set; } /// <summary> /// 舱位可用数量 /// </summary> public string CabinInfo { get; set; } /// <summary> /// 价格 /// </summary> public string Price { get; set; } /// <summary> /// 货币类型 /// </summary> public string disCurrCode { get; set; } /// <summary> /// 机建 /// </summary> public string AirportTax { get; set; } /// <summary> /// 燃油 /// </summary> public string FuelTax { get; set; } /// <summary> /// 代理人费率 /// </summary> public string zValue { get; set; } /// <summary> /// 折扣率 /// </summary> public string DisCount { get; set; } /// <summary> /// 去程回程标志,O 代表去程,I 代表回程 /// </summary> public string OI { get; set; }
标签:
原文地址:http://blog.csdn.net/qq_30079853/article/details/51452228