Verituls.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package com.zhentao.utils;
  2. import cn.hutool.core.util.IdUtil;
  3. import cn.hutool.core.util.JAXBUtil;
  4. import cn.hutool.http.HttpRequest;
  5. import cn.hutool.http.HttpUtil;
  6. import cn.hutool.json.JSON;
  7. import cn.hutool.json.JSONUtil;
  8. import java.io.UnsupportedEncodingException;
  9. import java.security.MessageDigest;
  10. import java.security.NoSuchAlgorithmException;
  11. import java.util.HashMap;
  12. import java.util.Map;
  13. import java.util.TreeMap;
  14. public class Verituls {
  15. public static void VeriUtils(){
  16. Map<String,String> map = new TreeMap<>();
  17. String appId = "hutu123";
  18. String goodsId = "123";
  19. Long l = IdUtil.getSnowflake().nextId();
  20. Long l1 = System.currentTimeMillis();
  21. map.put("appId",appId);
  22. map.put("reqId",l.toString());
  23. map.put("reqTime",l1.toString());
  24. map.put("goodsId",goodsId);
  25. StringBuilder stringBuilder = new StringBuilder();
  26. Boolean bool = true;
  27. for (Map.Entry<String,String> m:map.entrySet()) {
  28. if (bool){
  29. stringBuilder.append(m.getKey()).append("=").append(m.getValue()).append("&");
  30. bool=false;
  31. }else {
  32. stringBuilder.append("&").append(m.getKey()).append("=").append(m.getValue());
  33. }
  34. }
  35. stringBuilder.append("123");
  36. System.err.println(stringBuilder);
  37. try {
  38. String md5 = EraHelper.byte2HexStr(MessageDigest.getInstance("MD5").digest(stringBuilder.toString().getBytes("UTF-8")));
  39. HttpRequest request = HttpUtil.createPost("http://localhost:9500/goods/orderadd");
  40. Map<String,String> map1 = new HashMap<>();
  41. map1.put("pageNo","1");
  42. map1.put("pageSize","10");
  43. map1.put("sign",md5);
  44. map1.put("reqTime",l1.toString());
  45. map1.put("goodsId",goodsId);
  46. request.body(JSONUtil.toJsonStr(map1));
  47. Map<String,String> map2 = new HashMap<>();
  48. map2.put("appId",appId);
  49. map2.put("reqId",l.toString());
  50. request.addHeaders(map2);
  51. String body = request.execute().body();
  52. System.err.println(body);
  53. } catch (NoSuchAlgorithmException e) {
  54. throw new RuntimeException(e);
  55. } catch (UnsupportedEncodingException e) {
  56. throw new RuntimeException(e);
  57. }
  58. }
  59. public static void main(String[] args) {
  60. Verituls.VeriUtils();
  61. }
  62. }