///
<summary>
/// 令牌申请
/// </summary>
/// <returns></returns>
/// 需要引用的命名空间
/// using com.travelsky.sbeclient.authorization;
/// using com.travelsky.sbeclient;
public string applyToken()
{
string SbeID = " linkoskyTest " ;
string SbePWD = " 123456 " ;
AuthorizationRequest authRequest = new AuthorizationRequest(SbeID, SbePWD);
ApplyTokenClient TokenClient = new ApplyTokenClient();
AuthorizationResponse response = TokenClient.applyToken(authRequest);
string Token = response.token;
return Token;
}
/// 令牌申请
/// </summary>
/// <returns></returns>
/// 需要引用的命名空间
/// using com.travelsky.sbeclient.authorization;
/// using com.travelsky.sbeclient;
public string applyToken()
{
string SbeID = " linkoskyTest " ;
string SbePWD = " 123456 " ;
AuthorizationRequest authRequest = new AuthorizationRequest(SbeID, SbePWD);
ApplyTokenClient TokenClient = new ApplyTokenClient();
AuthorizationResponse response = TokenClient.applyToken(authRequest);
string Token = response.token;
return Token;
}
View Code
///
<summary>
/// 账号激活接口。注意:一个API账号首先需要激活该帐号才能使用。如果API迁移到其它机器上, 需要做挂起/重新激活操作 <br/>
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public void activeAccount()
{
string SbeID = " linkoskyTest " ;
string SbePWD = " 123456 " ;
AccountActiveRequest accountActiveRequest = new AccountActiveRequest(SbeID, SbePWD, " 1 " );
ActiveClient activeClient = new ActiveClient();
SBEResponse response = activeClient.activeAccount(accountActiveRequest);
// response.resultCode == 0;激活成功
}
/// 账号激活接口。注意:一个API账号首先需要激活该帐号才能使用。如果API迁移到其它机器上, 需要做挂起/重新激活操作 <br/>
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public void activeAccount()
{
string SbeID = " linkoskyTest " ;
string SbePWD = " 123456 " ;
AccountActiveRequest accountActiveRequest = new AccountActiveRequest(SbeID, SbePWD, " 1 " );
ActiveClient activeClient = new ActiveClient();
SBEResponse response = activeClient.activeAccount(accountActiveRequest);
// response.resultCode == 0;激活成功
}
View Code
///
<summary>
/// 挂起方法接口。注意:挂起帐号,当客户端需要在另一台机器使用该帐号时,需要在原机器上进行挂起操作。
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public void inactiveAccount()
{
string SbeID = " linkoskyTest " ;
string SbePWD = " 123456 " ;
AccountActiveRequest accountActiveRequest = new AccountActiveRequest(SbeID, SbePWD, " 0 " );
ActiveClient activeClient = new ActiveClient();
SBEResponse response = activeClient.activeAccount(accountActiveRequest);
// response.resultCode == 0;挂起成功
}
/// 挂起方法接口。注意:挂起帐号,当客户端需要在另一台机器使用该帐号时,需要在原机器上进行挂起操作。
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public void inactiveAccount()
{
string SbeID = " linkoskyTest " ;
string SbePWD = " 123456 " ;
AccountActiveRequest accountActiveRequest = new AccountActiveRequest(SbeID, SbePWD, " 0 " );
ActiveClient activeClient = new ActiveClient();
SBEResponse response = activeClient.activeAccount(accountActiveRequest);
// response.resultCode == 0;挂起成功
}
///
<summary>
/// 国内预订PNR创建接口
/// </summary>
public void createDomesticPNR()
{
/// 需要引用的命名空间
// using com.travelsky.sbeclient.obe.request;
// using com.travelsky.sbeclient.obe.book;
// using com.travelsky.sbeclient;
// using com.travelsky.sbeclient.utils;
BookingInfoRequest request = new BookingInfoRequest();
// 联系组
BookContact bookContact = new BookContact();
bookContact.psgId = " 张三 " ; // 联系人(其中一个旅客的名字 )
bookContact.contact = " 13800138000 " ; // 联系电话 必填
request.contact = bookContact;
request.officeNo = " CAN453 " ; //
request.ticketLimit = Convert.ToDateTime( " 2011-08-17 12:00:00 " ).AddDays( - 1 ).ToString( " yyyy-MM-dd hh:mm:ss " ); // 出票时限,一般在航班起飞前一两天
#region SegmentInfo 航段信息 ,航班号、 起飞机场、 到达机场、 舱位、 航班日期必填
int segcount = Convert.ToInt16( " 1 " );
SegmentInfo[] SegmentInfos = new SegmentInfo[segcount];
for ( int i = 0 ; i < segcount; i ++ )
{
SegmentInfo s = new SegmentInfo();
s.flightNo = " CA1310 " ; // 航班号
s.departure = " CAN " ; // 起飞机场(三字代码)
s.arrival = " PEK " ; // 到达机场(三字代码)
string departureTime_str = " 2011-08-17 12:00:00 " ;
if ( ! string .IsNullOrEmpty(departureTime_str))
{
DateTime depTime = Convert.ToDateTime(departureTime_str);
s.departureTime = depTime.ToString( " HH:mm " ); // 航班日期和时间
s.departureDate = depTime.ToString( " yyyy-MM-dd " );
}
string arrivalTime_str = " 2011-08-18 12:00:00 " ;
if ( ! string .IsNullOrEmpty(arrivalTime_str))
{
DateTime arrTime = Convert.ToDateTime(arrivalTime_str);
s.arrivalTime = arrTime.ToString( " HH:mm " ); // 航班日期和时间
s.arrivalDate = arrTime.ToString( " yyyy-MM-dd " );
}
s.cabin = " Y " ; // 舱位 F,C,Y,....航空公司航位
SegmentInfos[i] = s;
}
request.segments = SegmentInfos; // 国内一般是一个或两个(来回程)航段
#endregion
#region PassengerInfo
int psgcount = Convert.ToInt16( " 1 " );
PassengerInfo[] PassengerInfos = new PassengerInfo[psgcount];
for ( int i = 0 ; i < psgcount; i ++ )
{
// 旅客信息 ,婴儿旅客要有出生日期
PassengerInfo psg = new PassengerInfo();
psg.name = " 张三 " ;
psg.gender = " M " ; // M 男,F 女
psg.certType = " NI " ; // NI 身份证,PP 护照,ID其他证件
psg.certNo = " 422322198607061020 " ; // 证件号
psg.psgType = " ADT " ; // ADT成人,CHD儿童,INF婴儿
// 证件为护照时,要出生日期
psg.birthDay = " 1977-08-01 " ;
if ( ! string .IsNullOrEmpty(psg.birthDay) && psg.psgType.Trim() == PassengerInfo.CHILD)
{
int year1 = Convert.ToDateTime(psg.birthDay).Year;
int year2 = DateTime.Now.Year;
psg.age = year2 - year1; // 儿童岁数
}
psg.seat = " NSSB " ; // 座位
psg.meal = " AVML " ; // 食物
psg.fqAirCode = "" ; // 所属航空公司常客
psg.fqNo = "" ; // 常客卡号
PassengerInfos[i] = psg;
// 婴儿不占座,不用设座位和食物
}
request.passengers = PassengerInfos;
#endregion
#region SSRInfo
int ssrcount = Convert.ToInt16( " 1 " );
SSRInfo[] SSRInfos = new SSRInfo[ssrcount];
string ssr_srvcode0 = " AVIH " ;
if ( ! string .IsNullOrEmpty(ssr_srvcode0))
{
for ( int i = 0 ; i < ssrcount; i ++ )
{
SSRInfo ssr = new SSRInfo();
ssr.serveCode = " AVIH " ; // 服务代码
ssr.serveInfo = " SSR内容 " ;
string id = " 1 " ;
if ( ! string .IsNullOrEmpty(id))
{
ssr.segIdx = Convert.ToInt16(id); // 第1个航段
}
ssr.psgName = " 张三 " ;
SSRInfos[i] = ssr;
}
request.ssrs = SSRInfos;
}
// request.ssrs = null;
#endregion
#region OSIInfo
int osicount = Convert.ToInt16( " 1 " );
string airCode0 = " CA " ;
// osi_aircode 为空时,if用来避免异常
if ( ! string .IsNullOrEmpty(airCode0))
{
OSIInfo[] OSIInfos = new OSIInfo[osicount];
for ( int i = 0 ; i < ssrcount; i ++ )
{
OSIInfo osi = new OSIInfo();
string airCode = " CA " ;
osi.airCode = airCode; // 航空公司代码
osi.osi = " osi内容 " ;
osi.psgName = " 张三 " ;
OSIInfos[i] = osi;
}
request.osis = OSIInfos;
}
#endregion
#region RMK
int rmkcount = Convert.ToInt16( " 1 " );
RMKInfo[] RMKInfos = new RMKInfo[rmkcount];
string rmk_info0 = " RMK内容 " ;
if ( ! string .IsNullOrEmpty(rmk_info0))
{
for ( int i = 0 ; i < rmkcount; i ++ )
{
RMKInfo rmk = new RMKInfo();
rmk.rmkInfo = " RMK内容 " ;
rmk.psgName = " 张三 " ;
RMKInfos[i] = rmk;
}
request.rmks = RMKInfos;
}
#endregion
request.token = Client.applyToken( new AuthorizationRequest( " SbeID " , SBEUtil.md5( " SbePWD " ))); ; // 账号需与航信申请;
com.travelsky.sbeclient.obe.CreatePnrClient Client = new com.travelsky.sbeclient.obe.CreatePnrClient();
sbeResponse = Client.createPnr(request);
}
/// 国内预订PNR创建接口
/// </summary>
public void createDomesticPNR()
{
/// 需要引用的命名空间
// using com.travelsky.sbeclient.obe.request;
// using com.travelsky.sbeclient.obe.book;
// using com.travelsky.sbeclient;
// using com.travelsky.sbeclient.utils;
BookingInfoRequest request = new BookingInfoRequest();
// 联系组
BookContact bookContact = new BookContact();
bookContact.psgId = " 张三 " ; // 联系人(其中一个旅客的名字 )
bookContact.contact = " 13800138000 " ; // 联系电话 必填
request.contact = bookContact;
request.officeNo = " CAN453 " ; //
request.ticketLimit = Convert.ToDateTime( " 2011-08-17 12:00:00 " ).AddDays( - 1 ).ToString( " yyyy-MM-dd hh:mm:ss " ); // 出票时限,一般在航班起飞前一两天
#region SegmentInfo 航段信息 ,航班号、 起飞机场、 到达机场、 舱位、 航班日期必填
int segcount = Convert.ToInt16( " 1 " );
SegmentInfo[] SegmentInfos = new SegmentInfo[segcount];
for ( int i = 0 ; i < segcount; i ++ )
{
SegmentInfo s = new SegmentInfo();
s.flightNo = " CA1310 " ; // 航班号
s.departure = " CAN " ; // 起飞机场(三字代码)
s.arrival = " PEK " ; // 到达机场(三字代码)
string departureTime_str = " 2011-08-17 12:00:00 " ;
if ( ! string .IsNullOrEmpty(departureTime_str))
{
DateTime depTime = Convert.ToDateTime(departureTime_str);
s.departureTime = depTime.ToString( " HH:mm " ); // 航班日期和时间
s.departureDate = depTime.ToString( " yyyy-MM-dd " );
}
string arrivalTime_str = " 2011-08-18 12:00:00 " ;
if ( ! string .IsNullOrEmpty(arrivalTime_str))
{
DateTime arrTime = Convert.ToDateTime(arrivalTime_str);
s.arrivalTime = arrTime.ToString( " HH:mm " ); // 航班日期和时间
s.arrivalDate = arrTime.ToString( " yyyy-MM-dd " );
}
s.cabin = " Y " ; // 舱位 F,C,Y,....航空公司航位
SegmentInfos[i] = s;
}
request.segments = SegmentInfos; // 国内一般是一个或两个(来回程)航段
#endregion
#region PassengerInfo
int psgcount = Convert.ToInt16( " 1 " );
PassengerInfo[] PassengerInfos = new PassengerInfo[psgcount];
for ( int i = 0 ; i < psgcount; i ++ )
{
// 旅客信息 ,婴儿旅客要有出生日期
PassengerInfo psg = new PassengerInfo();
psg.name = " 张三 " ;
psg.gender = " M " ; // M 男,F 女
psg.certType = " NI " ; // NI 身份证,PP 护照,ID其他证件
psg.certNo = " 422322198607061020 " ; // 证件号
psg.psgType = " ADT " ; // ADT成人,CHD儿童,INF婴儿
// 证件为护照时,要出生日期
psg.birthDay = " 1977-08-01 " ;
if ( ! string .IsNullOrEmpty(psg.birthDay) && psg.psgType.Trim() == PassengerInfo.CHILD)
{
int year1 = Convert.ToDateTime(psg.birthDay).Year;
int year2 = DateTime.Now.Year;
psg.age = year2 - year1; // 儿童岁数
}
psg.seat = " NSSB " ; // 座位
psg.meal = " AVML " ; // 食物
psg.fqAirCode = "" ; // 所属航空公司常客
psg.fqNo = "" ; // 常客卡号
PassengerInfos[i] = psg;
// 婴儿不占座,不用设座位和食物
}
request.passengers = PassengerInfos;
#endregion
#region SSRInfo
int ssrcount = Convert.ToInt16( " 1 " );
SSRInfo[] SSRInfos = new SSRInfo[ssrcount];
string ssr_srvcode0 = " AVIH " ;
if ( ! string .IsNullOrEmpty(ssr_srvcode0))
{
for ( int i = 0 ; i < ssrcount; i ++ )
{
SSRInfo ssr = new SSRInfo();
ssr.serveCode = " AVIH " ; // 服务代码
ssr.serveInfo = " SSR内容 " ;
string id = " 1 " ;
if ( ! string .IsNullOrEmpty(id))
{
ssr.segIdx = Convert.ToInt16(id); // 第1个航段
}
ssr.psgName = " 张三 " ;
SSRInfos[i] = ssr;
}
request.ssrs = SSRInfos;
}
// request.ssrs = null;
#endregion
#region OSIInfo
int osicount = Convert.ToInt16( " 1 " );
string airCode0 = " CA " ;
// osi_aircode 为空时,if用来避免异常
if ( ! string .IsNullOrEmpty(airCode0))
{
OSIInfo[] OSIInfos = new OSIInfo[osicount];
for ( int i = 0 ; i < ssrcount; i ++ )
{
OSIInfo osi = new OSIInfo();
string airCode = " CA " ;
osi.airCode = airCode; // 航空公司代码
osi.osi = " osi内容 " ;
osi.psgName = " 张三 " ;
OSIInfos[i] = osi;
}
request.osis = OSIInfos;
}
#endregion
#region RMK
int rmkcount = Convert.ToInt16( " 1 " );
RMKInfo[] RMKInfos = new RMKInfo[rmkcount];
string rmk_info0 = " RMK内容 " ;
if ( ! string .IsNullOrEmpty(rmk_info0))
{
for ( int i = 0 ; i < rmkcount; i ++ )
{
RMKInfo rmk = new RMKInfo();
rmk.rmkInfo = " RMK内容 " ;
rmk.psgName = " 张三 " ;
RMKInfos[i] = rmk;
}
request.rmks = RMKInfos;
}
#endregion
request.token = Client.applyToken( new AuthorizationRequest( " SbeID " , SBEUtil.md5( " SbePWD " ))); ; // 账号需与航信申请;
com.travelsky.sbeclient.obe.CreatePnrClient Client = new com.travelsky.sbeclient.obe.CreatePnrClient();
sbeResponse = Client.createPnr(request);
}