use of org.apache.http.message.BasicNameValuePair in project 12306-hunter by xautlx.
the class HttpClientService method submitOrderRequest.
public void submitOrderRequest(SingleTrainOrderVO singleTrainOrderVO) {
String title = "[登录用户:" + singleTrainOrderVO.getLoginUser() + "] ";
HttpClient httpClient = buildHttpClient();
TrainQueryInfo trainQueryInfo = singleTrainOrderVO.getTrainQueryInfo();
try {
// 提交预定的车次 一共25个参数
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair(ORDER_ARRIVE_TIME, trainQueryInfo.getEndTime()));
parameters.add(new BasicNameValuePair(ORDER_FROM_STATION_NAME, trainQueryInfo.getFromStation()));
parameters.add(new BasicNameValuePair(ORDER_FROM_STATION_NO, trainQueryInfo.getFormStationNo()));
parameters.add(new BasicNameValuePair(ORDER_FROM_STATION_TELECODE, trainQueryInfo.getFromStationCode()));
parameters.add(new BasicNameValuePair(ORDER_FROM_STATION_TELECODE_NAME, trainQueryInfo.getFromStationName()));
parameters.add(new BasicNameValuePair(ORDER_INCLUDE_STUDENT, "00"));
parameters.add(new BasicNameValuePair(ORDER_LISHI, trainQueryInfo.getTakeTime()));
parameters.add(new BasicNameValuePair(ORDER_LOCATIONCODE, trainQueryInfo.getLocationCode()));
parameters.add(new BasicNameValuePair(ORDER_MMSTR, trainQueryInfo.getMmStr()));
parameters.add(new BasicNameValuePair(ORDER_ROUND_START_TIME_STR, "00:00--24:00"));
parameters.add(new BasicNameValuePair(ORDER_ROUND_TRAIN_DATE, singleTrainOrderVO.getTrainDate()));
parameters.add(new BasicNameValuePair(ORDER_SEATTYPE_NUM, ""));
parameters.add(new BasicNameValuePair(ORDER_SINGLE_ROUND_TYPE, trainQueryInfo.getSingle_round_type()));
parameters.add(new BasicNameValuePair(ORDER_START_TIME_STR, "00:00--24:00"));
parameters.add(new BasicNameValuePair(ORDER_STATION_TRAIN_CODE, trainQueryInfo.getTrainNo()));
parameters.add(new BasicNameValuePair(ORDER_TO_STATION_NAME, trainQueryInfo.getToStation()));
parameters.add(new BasicNameValuePair(ORDER_TO_STATION_NO, trainQueryInfo.getToStationNo()));
parameters.add(new BasicNameValuePair(ORDER_TO_STATION_TELECODE, trainQueryInfo.getToStationCode()));
parameters.add(new BasicNameValuePair(ORDER_TO_STATION_TELECODE_NAME, trainQueryInfo.getToStationName()));
parameters.add(new BasicNameValuePair(ORDER_TRAIN_CLASS_ARR, "QB#D#Z#T#K#QT#"));
parameters.add(new BasicNameValuePair(ORDER_TRAIN_DATE, singleTrainOrderVO.getTrainDate()));
parameters.add(new BasicNameValuePair(ORDER_TRAIN_PASS_TYPE, "QB"));
parameters.add(new BasicNameValuePair(ORDER_TRAIN_START_TIME, trainQueryInfo.getStartTime()));
parameters.add(new BasicNameValuePair(ORDER_TRAINNO4, trainQueryInfo.getTrainno4()));
parameters.add(new BasicNameValuePair(ORDER_YPINFODETAIL, trainQueryInfo.getYpInfoDetail()));
TicketMainFrame.appendMessage(title + "提交订票请求, 车次:" + singleTrainOrderVO.getTrainNo() + ",席别:" + singleTrainOrderVO.getSeatType());
HttpResponse response = postHttpRequest(httpClient, POST_URL_SUBMUTORDERREQUEST, parameters, singleTrainOrderVO.getCookieData());
int statusCode = response.getStatusLine().getStatusCode();
// 返回码 301 或 302 转发到location的新地址
if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
Header locationHeader = response.getFirstHeader("location");
String redirectUrl = locationHeader.getValue();
TicketMainFrame.appendMessage(title + "订票请求响应代码:" + statusCode + ", 转向获取订票凭证数据");
logger.debug("Response StatusCode: " + statusCode, "Redirect to URL: " + redirectUrl);
HttpClient httpClient2 = buildHttpClient();
String responseBody = postHttpRequestAsString(httpClient2, redirectUrl, null, singleTrainOrderVO.getCookieData());
httpClient2.getConnectionManager().shutdown();
String leftTicketStr = TicketUtil.getCredential(responseBody);
if (StringUtils.isBlank(leftTicketStr)) {
throw new IllegalArgumentException(title + "未取到有效的leftTicketStr数据");
} else {
TicketMainFrame.appendMessage(title + "成功获取到leftTicketStr凭证数据:" + leftTicketStr);
}
singleTrainOrderVO.setSubmitOrderRequestLeftTicketStr(leftTicketStr);
String token = TicketUtil.getToken(responseBody);
if (StringUtils.isBlank(leftTicketStr)) {
throw new IllegalArgumentException(title + "未取到有效的token数据");
} else {
TicketMainFrame.appendMessage(title + "成功获取到Token凭证数据:" + token);
}
singleTrainOrderVO.setSubmitOrderRequestToken(token);
}
} finally {
httpClient.getConnectionManager().shutdown();
}
}
use of org.apache.http.message.BasicNameValuePair in project 12306-hunter by xautlx.
the class HttpClientService method Login.
public boolean Login(String loginUser, String loginPasswd, String loginCode, Map<String, String> cookieData) {
HttpClient httpClient = buildHttpClient();
try {
String loginRand = this.loginAysnSuggest(loginUser, loginPasswd, loginCode, cookieData);
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair(LOGIN_LOGINRAND, loginRand));
parameters.add(new BasicNameValuePair(LOGIN_USERNAME, loginUser));
parameters.add(new BasicNameValuePair(LOGIN_NAMEERRORFOCUS, ""));
parameters.add(new BasicNameValuePair(LOGIN_PASSWORDERRORFOCUS, ""));
parameters.add(new BasicNameValuePair(LOGIN_RANDCODE, loginCode));
parameters.add(new BasicNameValuePair(LOGIN_RANDERRORFOCUS, ""));
parameters.add(new BasicNameValuePair(LOGIN_REFUNDFLAG, "Y"));
parameters.add(new BasicNameValuePair(LOGIN_REFUNDLOGIN, "N"));
parameters.add(new BasicNameValuePair(LOGIN_PASSWORD, loginPasswd));
String responseHTML = postHttpRequestAsString(httpClient, POST_UTL_LOGINACTION, parameters, cookieData);
if (responseHTML.contains("欢迎您登录中国铁路客户服务中心网站")) {
TicketMainFrame.appendMessage("用户[" + loginUser + "]登录成功");
return true;
} else {
TicketMainFrame.appendMessage("用户[" + loginUser + "]登录失败,请查看详细的日志输出");
logger.error(" + Response ERROR HTML:\n" + responseHTML);
return false;
}
} finally {
httpClient.getConnectionManager().shutdown();
}
}
use of org.apache.http.message.BasicNameValuePair in project 12306-hunter by xautlx.
the class HttpClientService method confirmSingleForQueueOrder.
public String confirmSingleForQueueOrder(TicketData ticketData, SingleTrainOrderVO singleTrainOrderVO, String randCode, boolean justCheck) {
String title = "[登录用户:" + singleTrainOrderVO.getLoginUser() + "] ";
HttpClient httpClient = buildHttpClient();
TrainQueryInfo trainQueryInfo = singleTrainOrderVO.getTrainQueryInfo();
try {
String url = null;
if (justCheck) {
url = POST_URL_CHECKORDERINFO + randCode;
} else {
url = POST_URL_CONFIRMSINGLEFORQUEUE;
}
List<PassengerData> validPassengerDatas = ticketData.getValidPassengerDatas();
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
for (int i = 0; i < validPassengerDatas.size(); i++) {
parameters.add(new BasicNameValuePair("checkbox" + i, Integer.toString(i)));
}
parameters.add(new BasicNameValuePair("checkbox9", "Y"));
parameters.add(new BasicNameValuePair("checkbox9", "Y"));
parameters.add(new BasicNameValuePair("checkbox9", "Y"));
parameters.add(new BasicNameValuePair("checkbox9", "Y"));
parameters.add(new BasicNameValuePair("checkbox9", "Y"));
parameters.add(new BasicNameValuePair(SUBMIT_LEFTTICKETSTR, singleTrainOrderVO.getSubmitOrderRequestLeftTicketStr()));
for (int i = 0; i < validPassengerDatas.size(); i++) {
parameters.add(new BasicNameValuePair(SUBMIT_OLDPASSENGERS, validPassengerDatas.get(i).getShortText()));
}
for (int i = 0; i < (5 - validPassengerDatas.size()); i++) {
parameters.add(new BasicNameValuePair(SUBMIT_OLDPASSENGERS, ""));
}
parameters.add(new BasicNameValuePair(SUBMIT_BED_LEVEL_ORDER_NUM, "000000000000000000000000000000"));
parameters.add(new BasicNameValuePair(SUBMIT_CANCEL_FLAG, "1"));
parameters.add(new BasicNameValuePair(SUBMIT_END_TIME, trainQueryInfo.getEndTime()));
parameters.add(new BasicNameValuePair(SUBMIT_FROM_STATION_NAME, trainQueryInfo.getFromStation()));
parameters.add(new BasicNameValuePair(SUBMIT_FROM_STATION_TELECODE, trainQueryInfo.getFromStationCode()));
parameters.add(new BasicNameValuePair(SUBMIT_ID_MODE, "Y"));
parameters.add(new BasicNameValuePair(SUBMIT_RESERVE_FLAG, "A"));
parameters.add(new BasicNameValuePair(SUBMIT_TO_SEAT_TYPE_CODE, ""));
parameters.add(new BasicNameValuePair(SUBMIT_START_TIME, trainQueryInfo.getStartTime()));
parameters.add(new BasicNameValuePair(SUBMIT_STATION_TRAIN_CODE, trainQueryInfo.getTrainNo()));
parameters.add(new BasicNameValuePair(SUBMIT_TICKET_TYPE_ORDER_NUM, ""));
parameters.add(new BasicNameValuePair(SUBMIT_TO_STATION_NAME, trainQueryInfo.getToStation()));
parameters.add(new BasicNameValuePair(SUBMIT_TO_STATION_TELECODE, trainQueryInfo.getToStationCode()));
parameters.add(new BasicNameValuePair(QUERY_TRAIN_DATE, singleTrainOrderVO.getTrainDate()));
parameters.add(new BasicNameValuePair(QUERY_TRAIN_NO, trainQueryInfo.getTrainno4()));
parameters.add(new BasicNameValuePair(SUBMIT_TOKEN, singleTrainOrderVO.getSubmitOrderRequestToken()));
for (int i = 0; i < validPassengerDatas.size(); i++) {
parameters.add(new BasicNameValuePair(SUBMIT_PASSENGERTICKETS, validPassengerDatas.get(i).getLongText(singleTrainOrderVO.getSeatType())));
parameters.add(new BasicNameValuePair("passenger_" + (i + 1) + "_cardno", validPassengerDatas.get(i).getCardNo()));
parameters.add(new BasicNameValuePair("passenger_" + (i + 1) + "_cardtype", validPassengerDatas.get(i).getCardType().getValue()));
parameters.add(new BasicNameValuePair("passenger_" + (i + 1) + "_mobileno", validPassengerDatas.get(i).getMobile()));
parameters.add(new BasicNameValuePair("passenger_" + (i + 1) + "_name", validPassengerDatas.get(i).getName()));
parameters.add(new BasicNameValuePair("passenger_" + (i + 1) + "_seat", singleTrainOrderVO.getSeatType().getValue()));
parameters.add(new BasicNameValuePair("passenger_" + (i + 1) + "_ticket", validPassengerDatas.get(i).getTicketType().getValue()));
}
parameters.add(new BasicNameValuePair(SUBMIT_RANDCODE, randCode));
// 检查订单
if (justCheck) {
parameters.add(new BasicNameValuePair(SUBMIT_TFLAG, "dc"));
}
parameters.add(new BasicNameValuePair(SUBMIT_TEXTFIELD, "中文或拼音首字母"));
TicketMainFrame.appendMessage(title + "提交订单, 车次:" + singleTrainOrderVO.getTrainNo() + ",席别:" + singleTrainOrderVO.getSeatType() + ",日期:" + singleTrainOrderVO.getTrainDate());
String responseBody = postHttpRequestAsString(httpClient, url, parameters, singleTrainOrderVO.getCookieData());
return responseBody;
} finally {
httpClient.getConnectionManager().shutdown();
}
}
use of org.apache.http.message.BasicNameValuePair in project 12306-hunter by xautlx.
the class HttpClientService method main.
/**
* @param args
*/
public static void main(String[] args) {
HttpClientService httpClientService = new HttpClientService();
//httpClientService.initCookie();
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair(GETQUEUECOUNT_FROM, "BPX"));
parameters.add(new BasicNameValuePair(GETQUEUECOUNT_SEAT, "4"));
parameters.add(new BasicNameValuePair(GETQUEUECOUNT_STATION, "Z3"));
parameters.add(new BasicNameValuePair(GETQUEUECOUNT_TICKET, "40484502902027450262"));
parameters.add(new BasicNameValuePair(GETQUEUECOUNT_TO, "JBN"));
parameters.add(new BasicNameValuePair(GETQUEUECOUNT_TRAIN_DATE, "2013-11-21"));
parameters.add(new BasicNameValuePair(GETQUEUECOUNT_TRAIN_NO, "24000000Z306"));
Map<String, String> cookieData = new HashMap<String, String>();
cookieData.put("JSESSIONID", "81BFCA3C5F2AE80241FD81E7AA23B410");
cookieData.put("BIGipServerotsweb", "2262040842.48160.0000");
httpClientService.getHttpRequestAsString(buildHttpClient(), GET_URL_GETQUEUECOUNT, parameters, cookieData);
}
use of org.apache.http.message.BasicNameValuePair in project 12306-hunter by xautlx.
the class HttpClientService method getQueueCount.
public String getQueueCount(TicketData ticketData, SingleTrainOrderVO singleTrainOrderVO) {
String title = "[登录用户:" + singleTrainOrderVO.getLoginUser() + "] ";
HttpClient httpClient = buildHttpClient();
TrainQueryInfo trainQueryInfo = singleTrainOrderVO.getTrainQueryInfo();
try {
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair(GETQUEUECOUNT_FROM, ticketData.getTrainFromCode()));
parameters.add(new BasicNameValuePair(GETQUEUECOUNT_SEAT, singleTrainOrderVO.getSeatType().getValue()));
parameters.add(new BasicNameValuePair(GETQUEUECOUNT_STATION, trainQueryInfo.getTrainNo()));
parameters.add(new BasicNameValuePair(GETQUEUECOUNT_TICKET, singleTrainOrderVO.getSubmitOrderRequestLeftTicketStr()));
parameters.add(new BasicNameValuePair(GETQUEUECOUNT_TO, ticketData.getTrainToCode()));
parameters.add(new BasicNameValuePair(GETQUEUECOUNT_TRAIN_DATE, singleTrainOrderVO.getTrainDate()));
parameters.add(new BasicNameValuePair(GETQUEUECOUNT_TRAIN_NO, trainQueryInfo.getTrainno4()));
TicketMainFrame.appendMessage(title + "下单余票数查询请求, 车次:" + singleTrainOrderVO.getTrainNo() + ",席别:" + singleTrainOrderVO.getSeatType());
String response = getHttpRequestAsString(httpClient, GET_URL_GETQUEUECOUNT, parameters, singleTrainOrderVO.getCookieData());
return response;
} finally {
httpClient.getConnectionManager().shutdown();
}
}
Aggregations