聚合数据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_Sparameters:@{@"name":@"G4",@"dtype":@"json" }];


/* 2、站到站查询 */

[self test :kJHAPIS_LIFE_TRAIN_S2Sparameters:@{@"start":@"上海虹桥",@"end":@"苏州园区" }];

/* 3、12306实时余票查询 */
[self test :kJHAPIS_LIFE_TRAIN_YP parameters:@{@"from":@"上海虹桥",@"to":@"温州南" }];

/* 4、12306订票①:查询车次 */
[self test :kJHAPIS_LIFE_TRAIN_TICKET_CC parameters:@{@"from":@"上海虹桥",255);">/* 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

相关文章

迭代器模式(Iterator)迭代器模式(Iterator)[Cursor]意图...
高性能IO模型浅析服务器端编程经常需要构造高性能的IO模型,...
策略模式(Strategy)策略模式(Strategy)[Policy]意图:定...
访问者模式(Visitor)访问者模式(Visitor)意图:表示一个...
命令模式(Command)命令模式(Command)[Action/Transactio...
生成器模式(Builder)生成器模式(Builder)意图:将一个对...