聚合數據iOS SDK 12306火車票查詢訂票演示示例

1,將聚合數據SDK(JuheApis.framework)添加到你的程序中來,SDK依賴的包包括:



2,在聚合SDK Framework的JHSDKAPIPath.h文件中找到快遞查詢接口宏,以及字典參數

/* 12306火車票查詢訂票 */
/**
@brief 2306火車票查詢訂票--1、車次查詢
@param lname string 必填 車次名稱,如:G4
@param ldtype string 非必填 返回數據的格式,xml或json,默認json
*/
#define kJHAPIS_LIFE_TRAIN_S @"juhe.apis.train.s" //1、車次查詢

/**
@brief 12306火車票查詢訂票--2、站到站查詢
@param start string 必填 出發站
@param end string 必填 終點站
@param traintype string 非必填 列車類型,G-高速動車 K-快速 T-空調特快 D-動車組 Z-直達特快 Q-其他
@param dtype string 非必填 返回數據的格式,xml或json,默認json
*/
#define kJHAPIS_LIFE_TRAIN_S2S @"juhe.apis.train.s2s" //2、站到站查詢

/**
@brief 12306火車票查詢訂票--3、12306實時餘票查詢
@param dtype string 非必填 返回數據的格式,xml或json,默認json
@param from string 必填 出發站,如:上海虹橋
@param to string 必填 到達站,如:溫州南
@param date string 非必填 出發日期,默認今日
@param tt string 非必填 車次類型,默認全部,如:G(高鐵)、D(動車)、T(特快)、Z(直達)、K(快速)、Q(其他)
*/
#define kJHAPIS_LIFE_TRAIN_YP @"juhe.apis.train.yp" //3、12306實時餘票查詢

/**
@brief 12306火車票查詢訂票--4、12306訂票①:查詢車次
@param from string 必填 出發站名稱:如上海虹橋
@param to string 必填 到達站名稱:如溫州南
@param date date 非必填 默認當天,格式:2014-07-11
@param tt string 非必填 車次類型,默認全部,如:G(高鐵)、D(動車)、T(特快)、Z(直達)、K(快速)、Q(其他)
*/
#define kJHAPIS_LIFE_TRAIN_TICKET_CC @"juhe.apis.train.ticket.cc" //4、12306訂票①:查詢車次

/**
@brief 12306火車票查詢訂票--5、12306訂票②:提交訂單
@param name string 必填 乘客姓名
@param seat string 必填 座位類型:商務座:9,一等座:M,二等座:O,特等座:P,高級軟臥:6,軟臥:4,硬臥:3,軟座:2,硬座:1,無座:0
@param mobile string 必填 乘客手機號碼
@param idcard string 必填 乘客***號碼
@param username string 必填 12306官網賬號
@param password string 必填 12306官網密碼
@param train_no string 必填 步驟①對應車次返回值
@param station_train_code string 必填 步驟①對應車次返回值
@param from_station_telecode string 必填 步驟①對應車次返回值
@param to_station_telecode string 必填 步驟①對應車次返回值
@param from_station_name string 必填 步驟①對應車次返回值
@param to_station_name string 必填 步驟①對應車次返回值
@param secretStr string 必填 步驟①對應車次返回值
*/
#define kJHAPIS_LIFE_TRAIN_TICKET_ORDER @"juhe.apis.train.ticket.order" //5、12306訂票②:提交訂單



3,快遞查詢接口在程序中調用方法(將ViewController.m改爲.mm)

#import "ViewController.h"

#import <JuheApis/JuheAPI.h>
#import <JuheApis/JHOpenidSupplier.h>
#import <JuheApis/JHSDKAPIPath.h>

@interface ViewController ()
@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[JHOpenidSupplier shareSupplier] registerJuheAPIByOpenId:@"申請到的OpenId“];

