package com.zhentao.utils; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.JAXBUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpUtil; import cn.hutool.json.JSON; import cn.hutool.json.JSONUtil; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.HashMap; import java.util.Map; import java.util.TreeMap; public class Verituls { public static void VeriUtils(){ Map map = new TreeMap<>(); String appId = "hutu123"; String goodsId = "123"; Long l = IdUtil.getSnowflake().nextId(); Long l1 = System.currentTimeMillis(); map.put("appId",appId); map.put("reqId",l.toString()); map.put("reqTime",l1.toString()); map.put("goodsId",goodsId); StringBuilder stringBuilder = new StringBuilder(); Boolean bool = true; for (Map.Entry m:map.entrySet()) { if (bool){ stringBuilder.append(m.getKey()).append("=").append(m.getValue()).append("&"); bool=false; }else { stringBuilder.append("&").append(m.getKey()).append("=").append(m.getValue()); } } stringBuilder.append("123"); System.err.println(stringBuilder); try { String md5 = EraHelper.byte2HexStr(MessageDigest.getInstance("MD5").digest(stringBuilder.toString().getBytes("UTF-8"))); HttpRequest request = HttpUtil.createPost("http://localhost:9500/goods/orderadd"); Map map1 = new HashMap<>(); map1.put("pageNo","1"); map1.put("pageSize","10"); map1.put("sign",md5); map1.put("reqTime",l1.toString()); map1.put("goodsId",goodsId); request.body(JSONUtil.toJsonStr(map1)); Map map2 = new HashMap<>(); map2.put("appId",appId); map2.put("reqId",l.toString()); request.addHeaders(map2); String body = request.execute().body(); System.err.println(body); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } public static void main(String[] args) { Verituls.VeriUtils(); } }