1.增加hutool包,替换httpPost函数,解决接收数据无法json格式化
This commit is contained in:
gaoben 2021-12-09 18:32:01 +08:00
parent 058a898c25
commit e921fd57ab
2 changed files with 32 additions and 1 deletions

View File

@ -181,6 +181,12 @@
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.16</version>
</dependency>
<dependency>

View File

@ -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<String,String> 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";