From 00f0e50a12ac3fed85982393da66c9e4cb8bcc63 Mon Sep 17 00:00:00 2001 From: zhouyahui Date: Tue, 4 Dec 2018 18:11:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lease/util/VehicleAppraisementUtil.java | 111 ++++++++++-------- 1 file changed, 65 insertions(+), 46 deletions(-) diff --git a/src_tenwa/com/tenwa/lease/util/VehicleAppraisementUtil.java b/src_tenwa/com/tenwa/lease/util/VehicleAppraisementUtil.java index aaa54d9ff..0308a64f8 100644 --- a/src_tenwa/com/tenwa/lease/util/VehicleAppraisementUtil.java +++ b/src_tenwa/com/tenwa/lease/util/VehicleAppraisementUtil.java @@ -5,54 +5,73 @@ import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import org.apache.commons.jexl2.Main; + import com.amarsoft.app.awe.config.InitSecondHandCarConfig; public class VehicleAppraisementUtil { - - public static String getVehicleAppraisementResponse(String modelId,String zone,String regDate,String mile){ - String urlStr = InitSecondHandCarConfig.PREFIX+"/service/getUsedCarPrice?" - +"token="+InitSecondHandCarConfig.TOKEN+"&modelId="+modelId - +"®Date="+regDate+"&mile="+mile+"&zone="+zone+""; - String result = VehicleAppraisementUtil.getResponseResult(urlStr); - return result; + public static void main(String[] args) { + // 二手车prefix,测试http://testapi.che300.com;生产http://api.che300.com + String prefix = "http://testapi.che300.com"; + // 二手车token,测试a6b83424b55410c36415178002f8415e;生产0685c8275534d8d391cdaa5a5cf48c73 + String token = "a6b83424b55410c36415178002f8415e"; + // 二收车参数regDate上牌日期 + String regDate = "2017-12-02"; + // 二收车参数里程数(万公里) + String mile = "10.00"; + // 二收车评估城市区划代码110100北京 + String zone = "110100"; + String urlStr = prefix + "/service/getUsedCarPrice?token=" + token + "&modelId=1128683®Date=" + regDate + + "&mile=" + mile + "&zone=" + zone; + + String result = VehicleAppraisementUtil.getResponseResult(urlStr); + System.out.println(result); + } + + public static String getVehicleAppraisementResponse(String modelId, String zone, String regDate, String mile) { + String urlStr = InitSecondHandCarConfig.PREFIX + "/service/getUsedCarPrice?" + "token=" + + InitSecondHandCarConfig.TOKEN + "&modelId=" + modelId + "®Date=" + regDate + "&mile=" + mile + + "&zone=" + zone + ""; + String result = VehicleAppraisementUtil.getResponseResult(urlStr); + return result; + } + + // 通过请求url返回Json数据 + public static String getResponseResult(String url) { + String line = ""; + String httpResponseResult = ""; + try { + HttpURLConnection connection = VehicleAppraisementUtil.getURLConnection(url); + connection.setReadTimeout(5000); + connection.setConnectTimeout(5000); + connection.connect(); + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8")); + while ((line = reader.readLine()) != null) { + httpResponseResult += line.toString(); } - //通过请求url返回Json数据 - public static String getResponseResult (String url){ - String line = ""; - String httpResponseResult = ""; - try { - HttpURLConnection connection = VehicleAppraisementUtil.getURLConnection(url); - connection.setReadTimeout(5000); - connection.setConnectTimeout(5000); - connection.connect(); - BufferedReader reader = new BufferedReader( - new InputStreamReader( - connection.getInputStream(),"utf-8")); - while ((line = reader.readLine()) != null) { - httpResponseResult += line.toString(); - } - } catch (Exception e) { - e.printStackTrace(); - } - return httpResponseResult; - } - //获取请求需要的HttpURLConnection连接 - public static HttpURLConnection getURLConnection(String url){ - HttpURLConnection connection = null; - try { - URL newUrl = new URL(url); - connection = (HttpURLConnection) newUrl.openConnection(); - connection.setDoOutput(false);//post请求应改为true - connection.setDoInput(true); - connection.setRequestMethod("GET"); - connection.setUseCaches(false); - connection.setInstanceFollowRedirects(true); - connection.setRequestProperty("Content-Type", "application/json"); - connection.setRequestProperty("Charset", "utf-8"); - connection.setRequestProperty("Accept-Charset", "utf-8"); - } catch (Exception e) { - e.printStackTrace(); - } - return connection; - } + } catch (Exception e) { + e.printStackTrace(); + } + return httpResponseResult; + } + + // 获取请求需要的HttpURLConnection连接 + public static HttpURLConnection getURLConnection(String url) { + HttpURLConnection connection = null; + try { + URL newUrl = new URL(url); + connection = (HttpURLConnection) newUrl.openConnection(); + connection.setDoOutput(false);// post请求应改为true + connection.setDoInput(true); + connection.setRequestMethod("GET"); + connection.setUseCaches(false); + connection.setInstanceFollowRedirects(true); + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestProperty("Charset", "utf-8"); + connection.setRequestProperty("Accept-Charset", "utf-8"); + } catch (Exception e) { + e.printStackTrace(); + } + return connection; + } }