/// 令牌申請
/// </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;
}
/// 賬號激活接口。注意:一個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;激活成功
}
/// 掛起方法接口。注意:掛起帳號,當客戶端需要在另一臺機器使用該帳號時,需要在原機器上進行掛起操作。
/// </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;掛起成功
}
/// 國內預訂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);
}