test.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //package com.huimv.admin.timer;
  2. //
  3. //
  4. //
  5. //import cn.hutool.core.date.DateTime;
  6. //import cn.hutool.core.date.DateUtil;
  7. //import cn.hutool.core.util.ObjectUtil;
  8. //import cn.hutool.json.JSONUtil;
  9. //import com.alibaba.fastjson.JSON;
  10. //import com.huimv.admin.entity.zengxindto.ProdStockDto;
  11. //import org.springframework.web.client.RestTemplate;
  12. //
  13. //import java.io.IOException;
  14. //import java.security.GeneralSecurityException;
  15. //import java.security.MessageDigest;
  16. //import java.time.LocalDateTime;
  17. //import java.time.format.DateTimeFormatter;
  18. //import java.util.*;
  19. //
  20. ///**
  21. // * @Project : huimv.shiwan
  22. // * @Package : com.huimv.admin.timer
  23. // * @Description : TODO
  24. // * @Author : yuxuexuan
  25. // * @Create : 2024/1/24 0024 18:16
  26. // **/
  27. //public class test {
  28. // /* public static void main(String[] args) throws IOException {
  29. // Map<String, String> params = new HashMap();
  30. // params.put("token","E0FE7EE553814E338A339A7BC43F2D82");
  31. // params.put("data","{\"db_name\":\"MSSQL\",\"proc_name\":\"rep_yz_kc_hz\",\"method\":\"open_proc\",\"params\":[{\"name\":\"@fdate\",\"value\":\"2024-01-24\"}]}");
  32. // params.put("sign_method","md5");
  33. // params.put("timestamp","2024-01-24 19:59:29");
  34. // params.put("version","2.0");
  35. // String[] keys = params.keySet().toArray(new String[0]);
  36. // Arrays.sort(keys);
  37. // for (String key : keys) {
  38. // System.out.println(key);
  39. // }
  40. //
  41. // System.out.println(signTopRequest(params, "E911CE7BE0B84208B77DC50CEDA2B3C8", "MD5"));
  42. //
  43. // }*/
  44. // public static void main(String[] args) throws IOException {
  45. // DateTime dateTime = DateUtil.offsetDay(new Date(), -352);
  46. // String substring = dateTime.toString().substring(0, 10);
  47. // System.out.println(substring);
  48. //
  49. // String url = "http://test.htpig.cn/rest/db/storedproc";
  50. // Map<String, Object> map = new HashMap<String, Object>();
  51. // map.put("db_name", "MSSQL");
  52. // map.put("proc_name", "rep_yz_hm_sw");
  53. // map.put("method", "open_proc");
  54. // List list = new ArrayList();
  55. // HashMap<String, Object> maps = new HashMap<>();
  56. // maps.put("name", "@fdate1");
  57. // maps.put("value", substring);
  58. // HashMap<String, Object> maps2 = new HashMap<>();
  59. // maps2.put("name", "@fdate2");
  60. // maps2.put("value", substring);
  61. // list.add(maps);
  62. // list.add(maps2);
  63. // map.put("params", list);
  64. // String params = JSON.toJSONString(map);
  65. //
  66. // LocalDateTime timestamp = LocalDateTime.now();
  67. // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  68. // // 格式化日期时间为字符串
  69. // String formattedDateTime = timestamp.format(formatter);
  70. // Map<String,String> tokenMap = new HashMap<>();
  71. // String token = "36F1C87C390E4F15AE5BAA82996DFB8D";
  72. // String secret = "E911CE7BE0B84208B77DC50CEDA2B3C8";
  73. // tokenMap.put("token",token);
  74. // tokenMap.put("data",params);
  75. // tokenMap.put("sign_method","md5");
  76. // tokenMap.put("timestamp",formattedDateTime);
  77. // tokenMap.put("version","2.0");
  78. // String sign = signTopRequest(tokenMap, secret, "md5");
  79. // tokenMap.put("sign",sign);
  80. // String url1 = url + "?token=" + token + "&sign_method=md5" + "&timestamp=" + formattedDateTime + "&version=2.0" + "&sign=" + sign + "&data={data}" ;
  81. // RestTemplate restTemplate = new RestTemplate();
  82. // String forObject = restTemplate.getForObject(url1 , String.class,params);
  83. //
  84. // ProdStockDto jz2 = JSONUtil.toBean(forObject, ProdStockDto.class);
  85. // List<List<Object>> jzdata = jz2.getData();
  86. // Integer intjz = ObjectUtil.isEmpty(jzdata) ? 0:Integer.parseInt(jzdata.get(0).get(3).toString());
  87. // System.out.println(intjz);
  88. // System.out.println(forObject);
  89. // }
  90. //
  91. //
  92. //
  93. // public static String signTopRequest(Map<String, String> params, String secret, String signMethod) throws IOException {
  94. // // 第一步:检查参数是否已经排序
  95. // String[] keys = params.keySet().toArray(new String[0]);
  96. // Arrays.sort(keys);
  97. //
  98. // // 第二步:把所有参数名和参数值串在一起
  99. // StringBuilder query = new StringBuilder();
  100. // query.append(secret);
  101. // for (String key : keys) {
  102. // String value = params.get(key);
  103. // query.append(key).append(value);
  104. // }
  105. // query.append(secret);
  106. //
  107. // // 第三步:使用MD5/HMAC加密
  108. // byte[] bytes;
  109. //
  110. // System.out.println(query);
  111. // bytes = encryptMD5(query.toString());
  112. //
  113. // // 第四步:把二进制转化为大写的十六进制(正确签名应该为32大写字符串,此方法需要时使用)
  114. // return byte2hex(bytes);
  115. // }
  116. //
  117. //
  118. // public static byte[] encryptMD5(String data) throws IOException {
  119. // return encryptMD5(data.getBytes("UTF-8"));
  120. // }
  121. // public static byte[] encryptMD5(byte[] data) throws IOException {
  122. // byte[] bytes = null;
  123. // try {
  124. // MessageDigest md = MessageDigest.getInstance("MD5");
  125. // bytes = md.digest(data);
  126. // } catch (GeneralSecurityException gse) {
  127. // throw new IOException(gse.toString());
  128. // }
  129. // return bytes;
  130. // }
  131. // public static String byte2hex(byte[] bytes) {
  132. // StringBuilder sign = new StringBuilder();
  133. // for (int i = 0; i < bytes.length; i++) {
  134. // String hex = Integer.toHexString(bytes[i] & 0xFF);if (hex.length() == 1) {
  135. // sign.append("0");
  136. // }
  137. // sign.append(hex.toUpperCase());
  138. // }
  139. // return sign.toString();
  140. // }
  141. //
  142. //
  143. //
  144. //}