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)
返回字段:

2、站到站查询 API :juhe.apis.train.s2s (宏 :kJHAPIS_LIFE_TRAIN_S2S)
返回字段 :

3、12306实时余票查询 API :juhe.apis.train.yp (宏 : kJHAPIS_LIFE_TRAIN_YP )
返回字段 :


4、12306订票①:查询车次 API :juhe.apis.train.ticket.cc (宏 : kJHAPIS_LIFE_TRAIN_TICKET_CC )
返回字段:




5、12306订票②:提交订单 API :juhe.apis.train.ticket.order (宏 : kJHAPIS_LIFE_TRAIN_TICKET_ORDER )
返回字段 :

6. 12306 火车票查询订票错误码
 (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|