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
*列车类型
voidgetS2S(Stringstart,Stringend,Stringtraintype,0);padding:0px;margin:0px;width:auto;border:0px;">*12306实时余票查询
*@paramfrom
*@paramto
*到达站
*@paramdate
*出发日期默认今天
*车次类型
voidgetTicketleft(Stringfrom,Stringto,Stringdate,0);padding:0px;margin:0px;width:auto;border:0px;">*12306订票①:查询车次
*出发日期
voidbookTrainNum(Stringfrom,0);padding:0px;margin:0px;width:auto;border:0px;">*乘客姓名
*@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
voidbookTicket(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)
首先,在AnroidManifest.xml中添加权限
<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
Meta-data
android:name="com.thinkland.juheapi.openid"
android:value="申请的openid"在使用前需要调用一次初始化方法
Java代码
CommonFun.initialize(getApplicationContext()); 导入相关包
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
voidjsonLoaded(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)
返回字段:
void@H_233_502@getS2S(Stringstart,Stringend,62);">traintype,255);">返回字段:
void@H_233_502@getTicketleft(Stringfrom,62);">to,62);">date,255);">返回字段:
void@H_233_502@bookTrainNum(String返回值:
void@H_233_502@bookTicket(Stringseat,62);">mobile,
Stringidcard,62);">username,62);">password,62);">train_no,62);">station_train_code,62);">from_station_telecode,62);">to_station_telecode,62);">from_station_name,62);">to_station_name,62);">secretStr,255);">返回码: