| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- //package com.huimv.admin.timer;
- //
- //
- //
- //import cn.hutool.core.date.DateTime;
- //import cn.hutool.core.date.DateUtil;
- //import cn.hutool.core.util.ObjectUtil;
- //import cn.hutool.json.JSONUtil;
- //import com.alibaba.fastjson.JSON;
- //import com.huimv.admin.entity.zengxindto.ProdStockDto;
- //import org.springframework.web.client.RestTemplate;
- //
- //import java.io.IOException;
- //import java.security.GeneralSecurityException;
- //import java.security.MessageDigest;
- //import java.time.LocalDateTime;
- //import java.time.format.DateTimeFormatter;
- //import java.util.*;
- //
- ///**
- // * @Project : huimv.shiwan
- // * @Package : com.huimv.admin.timer
- // * @Description : TODO
- // * @Author : yuxuexuan
- // * @Create : 2024/1/24 0024 18:16
- // **/
- //public class test {
- // /* public static void main(String[] args) throws IOException {
- // Map<String, String> params = new HashMap();
- // params.put("token","E0FE7EE553814E338A339A7BC43F2D82");
- // params.put("data","{\"db_name\":\"MSSQL\",\"proc_name\":\"rep_yz_kc_hz\",\"method\":\"open_proc\",\"params\":[{\"name\":\"@fdate\",\"value\":\"2024-01-24\"}]}");
- // params.put("sign_method","md5");
- // params.put("timestamp","2024-01-24 19:59:29");
- // params.put("version","2.0");
- // String[] keys = params.keySet().toArray(new String[0]);
- // Arrays.sort(keys);
- // for (String key : keys) {
- // System.out.println(key);
- // }
- //
- // System.out.println(signTopRequest(params, "E911CE7BE0B84208B77DC50CEDA2B3C8", "MD5"));
- //
- // }*/
- // public static void main(String[] args) throws IOException {
- // DateTime dateTime = DateUtil.offsetDay(new Date(), -352);
- // String substring = dateTime.toString().substring(0, 10);
- // System.out.println(substring);
- //
- // String url = "http://test.htpig.cn/rest/db/storedproc";
- // Map<String, Object> map = new HashMap<String, Object>();
- // map.put("db_name", "MSSQL");
- // map.put("proc_name", "rep_yz_hm_sw");
- // map.put("method", "open_proc");
- // List list = new ArrayList();
- // HashMap<String, Object> maps = new HashMap<>();
- // maps.put("name", "@fdate1");
- // maps.put("value", substring);
- // HashMap<String, Object> maps2 = new HashMap<>();
- // maps2.put("name", "@fdate2");
- // maps2.put("value", substring);
- // list.add(maps);
- // list.add(maps2);
- // map.put("params", list);
- // String params = JSON.toJSONString(map);
- //
- // LocalDateTime timestamp = LocalDateTime.now();
- // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- // // 格式化日期时间为字符串
- // String formattedDateTime = timestamp.format(formatter);
- // Map<String,String> tokenMap = new HashMap<>();
- // String token = "36F1C87C390E4F15AE5BAA82996DFB8D";
- // String secret = "E911CE7BE0B84208B77DC50CEDA2B3C8";
- // tokenMap.put("token",token);
- // tokenMap.put("data",params);
- // tokenMap.put("sign_method","md5");
- // tokenMap.put("timestamp",formattedDateTime);
- // tokenMap.put("version","2.0");
- // String sign = signTopRequest(tokenMap, secret, "md5");
- // tokenMap.put("sign",sign);
- // String url1 = url + "?token=" + token + "&sign_method=md5" + "×tamp=" + formattedDateTime + "&version=2.0" + "&sign=" + sign + "&data={data}" ;
- // RestTemplate restTemplate = new RestTemplate();
- // String forObject = restTemplate.getForObject(url1 , String.class,params);
- //
- // ProdStockDto jz2 = JSONUtil.toBean(forObject, ProdStockDto.class);
- // List<List<Object>> jzdata = jz2.getData();
- // Integer intjz = ObjectUtil.isEmpty(jzdata) ? 0:Integer.parseInt(jzdata.get(0).get(3).toString());
- // System.out.println(intjz);
- // System.out.println(forObject);
- // }
- //
- //
- //
- // public static String signTopRequest(Map<String, String> params, String secret, String signMethod) throws IOException {
- // // 第一步:检查参数是否已经排序
- // String[] keys = params.keySet().toArray(new String[0]);
- // Arrays.sort(keys);
- //
- // // 第二步:把所有参数名和参数值串在一起
- // StringBuilder query = new StringBuilder();
- // query.append(secret);
- // for (String key : keys) {
- // String value = params.get(key);
- // query.append(key).append(value);
- // }
- // query.append(secret);
- //
- // // 第三步:使用MD5/HMAC加密
- // byte[] bytes;
- //
- // System.out.println(query);
- // bytes = encryptMD5(query.toString());
- //
- // // 第四步:把二进制转化为大写的十六进制(正确签名应该为32大写字符串,此方法需要时使用)
- // return byte2hex(bytes);
- // }
- //
- //
- // public static byte[] encryptMD5(String data) throws IOException {
- // return encryptMD5(data.getBytes("UTF-8"));
- // }
- // public static byte[] encryptMD5(byte[] data) throws IOException {
- // byte[] bytes = null;
- // try {
- // MessageDigest md = MessageDigest.getInstance("MD5");
- // bytes = md.digest(data);
- // } catch (GeneralSecurityException gse) {
- // throw new IOException(gse.toString());
- // }
- // return bytes;
- // }
- // public static String byte2hex(byte[] bytes) {
- // StringBuilder sign = new StringBuilder();
- // for (int i = 0; i < bytes.length; i++) {
- // String hex = Integer.toHexString(bytes[i] & 0xFF);if (hex.length() == 1) {
- // sign.append("0");
- // }
- // sign.append(hex.toUpperCase());
- // }
- // return sign.toString();
- // }
- //
- //
- //
- //}
|