UIButton* beginBtn=[UIButton buttonWithType:UIButtonTypeSystem];
beginBtn.frame=CGRectMake(20, 111, 280, 40);
[beginBtn setTitle:@"開始" forState:UIControlStateNormal];
[beginBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
[beginBtn addTarget:self action:@selector(doTestAction) forControlEvents:UIControlEventTouchUpInside];
[beginBtn setBackgroundImage:[UIImage imageNamed:@"button5"] forState:UIControlStateNormal];
[self.view addSubview:beginBtn];
}

- (void)doTestAction
{
/* 1、車次查詢 */
[self test : kJHAPIS_LIFE_TRAIN_S parameters:@{@"name":@"G4" , @"dtype":@"json" }];


/* 2、站到站查詢 */

[self test :kJHAPIS_LIFE_TRAIN_S2S parameters:@{@"start":@"上海虹橋" , @"end":@"蘇州園區" }];


/* 3、12306實時餘票查詢 */
[self test :kJHAPIS_LIFE_TRAIN_YP parameters:@{@"from":@"上海虹橋" , @"to":@"溫州南" }];


/* 4、12306訂票①:查詢車次 */
[self test :kJHAPIS_LIFE_TRAIN_TICKET_CC parameters:@{@"from":@"上海虹橋" , @"to":@"溫州南" }];


/* 5、12306訂票②:提交訂單 */
[self test :kJHAPIS_LIFE_TRAIN_TICKET_ORDER parameters:@{@"name":@"乘客姓名" , @"seat":@"O" , @"mobile":@"乘客手機號碼" , @"idcard":@"乘客***號碼" , @"username":@"12306官網賬號" ,@"password":@"12306官網密碼" , @"train_no":@"步驟①對應車次返回值" , @"station_train_code":@"步驟①對應車次返回值" , @"from_station_telecod":@"步驟①對應車次返回值" } ] ;


}

- (void)test:(NSString *)path parameters:(NSDictionary *)parameters{

JuheAPI *juheapi = [JuheAPI shareJuheApi];
[juheapi executeWorkWithAPI:path
parameters:parameters
success:^(id responseObject){
if ([[parameters objectForKey:@"dtype"] isEqualToString:@"xml"]) {
NSLog(@"***xml*** \n %@", responseObject);
}else{
int error_code = [[responseObject objectForKey:@"error_code"] intValue];
if (!error_code) {
NSLog(@" %@", responseObject);
}else{
NSLog(@" %@", responseObject);
}
}

} failure:^(NSError *error) {
NSLog(@"error: %@",error.description);
}];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end


4,12306火車票查詢訂票接口返回數據說明以及錯誤碼說明

1、車次查詢 
API :juhe.apis.train.s (宏 : kJHAPIS_LIFE_TRAIN_S) 

返回字段:

wKioL1Q4neuSWJymAALCHMr6JNE943.jpg

2、站到站查詢 

API :juhe.apis.train.s2s (宏 : kJHAPIS_LIFE_TRAIN_S2S) 

返回字段 :

wKiom1Q4nbTDbqUuAAGqHg70miw245.jpg

3、12306實時餘票查詢
API :juhe.apis.train.yp (宏 : kJHAPIS_LIFE_TRAIN_YP ) 

返回字段 :

wKioL1Q4nmPjPiwrAAH4-CGvOK4291.jpg

wKiom1Q4niyBdMoJAAEw86mQpFk603.jpg


4、12306訂票①:查詢車次 
API :juhe.apis.train.ticket.cc (宏 : kJHAPIS_LIFE_TRAIN_TICKET_CC ) 

返回字段:

wKioL1Q4nufQrLTPAAHjNT6iet0358.jpg

wKioL1Q4nueA7sJtAAFZA23OIUc481.jpg

wKiom1Q4nrDwshW_AAFyY1_JjMA531.jpg

wKiom1Q4nrDQYzL6AADV-UDjtOw523.jpg

5、12306訂票②:提交訂單
API :juhe.apis.train.ticket.order (宏 : kJHAPIS_LIFE_TRAIN_TICKET_ORDER )

返回字段 :

wKioL1Q4n0LhxjnTAACKpidAmms232.jpg

6. 12306 火車票查詢訂票錯誤碼



wKiom1Q4nwyA3ewMAAIgo7HZULs886.jpg


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章