Sfoglia il codice sorgente

招行支付2.0-请求id自定义工具类

ZhangWenQiang 4 anni fa
parent
commit
98b37962a0

+ 7 - 1
happy-cloud-wisdom/happy-cloud-wisdom-biz/src/main/java/org/jeecg/common/zhutils/PayRequest.java

@@ -31,13 +31,19 @@ public class PayRequest {
      * @return
      */
     public static String doRequest(JSONObject obj_body, String funcode, String userid, String payurl,
-                                   String reqid, PublicKey publicKey, PrivateKey prvKey, String aesKey) throws Exception {
+                                   PublicKey publicKey, PrivateKey prvKey, String aesKey) throws Exception {
         JSONObject jObject = new JSONObject();
         JSONObject request = new JSONObject();
         // head
         JSONObject head = new JSONObject();
         head.put("funcode", funcode);
         head.put("userid", userid);
+        //免前置接入方式时该字段必输,前17位必须满足日期格式yyyyMMddHHmmssSSS(年月日时分秒毫秒)后面的自己定义,长度18-51位
+        LocalDateTime now = LocalDateTime.now(ZoneId.of("+8"));
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
+        String reqid = formatter.format(now);
+        //组合随机数(12位),请求id=日期+随机数
+        reqid = reqid + RandomRequest.getRandom(12);
         head.put("reqid", reqid);
         //data
         request.put("head", head);

+ 48 - 0
happy-cloud-wisdom/happy-cloud-wisdom-biz/src/main/java/org/jeecg/common/zhutils/RandomRequest.java

@@ -0,0 +1,48 @@
+package org.jeecg.common.zhutils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Random;
+
+/**
+ * @Author: zwq
+ * @Date: Create in 2021/6/2 9:57
+ * @Description: 免前置机模式请求id随机数生成工具类
+ */
+public class RandomRequest {
+
+    /**
+     * 小写字母
+     */
+    private static String[] lowercase = {
+            "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
+            "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
+
+    /**
+     * 数字
+     */
+    private static String[] number = {
+            "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
+
+    /**
+     * 静态随机数
+     */
+    private static Random random = new Random();
+
+    /**
+     * 获取随机数
+     *
+     * @param num 随机数位数
+     * @return
+     */
+    public static String getRandom(int num) {
+        ArrayList<String> temp = new ArrayList<String>();
+        StringBuffer code = new StringBuffer();
+        temp.addAll(Arrays.asList(lowercase));
+        temp.addAll(Arrays.asList(number));
+        for (int i = 0; i < num; i++) {
+            code.append(temp.get(random.nextInt(temp.size())));
+        }
+        return code.toString();
+    }
+}