Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/master'

yumeng 1 anno fa
parent
commit
4574be6581

+ 2 - 0
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java

@@ -259,6 +259,8 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/kuaiShou/promoter/**", "anon");
         filterChainDefinitionMap.put("/financePayment/**", "anon");
         filterChainDefinitionMap.put("/materialData/**", "anon");
+        filterChainDefinitionMap.put("/budget/**", "anon");
+        filterChainDefinitionMap.put("/ctop/byteDanceVideoInfo/*", "anon");
 
         // 添加自己的过滤器并且取名为jwt
         Map<String, Filter> filterMap = new HashMap<>(1);

+ 43 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceVideoInfoController.java

@@ -2,6 +2,10 @@ package cn.com.ctop.toutiao.modules.material.controller;
 
 import cn.com.ctop.toutiao.modules.material.entity.ByteDanceVideoInfo;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceVideoInfoService;
+import cn.com.ctop.toutiao.modules.tool.callback.AuthTokenUtil;
+import cn.com.ctop.toutiao.modules.tool.callback.BaseResponse;
+import cn.com.ctop.toutiao.modules.tool.callback.CallbackResponse;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -12,9 +16,18 @@ import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
 import java.util.Arrays;
 
 /**
@@ -162,4 +175,33 @@ public class ByteDanceVideoInfoController {
         }
         return result;
     }
+
+
+    /**
+     * 广告违规素材推送
+     */
+    @RequestMapping(value = "/illegalVideosPush", method = {RequestMethod.GET, RequestMethod.POST})
+    public CallbackResponse illegalVideosPush(HttpServletRequest request,
+                                              @RequestParam(value = "challenge", defaultValue = "0") int challenge,
+                                              @RequestParam(value = "event", defaultValue = "") String event) throws IOException {
+        log.info("广告违规素材推送--------------------------challenge= " + challenge + ";event= " + event);
+        // 处理 verify 事件
+        if (null != event && event.equals("verify_webhook")) {
+            return new CallbackResponse(BaseResponse.ok(), challenge);
+        }
+
+        // 订阅任务配置页面的 "验证密钥"
+        String secretKey = "156a5d76ad354b43865ef57e5e416ca7";
+        // 数据接收,验证消息
+        AuthTokenUtil.InputStreamCacher cacher = new AuthTokenUtil.InputStreamCacher(request.getInputStream());
+        boolean isValidToken = AuthTokenUtil.isValidToken(secretKey, cacher, request.getHeader("X-Open-Signature"));
+        log.info("isValidToken=" + isValidToken);
+        if (!isValidToken) {
+            return new CallbackResponse(new BaseResponse(400, "invalid token"), 0);
+        }
+        JSONObject result = JSONObject.parseObject(new String(AuthTokenUtil.readAsBytes(cacher)));
+        System.out.println("返回结果:" + result.toJSONString());
+        // 数据处理流程...
+        return new CallbackResponse(BaseResponse.ok(), 0);
+    }
 }

+ 77 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/tool/callback/AuthTokenUtil.java

@@ -0,0 +1,77 @@
+package cn.com.ctop.toutiao.modules.tool.callback;
+
+
+import com.google.common.hash.HashCode;
+import com.google.common.hash.HashFunction;
+import com.google.common.hash.Hashing;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import  org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class AuthTokenUtil {
+    static Logger logger = LoggerFactory.getLogger(AuthTokenUtil.class);
+
+    public static byte[] readAsBytes(InputStreamCacher cacher){
+        int len = cacher.getLength();
+        byte[] buffer = new byte[len];
+        try(InputStream in = cacher.getInputStream()){
+            in.read(buffer, 0, len);
+        }catch (IOException e){
+            e.printStackTrace();
+        }
+        return buffer;
+    }
+    // 根据SecretKey计算签名
+    public static String genSignature(String secretKey, byte[] binaryparams){
+        HashFunction function = Hashing.hmacSha256(secretKey.getBytes());
+        HashCode code = function.hashBytes(binaryparams);
+        return code.toString();
+    }
+    // 校验签名
+    public static boolean isValidToken(String secretKey, InputStreamCacher cacher, String signature ) {
+        if (StringUtils.isEmpty(secretKey) || StringUtils.isEmpty(signature)) {
+            return false;
+        }
+        String reSignature = genSignature(secretKey,readAsBytes(cacher));
+//        logger.info("secretKey: " + secretKey);
+//        logger.info("content: " + new String(readAsBytes(cacher)));
+//        logger.info("signature: " + signature);
+//        logger.info("reSignature: " + reSignature);
+        return signature.equals(reSignature);
+    }
+
+    public static class InputStreamCacher {
+        private int length;
+        private ByteArrayOutputStream byteArrayOutputStream = null;
+
+        public InputStreamCacher(InputStream inputStream) {
+            if (inputStream == null)
+                return;
+            length = 0;
+            byteArrayOutputStream = new ByteArrayOutputStream();
+            byte[] buffer = new byte[1024];
+            int len;
+            try {
+                while ((len = inputStream.read(buffer)) > -1 ) {
+                    byteArrayOutputStream.write(buffer, 0, len);
+                    length += len;
+                }
+                byteArrayOutputStream.flush();
+            } catch (IOException e) {
+            }
+        }
+        public InputStream getInputStream() {
+            if (byteArrayOutputStream== null)
+                return null;
+            return new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
+        }
+        public int getLength() {
+            return length;
+        }
+    }
+}

+ 21 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/tool/callback/BaseResponse.java

@@ -0,0 +1,21 @@
+package cn.com.ctop.toutiao.modules.tool.callback;
+
+
+import com.fasterxml.jackson.annotation.JsonAlias;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+@AllArgsConstructor
+public class BaseResponse implements Serializable {
+    @JsonAlias("StatusCode")
+    private Integer statusCode;
+    @JsonAlias("StatusMessage")
+    private String StatusMessage;
+
+    public static BaseResponse ok() {
+        return new BaseResponse(0, "ok");
+    }
+}

+ 16 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/tool/callback/CallbackResponse.java

@@ -0,0 +1,16 @@
+package cn.com.ctop.toutiao.modules.tool.callback;
+
+import com.fasterxml.jackson.annotation.JsonAlias;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class CallbackResponse {
+    @JsonAlias("BaseResp")
+    private BaseResponse baseResp;
+    @JsonAlias("challenge")
+    @JsonInclude(JsonInclude.Include.NON_EMPTY)
+    private Integer challenge;
+}