1.聚合SDK是聚合数据平台,为移动开发者提供的免费数据接口.使用前请先到聚合平台(http://www.juhe.cn/)注册,申请相关数据.

2.下载聚合数据SDK,将开发包里的juhe_sdk_v_1_1.jar拷贝到libs根目录下,将libJuheSDK_v_1_0.so拷贝到libs\armeabi目录下,如图:


3. 根据接口说明文档找到以下方法:

Java代码

/**

*获取车次

*

*@paramname

*车次

*@paramjsonCallBack

*/

publicvoidgetTrainNum(Stringname,JsonCallBackjsonCallBack)

/**

*站到站查询

*

*@paramstart

*出发站

*@paramend

*终点站

*@paramtraintype

*列车类型

*@paramjsonCallBack

*/

publicvoidgetS2S(Stringstart,Stringend,Stringtraintype,JsonCallBackjsonCallBack)

/**

*12306实时余票查询

*

*@paramfrom

*出发站

*@paramto

*到达站

*@paramdate

*出发日期默认今天

*@paramtraintype

*车次类型

*@paramjsonCallBack

*/

publicvoidgetTicketleft(Stringfrom,Stringto,Stringdate,Stringtraintype,JsonCallBackjsonCallBack)

/**

*12306订票①:查询车次

*

*@paramfrom

*出发站

*@paramto

*到达站

*@paramdate

*出发日期

*@paramtraintype

*车次类型

*@paramjsonCallBack

*/

publicvoidbookTrainNum(Stringfrom,Stringto,Stringdate,Stringtraintype,JsonCallBackjsonCallBack)

/**

*

*@paramname

*乘客姓名

*@paramseat

*座位类型:商务座:9,一等座:M,二等座:O,特等座:P,高级软卧:6,软卧:4,硬卧:3,软座:2,硬座:1,无座:0

*@parammobile

*乘客手机号码

*@paramidcard

*乘客***号码

*@paramusername

*12306官网账号

*@parampassword

*12306官网密码

*@paramtrain_no

*步骤①对应车次返回值

*@paramstation_train_code

*步骤①对应车次返回值

*@paramfrom_station_telecode

*步骤①对应车次返回值

*@paramto_station_telecode

*步骤①对应车次返回值

*@paramfrom_station_name

*步骤①对应车次返回值

*@paramto_station_name

*步骤①对应车次返回值

*@paramsecretStr

*步骤①对应车次返回值

*@paramjsonCallBack

*/

publicvoidbookTicket(Stringname,Stringseat,Stringmobile,Stringidcard,Stringusername,Stringpassword,Stringtrain_no,Stringstation_train_code,Stringfrom_station_telecode,Stringto_station_telecode,Stringfrom_station_name,Stringto_station_name,StringsecretStr,JsonCallBackjsonCallBack)



4.程序中调用方法


首先,在AnroidManifest.xml中添加权限


Html代码

<uses-permissionandroid:name="android.permission.READ_PHONE_STATE"/>

<uses-permissionandroid:name="android.permission.INTERNET"/>

<uses-permissionandroid:name="android.permission.ACCESS_NETWORK_STATE"/>

<uses-permissionandroid:name="android.permission.ACCESS_WIFI_STATE"/>

<uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-permissionandroid:name="android.permission.READ_CONTACTS"/>


在application标签内部加入你申请的openid


Html代码

<meta-data

android:name="com.thinkland.juheapi.openid"

android:value="申请的openid"/>


在使用前需要调用一次初始化方法


Java代码

CommonFun.initialize(getApplicationContext());



导入相关包


Java代码

importcom.thinkland.juheapi.common.CommonFun;

importcom.thinkland.juheapi.common.JsonCallBack;

importcom.thinkland.juheapi.data.train.TrainData;





调用方法

Java代码

//站站查询

TrainDatatrainData=TrainData.getInstance();

trainData.getS2S("上海虹桥","苏州园区","G",newJsonCallBack(){

@Override

publicvoidjsonLoaded(JSONObjectarg0){

//TODOAuto-generatedmethodstub

try{

intresultcode=arg0.getInt("resultcode");

if(resultcode==200){

JSONArrayresultJson=arg0.getJSONArray("result");

}

}catch(JSONExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

}

});





5.返回字段及相关错误码


publicvoidgetTrainNum(Stringname, JsonCallBackjsonCallBack)

返回字段:

publicvoidgetS2S(Stringstart,Stringend, Stringtraintype,JsonCallBackjsonCallBack)

返回字段:

publicvoidgetTicketleft(Stringfrom, Stringto,Stringdate, Stringtraintype,JsonCallBackjsonCallBack)

返回字段:

publicvoidbookTrainNum(Stringfrom, Stringto,Stringdate,Stringtraintype, JsonCallBackjsonCallBack)

返回值:

publicvoidbookTicket(Stringname, Stringseat, Stringmobile,

Stringidcard, Stringusername, Stringpassword, Stringtrain_no,

Stringstation_train_code, Stringfrom_station_telecode,

Stringto_station_telecode, Stringfrom_station_name,

Stringto_station_name, StringsecretStr, JsonCallBackjsonCallBack)

返回码: