From c168ad4af7d7897fdd761157222ad1093761e12b Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Tue, 29 Oct 2019 13:28:31 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=81=9C=E8=BD=A6][=E6=96=B0=E5=A2=9E]:?= =?UTF-8?q?=E5=B0=9A=E5=AE=89=E5=81=9C=E8=BD=A6=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/iformall/utils/car/ShangAnUtil.java | 164 ++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 mallinkService/src/main/java/com/iformall/utils/car/ShangAnUtil.java diff --git a/mallinkService/src/main/java/com/iformall/utils/car/ShangAnUtil.java b/mallinkService/src/main/java/com/iformall/utils/car/ShangAnUtil.java new file mode 100644 index 000000000..aadaac57e --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/utils/car/ShangAnUtil.java @@ -0,0 +1,164 @@ +package com.iformall.utils.car; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.iformall.utils.DateUtils; +import org.apache.http.Consts; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicHeader; +import org.apache.http.protocol.HTTP; +import org.apache.http.util.EntityUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * 尚安停车 + */ +public class ShangAnUtil { + + private final static Logger logger = LoggerFactory.getLogger(ShangAnUtil.class); + + public static final String KEY = "NzMFFDDJDIFACACCM2zAezDz"; + + public static final String PARK_NUMBER = "p190829183435"; + + public static final String URL = "http://www.p-share.com/shangan-yhq/web/api/outcoupon"; + + public static final String SUCCESS = "success"; + + public static final SimpleDateFormat dateInFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + + public static void main(String[] args) throws Exception { + String carNumber = "京XAZMF1"; + Date myDate = DateUtils.getHourTimeAfter(1, new Date()); + + String result = couponSend(URL, KEY, PARK_NUMBER, "1", myDate, carNumber, "1500"); + + JSONObject obj = JSON.parseObject(result); + } + + /** + * md5算法 + * @param data + * @return + * @throws NoSuchAlgorithmException + */ + + public static String md5(String data) throws NoSuchAlgorithmException { + MessageDigest md = MessageDigest.getInstance("MD5"); + md.update(data.getBytes()); + StringBuffer buf = new StringBuffer(); + byte[] bits = md.digest(); + for(int i=0;i params = new HashMap<>(); + params.put("parkNum", parkNumber); + params.put("couponModeId", couponModelId); + params.put("couponDate", dateInFormat.format(couponDate)); + params.put("plate", plate); + params.put("position", position); + try { + String result = Proc(url, key, parkNumber, params); + return result; + } catch (Exception e) { + return null; + } + } + + private static String Proc(String url, String key, String parkNumber, Map paramMap) { + CloseableHttpClient httpClient = HttpClients.createDefault(); + + HttpPost httpPost = new HttpPost(url); + httpPost.addHeader(HTTP.CONTENT_TYPE,"application/json"); + httpPost.addHeader("Accept", "application/json"); + httpPost.addHeader("Accept-Encoding", "UTF-8"); + + String sign = null; + try{ + sign = getSign(key, parkNumber); + httpPost.addHeader("sign", sign); + }catch(NoSuchAlgorithmException e) { + logger.error(e.getLocalizedMessage()); + } + + String jsonstr = JSON.toJSONString(paramMap); + logger.info(jsonstr); + + try { + StringEntity se = new StringEntity(jsonstr, Consts.UTF_8); + se.setContentType("application/json"); + se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"UTF-8")); + httpPost.setEntity(se); + } catch (Exception e) { + logger.error(e.getMessage()); + } + + HttpResponse response = null; + try { + response = httpClient.execute(httpPost); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + } + + String result = null; + + //打印StatusLine + logger.debug("StatusLine: " + response.getStatusLine()); + try{ + //获取实体 + HttpEntity httpEntity= response.getEntity(); + result = EntityUtils.toString(httpEntity, "UTF-8"); + logger.debug(result); + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + } + + try { //关闭流并释放资源 + httpClient.close(); + } catch (IOException e) { + logger.error(e.getLocalizedMessage()); + } + + return result; + } + + + + +} +