SkTest.java 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. package com.malk.siku;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.malk.server.aliwork.YDConf;
  4. import com.malk.server.aliwork.YDParam;
  5. import com.malk.server.aliwork.YDSearch;
  6. import com.malk.server.dingtalk.DDR_New;
  7. import com.malk.service.aliwork.YDClient;
  8. import com.malk.siku.service.SikuService;
  9. import com.malk.siku.service.SikuTaskService;
  10. import com.malk.utils.UtilMap;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.apache.commons.codec.digest.DigestUtils;
  13. import org.junit.Test;
  14. import org.junit.runner.RunWith;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.boot.test.context.SpringBootTest;
  17. import org.springframework.test.context.junit4.SpringRunner;
  18. import java.io.UnsupportedEncodingException;
  19. import java.math.BigInteger;
  20. import java.nio.charset.StandardCharsets;
  21. import java.security.MessageDigest;
  22. import java.security.NoSuchAlgorithmException;
  23. import java.text.ParseException;
  24. import java.text.SimpleDateFormat;
  25. import java.util.*;
  26. @Slf4j
  27. @SpringBootTest
  28. @RunWith(SpringRunner.class)
  29. public class SkTest {
  30. @Autowired
  31. private SikuTaskService sikuTaskService;
  32. @Autowired
  33. private SikuService sikuService;
  34. @Autowired
  35. private YDClient ydClient;
  36. @Test
  37. public void getSecret(){
  38. //每刻报销-测试环境
  39. /*String appCode="AP52Y01LHHTAP9";
  40. String appSecret="N4WuERLteAUPaWebnsHy";*/
  41. //每刻报销-生产环境
  42. String appCode="AP52RG1SCG8S6L";
  43. String appSecret="YFTbD2MviqUwztBTbMWd";
  44. //每刻云票-测试环境
  45. /*String appCode="AP53EP1SVDS1N9";
  46. String appSecret="qF4nm3nPnyXYcrWcr5jl";*/
  47. long timeMillis = System.currentTimeMillis();
  48. log.info("time:{}",timeMillis);
  49. String s = DigestUtils.sha256Hex(appSecret + ":" + appCode + ":" + timeMillis);
  50. log.info("s:{}",s);
  51. }
  52. @Test
  53. public void ssoGetToken(){
  54. //生成token所使用的java代码
  55. String ssoSecret = "EC52NRFQYEFIB5:h34BITN5HAtVMt82P9VvTRhFYpCXLgfo";//该秘钥获取路径“设置-安全设置-系统安全策略-SSO”(若无此入口,需项目经理在boss系统开通相关许可)
  56. long timestamp = System.currentTimeMillis();
  57. String userId = "HZ769";
  58. String token = DigestUtils.sha256Hex((ssoSecret + ":" + userId + ":" + timestamp).getBytes());
  59. System.out.println("timestamp:"+timestamp);
  60. System.out.println("token:"+token);
  61. }
  62. @Test
  63. public void test(){
  64. sikuTaskService.syncLoanManage();
  65. }
  66. //批量触发供应商推送每刻
  67. @Test
  68. public void test2() throws ParseException {
  69. String createTime = "2026-05-21 00:00:00";
  70. //createTime转换为时间戳
  71. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  72. Date date = sdf.parse(createTime);
  73. long timestamp = date.getTime(); // 毫秒时间戳
  74. List<Map> dataList = getYdFormDataList("FORM-A4B7986899BF42BE8E6B5B9BC85839484PTG", JSONObject.toJSONString(Arrays.asList(new YDSearch("createTime", timestamp, "创建时间", YDSearch.Type.DATE_FIELD, YDSearch.Operator.GE))), YDConf.FORM_QUERY.retrieve_list_all);
  75. /*List<Map> dataList = (List<Map>)(ydClient.queryData(YDParam.builder()
  76. .formUuid("FORM-A4B7986899BF42BE8E6B5B9BC85839484PTG")
  77. .searchCondition(JSONObject.toJSONString(Arrays.asList(new YDSearch("createTime",timestamp,"创建时间", YDSearch.Type.DATE_FIELD,YDSearch.Operator.GE))))
  78. .pageSize(100)
  79. .pageNumber(1)
  80. .build(), YDConf.FORM_QUERY.retrieve_list_all).getData());*/
  81. for (Map data : dataList) {
  82. String formInstanceId = UtilMap.getString(data, "formInstanceId");
  83. Map<String, Object> map = UtilMap.map("formInstId, type", formInstanceId, "供应商");
  84. sikuService.saveTradingPartner(map);
  85. }
  86. }
  87. private List<Map> getYdFormDataList(String formUuid, String searchCondition, YDConf.FORM_QUERY formQuery) {
  88. List<Map> list = new ArrayList<>();
  89. DDR_New ddrNew;
  90. int pageNumber = 1;
  91. int pageSize = 100;
  92. do {
  93. ddrNew = ydClient.queryData(YDParam.builder().formUuid(formUuid)
  94. .searchCondition(searchCondition)
  95. .pageNumber(pageNumber)
  96. .pageSize(pageSize).build(), formQuery);
  97. list.addAll((List<Map>) ddrNew.getData());
  98. pageNumber++;
  99. }while (ddrNew.getTotalCount() > ddrNew.getPageNumber() * pageSize);
  100. return list;
  101. }
  102. //java md5算法
  103. public static String md5(String plainText)
  104. {
  105. byte[] secretBytes = null;
  106. try {
  107. MessageDigest md = MessageDigest.getInstance("MD5");
  108. md.update(plainText.getBytes("utf-8"));
  109. secretBytes = md.digest();
  110. }
  111. catch (NoSuchAlgorithmException e) {
  112. throw new RuntimeException("no such algorithm!");
  113. } catch (UnsupportedEncodingException e) {
  114. throw new RuntimeException(e);
  115. }
  116. String md5code = new BigInteger(1, secretBytes).toString(16);
  117. int length = md5code.length();
  118. for (int i = 0; i < 32 - length; i++) {
  119. md5code = "0" + md5code;
  120. }
  121. return md5code;
  122. }
  123. //java sha256算法
  124. public static String sha256Hex(String input) {
  125. try {
  126. // 创建一个MessageDigest实例,并指定使用SHA-256算法
  127. MessageDigest digest = MessageDigest.getInstance("SHA-256");
  128. // 将输入字符串转换为字节数组,并更新摘要
  129. byte[] hash = digest.digest(input.getBytes(StandardCharsets.UTF_8));
  130. // 将字节数组转换为十六进制字符串
  131. StringBuilder hexString = new StringBuilder();
  132. for (byte b : hash) {
  133. String hex = Integer.toHexString(0xff & b);
  134. if (hex.length() == 1) hexString.append('0');
  135. hexString.append(hex);
  136. }
  137. return hexString.toString();
  138. } catch (NoSuchAlgorithmException e) {
  139. throw new RuntimeException(e);
  140. }
  141. }
  142. public static String genSign(HashMap<String, String> params, String signKey, Integer signMethod)
  143. {
  144. params.put("sign_key", signKey);
  145. String result = "";
  146. try {
  147. List<Map.Entry<String, String>> infoIds = new ArrayList<Map.Entry<String, String>>(params.entrySet());
  148. Collections.sort(infoIds, new Comparator<Map.Entry<String, String>>() {
  149. public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {
  150. return (o1.getKey()).toString().compareTo(o2.getKey());
  151. }
  152. });
  153. // 构造签名键值对的格式
  154. for (Map.Entry<String, String> item : infoIds) {
  155. if (item.getKey() != null || item.getKey() != "") {
  156. String key = item.getKey();
  157. String val = item.getValue().trim();
  158. if (result == "") {
  159. result += key + "=" + val;
  160. } else {
  161. result += "&" + key + "=" + val;
  162. }
  163. }
  164. }
  165. //System.out.println(result);
  166. } catch(Exception e) {
  167. throw new RuntimeException("error");
  168. }
  169. if(signMethod == 1) {
  170. return sha256Hex(result);
  171. }
  172. return md5(result);
  173. }
  174. public static void main (String[] args) throws java.lang.Exception {
  175. long l = System.currentTimeMillis() / 1000;
  176. HashMap<String, String> map = new HashMap<String, String>();
  177. map.put("client_id", "3295ee5021a0dd6436d18f56e7c761c6");
  178. map.put("client_secret", "fe5539d17722035cba70a2e6220c43a4");
  179. map.put("grant_type", "client_credentials");
  180. map.put("phone", "18857526310");
  181. long currentTimeMillis = System.currentTimeMillis();
  182. map.put("timestamp", currentTimeMillis+"");
  183. String signKey = "038bD3BAb4a25D84dc96";
  184. Integer signMethod = 0;
  185. String sign = genSign(map, signKey, signMethod);
  186. System.out.println("sign:"+sign);
  187. System.out.println("timestamp:"+currentTimeMillis);
  188. }
  189. }