From e921fd57ab10359925fe9507778b668bbc78f2e7 Mon Sep 17 00:00:00 2001 From: gaoben Date: Thu, 9 Dec 2021 18:32:01 +0800 Subject: [PATCH] =?UTF-8?q?v3.0.9=201.=E5=A2=9E=E5=8A=A0hutool=E5=8C=85?= =?UTF-8?q?=EF=BC=8C=E6=9B=BF=E6=8D=A2httpPost=E5=87=BD=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=8E=A5=E6=94=B6=E6=95=B0=E6=8D=AE=E6=97=A0?= =?UTF-8?q?=E6=B3=95json=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shapelight-admin/pom.xml | 6 +++++ .../modules/xian/service/XaApi.java | 27 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/shapelight-admin/pom.xml b/shapelight-admin/pom.xml index d06f150..74dab09 100644 --- a/shapelight-admin/pom.xml +++ b/shapelight-admin/pom.xml @@ -181,6 +181,12 @@ + + cn.hutool + hutool-all + 5.7.16 + + diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/xian/service/XaApi.java b/shapelight-admin/src/main/java/net/shapelight/modules/xian/service/XaApi.java index 5d45c6a..4290f38 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/xian/service/XaApi.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/xian/service/XaApi.java @@ -1,5 +1,6 @@ package net.shapelight.modules.xian.service; +import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -95,7 +96,7 @@ public class XaApi { * @param secre * @return */ - public static String httpPOSTJson(String url, String json, String serviceId, String serviceValue, String appid, String secre, String tranId) { + public static String httpPOSTJsonOld(String url, String json, String serviceId, String serviceValue, String appid, String secre, String tranId) { String data = ""; HttpURLConnection conn = null; try { @@ -169,6 +170,30 @@ public class XaApi { } + public static String httpPOSTJson(String url, String json, String serviceId, String serviceValue, String appid, String secre, String tranId) { +// String data = ""; + + String currdate = new SimpleDateFormat("yyyyMMdd").format(new Date()); + String token = XaUtils.md5(appid + secre + currdate + json.replaceAll("\r\n", "")); + Map map=new HashMap(); + map.put("appid",appid); + map.put("token",token); + map.put("tranId",tranId);//可固定这么写 + map.put("serviceId",serviceId); + map.put("serviceValue",serviceValue); + map.put("versionCode",""); + map.put("User-Agent","Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); + String body = HttpUtil.createPost(url).headerMap(map, true).body(json).execute().body(); + try{ + body = URLDecoder.decode(body, "UTF-8"); + return body; + }catch (UnsupportedEncodingException e){ + log.error("解码返回结果失败:原始数据:"+body); + return ""; + } + } + + public static void syncRoom() { String appid = "1297164778041095"; String appsecret = "22971647780410956329716477804109";