柯桥增值式服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 line
2.2KB

  1. package com.ningdatech.kqapi.common.util;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import lombok.extern.slf4j.Slf4j;
  5. import java.io.IOException;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8. import java.util.Objects;
  9. /**
  10. * @Classname RefreshKeyUtil
  11. * @Description
  12. * @Date 2023/6/27 10:03
  13. * @Author PoffyZhang
  14. */
  15. @Slf4j
  16. public class RefreshKeyUtil {
  17. public static String getRequestSecret(String appKey, String appSecret,Long requestTime) throws IOException {
  18. // 刷新秘钥
  19. HttpUtil httpUtil = HttpUtil.getInstance();
  20. log.info("请求密钥" + appSecret);
  21. String sign = Md5Utils.hash (appKey + appSecret + requestTime);
  22. String refreshUrl = "http://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm";
  23. log.info(refreshUrl);
  24. Map<String,String> map = new HashMap<>();
  25. map.put("appKey",appKey);
  26. map.put("sign",sign);
  27. map.put("requestTime",requestTime + "");
  28. String result = httpUtil.sendHttpPost(refreshUrl,map);
  29. log.info(result);
  30. JSONObject dataJson = JSON.parseObject(result).getJSONObject("datas");
  31. if(Objects.nonNull(dataJson)){
  32. return dataJson.getString("requestSecret");
  33. }
  34. return result;
  35. }
  36. public static String refreshSecret(String appKey, String refreshSecret,Long requestTime) throws IOException {
  37. // 刷新秘钥
  38. HttpUtil httpUtil = HttpUtil.getInstance();
  39. log.info("刷新密钥" + refreshSecret);
  40. String refreshSign = Md5Utils.hash (appKey + refreshSecret + requestTime);
  41. String refreshUrl = "http://interface.zjzwfw.gov.cn/gateway/app/refreshTokenBySec.htm";
  42. log.info(refreshUrl);
  43. Map<String,String> map = new HashMap<>();
  44. map.put("appKey",appKey);
  45. map.put("sign",refreshSign);
  46. map.put("requestTime",requestTime + "");
  47. String result = httpUtil.sendHttpPost(refreshUrl,map);
  48. log.info(result);
  49. JSONObject dataJson = JSON.parseObject(result).getJSONObject("datas");
  50. if(Objects.nonNull(dataJson)){
  51. return dataJson.getString("requestSecret");
  52. }
  53. return result;
  54. }
  55. }