溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

聚合數(shù)據(jù)iOS SDK 12306火車票查詢訂票演示示例

發(fā)布時(shí)間:2020-04-09 19:05:32 來源:網(wǎng)絡(luò) 閱讀:376 作者:SorosW 欄目:移動(dòng)開發(fā)

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


聚合數(shù)據(jù)iOS SDK 12306火車票查詢訂票演示示例


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

/* 12306火車票查詢訂票 */
/**
@brief 2306火車票查詢訂票--1、車次查詢
@param lname string 必填 車次名稱,如:G4
@param ldtype string 非必填 返回?cái)?shù)據(jù)的格式,xml或json,默認(rèn)json
*/
#define kJHAPIS_LIFE_TRAIN_S @"juhe.apis.train.s" //1、車次查詢

/**
@brief 12306火車票查詢訂票--2、站到站查詢
@param start string 必填 出發(fā)站
@param end string 必填 終點(diǎn)站
@param traintype string 非必填 列車類型,G-高速動(dòng)車 K-快速 T-空調(diào)特快 D-動(dòng)車組 Z-直達(dá)特快 Q-其他
@param dtype string 非必填 返回?cái)?shù)據(jù)的格式,xml或json,默認(rèn)json
*/
#define kJHAPIS_LIFE_TRAIN_S2S @"juhe.apis.train.s2s" //2、站到站查詢

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

/**
@brief 12306火車票查詢訂票--4、12306訂票①:查詢車次
@param from string 必填 出發(fā)站名稱:如上海虹橋
@param to string 必填 到達(dá)站名稱:如溫州南
@param date date 非必填 默認(rèn)當(dāng)天,格式:2014-07-11
@param tt string 非必填 車次類型,默認(rèn)全部,如:G(高鐵)、D(動(dòng)車)、T(特快)、Z(直達(dá))、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 必填 座位類型:商務(wù)座:9,一等座:M,二等座:O,特等座:P,高級(jí)軟臥:6,軟臥:4,硬臥:3,軟座:2,硬座:1,無座:0
@param mobile string 必填 乘客手機(jī)號(hào)碼
@param idcard string 必填 乘客***號(hào)碼
@param username string 必填 12306官網(wǎng)賬號(hào)
@param password string 必填 12306官網(wǎng)密碼
@param train_no string 必填 步驟①對(duì)應(yīng)車次返回值
@param station_train_code string 必填 步驟①對(duì)應(yīng)車次返回值
@param from_station_telecode string 必填 步驟①對(duì)應(yīng)車次返回值
@param to_station_telecode string 必填 步驟①對(duì)應(yīng)車次返回值
@param from_station_name string 必填 步驟①對(duì)應(yīng)車次返回值
@param to_station_name string 必填 步驟①對(duì)應(yīng)車次返回值
@param secretStr string 必填 步驟①對(duì)應(yīng)車次返回值
*/
#define kJHAPIS_LIFE_TRAIN_TICKET_ORDER @"juhe.apis.train.ticket.order" //5、12306訂票②:提交訂單



3,快遞查詢接口在程序中調(diào)用方法(將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:@"申請(qǐng)到的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 p_w_picpathNamed:@"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":@"蘇州園區(qū)" }];


/* 3、12306實(shí)時(shí)余票查詢 */
[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":@"乘客手機(jī)號(hào)碼" , @"idcard":@"乘客***號(hào)碼" , @"username":@"12306官網(wǎng)賬號(hào)" ,@"password":@"12306官網(wǎng)密碼" , @"train_no":@"步驟①對(duì)應(yīng)車次返回值" , @"station_train_code":@"步驟①對(duì)應(yīng)車次返回值" , @"from_station_telecod":@"步驟①對(duì)應(yīng)車次返回值" } ] ;


}

- (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火車票查詢訂票接口返回?cái)?shù)據(jù)說明以及錯(cuò)誤碼說明

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

返回字段:

聚合數(shù)據(jù)iOS SDK 12306火車票查詢訂票演示示例

2、站到站查詢 

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

返回字段 :

聚合數(shù)據(jù)iOS SDK 12306火車票查詢訂票演示示例

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

返回字段 :

聚合數(shù)據(jù)iOS SDK 12306火車票查詢訂票演示示例

聚合數(shù)據(jù)iOS SDK 12306火車票查詢訂票演示示例


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

返回字段:

聚合數(shù)據(jù)iOS SDK 12306火車票查詢訂票演示示例

聚合數(shù)據(jù)iOS SDK 12306火車票查詢訂票演示示例

聚合數(shù)據(jù)iOS SDK 12306火車票查詢訂票演示示例

聚合數(shù)據(jù)iOS SDK 12306火車票查詢訂票演示示例

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

返回字段 :

聚合數(shù)據(jù)iOS SDK 12306火車票查詢訂票演示示例

6. 12306 火車票查詢訂票錯(cuò)誤碼



聚合數(shù)據(jù)iOS SDK 12306火車票查詢訂票演示示例


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI