Bladeren bron

笛风云

gongfuzhu 1 jaar geleden
bovenliggende
commit
7ca1fe479e

+ 137 - 0
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/api/dfy/Signature.java

@@ -0,0 +1,137 @@
+package com.zswl.cloud.springBtach.server.core.api.dfy;
+
+import cn.hutool.core.codec.Base64Encoder;
+import cn.hutool.crypto.SecureUtil;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.zswl.cloud.springBtach.server.core.api.dfy.request.ScenicRequest;
+import org.apache.commons.lang3.StringUtils;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * API签名工具类
+ */
+public class Signature {
+
+    private static final String API_SIGNATURE_KEY = "sign";
+
+    public static void main(String[] args) {
+
+
+        ScenicRequest scenicRequest = new ScenicRequest();
+        ScenicRequest.Scenic scenic = new ScenicRequest.Scenic();
+        scenic.setKey("南京");
+        scenic.setPage("1");
+        scenic.setPageSize("10");
+
+
+        scenicRequest.setData(scenic);
+//71C6F9A4927718E2E0B94D9D834875F2
+//71C6F9A4927718E2E0B94D9D834875F2
+
+        String SecretKey="aaaaaaaa";
+
+        System.out.println(JSONUtil.toJsonStr(scenicRequest));
+        String signature = getSignature(JSONUtil.parseObj(scenicRequest), SecretKey);
+        System.out.println(signature);
+        String data = Base64Encoder.encode(JSONUtil.parseObj(scenicRequest).get("data").toString());
+        System.out.println(data);
+        System.out.println(scenicRequest.getTimestamp());
+
+
+    }
+
+    /**
+     * 根据入参和密钥获取签名
+     */
+    public static String getSignature(JSONObject data, String secretKey) {
+
+        // 第一步:获取并排序json数据
+        //忽略签名
+        data.remove("sign");
+
+        //递归获取json结构中的键值对,组合键值并保存到列表中
+        List<String> keyValueList = new ArrayList<String>();
+        propertyFilter(null, data, keyValueList);
+
+        //对列表进行排序,区分大小写
+        Collections.sort(keyValueList);
+
+
+        // 第二步:格式化数据,用&分割
+        String formatText = StringUtils.join(keyValueList, "&");
+
+        //在首尾加上秘钥,用&分割
+        String finalText = secretKey + "&" + formatText + "&" + secretKey;
+
+        // 第三步:MD5加密并转换成大写的16进制(finalText为utf-8编码)
+
+        String upperCase = SecureUtil.md5(finalText).toUpperCase();
+
+
+
+        return upperCase;
+    }
+
+
+    private 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();
+    }
+
+    /**
+     * PropertyPreFilter
+     * 与jsonObjectPropertyFilter,jsonArrayPropertyFilter配合完成键值对的抽取组合
+     */
+    private static void propertyFilter(String key, Object value, List<String> list) {
+        if (null == value) {
+            return;
+        }
+        if (value instanceof JSONObject) {
+            jsonObjectPropertyFilter(key, (JSONObject) value, list);
+        } else if (value instanceof JSONArray) {
+            jsonArrayPropertyFilter(key, (JSONArray) value, list);
+        } else {
+            if (value != null && value.toString().length() > 0) {
+                list.add(key.trim() + "=" + value);
+            }
+        }
+    }
+
+    /**
+     * jsonObjectPropertyFilter 过滤json对象
+     */
+    private static void jsonObjectPropertyFilter(String key, JSONObject value, List<String> list) {
+        JSONObject jsonObject = value;
+        if (jsonObject.isEmpty()) {
+            return;
+        }
+        for (String str : jsonObject.keySet()) {
+            propertyFilter(str, jsonObject.get(str), list);
+        }
+    }
+
+    /**
+     * jsonArrayPropertyFilter 过滤json数组
+     */
+    private static void jsonArrayPropertyFilter(String key, JSONArray value, List<String> list) {
+        JSONArray jsonArray = value;
+        if (jsonArray.isEmpty()) {
+            return;
+        }
+        for (Object json : jsonArray) {
+            propertyFilter(key, json, list);
+        }
+    }
+
+}

+ 26 - 0
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/api/dfy/request/RequestBase.java

@@ -0,0 +1,26 @@
+package com.zswl.cloud.springBtach.server.core.api.dfy.request;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.unit.DataSizeUtil;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Date;
+
+@Data
+@AllArgsConstructor
+public class RequestBase {
+
+    private String apiKey;
+    private String sign;
+    private String timestamp;
+
+    public RequestBase() {
+
+        this.apiKey = "tickettest";
+        this.timestamp = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss");
+
+    }
+
+}

+ 25 - 0
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/api/dfy/request/ScenicRequest.java

@@ -0,0 +1,25 @@
+package com.zswl.cloud.springBtach.server.core.api.dfy.request;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class ScenicRequest extends RequestBase {
+
+    private Scenic data;
+
+    @Data
+    @NoArgsConstructor
+    @AllArgsConstructor
+    public static class Scenic {
+
+        private String key;
+        private String page;
+        private String pageSize;
+
+
+    }
+}

+ 1 - 1
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/api/ypp/YppApi.java

@@ -115,7 +115,7 @@ public class YppApi {
      * @return
      * @return
      */
      */
     public JSONObject movies(String cityId, String pageIndex, String pageSize) {
     public JSONObject movies(String cityId, String pageIndex, String pageSize) {
-        JSONObject entries = httpGet("https://channel.youpiaopiao.cn/api/movie/movies?cityId=" + cityId + "&pageIndex=" + pageIndex + "&pageSize" + pageSize);
+        JSONObject entries = httpGet("https://channel.youpiaopiao.cn/api/movie/movies?cityId=" + cityId + "&pageIndex=" + pageIndex + "&pageSize=" + pageSize);
         return entries;
         return entries;
 
 
     }
     }

+ 13 - 0
SpringBatchServiceServer/src/main/resources/application-dev.yml

@@ -30,10 +30,23 @@ swagger:
   version: "1.0"
   version: "1.0"
   enable: true
   enable: true
 
 
+# 有票票
 ypp:
 ypp:
   entId: 101206
   entId: 101206
   appSecret: VqJfaVYc87wDKk8Gad4yAx9v8TFNhrt0
   appSecret: VqJfaVYc87wDKk8Gad4yAx9v8TFNhrt0
 
 
+# 笛风云
+dfy:
+  host: https://doptest-api.dfyoo.com
+  mp:
+    acctId: 100012
+    apikey: tickettest
+    secretkey: aaaaaaaa
+  jd:
+    acctId: 100012
+    apikey: hoteltest
+    secretkey: aaaaaaaa
+
 
 
 #logging:
 #logging:
 #  level:
 #  level: