yumeng há 1 mês atrás
pai
commit
4ae4cadd68

+ 120 - 3
src/main/java/cn/com/ctop/track/controller/JingDongCpaController.java

@@ -2,7 +2,9 @@ package cn.com.ctop.track.controller;
 
 
 import cn.com.ctop.track.util.RedisUtil;
 import cn.com.ctop.track.util.RedisUtil;
 import cn.com.ctop.track.utils.Check;
 import cn.com.ctop.track.utils.Check;
+import cn.com.ctop.track.utils.HttpUtils;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.log4j.Logger;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.stereotype.Controller;
@@ -11,11 +13,13 @@ import org.springframework.web.bind.annotation.ResponseBody;
 
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
+import java.util.TreeMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeUnit;
 
 
 @Controller
 @Controller
+@Slf4j
 @RequestMapping("/jdCallback")
 @RequestMapping("/jdCallback")
 public class JingDongCpaController {
 public class JingDongCpaController {
     private static Logger logger = Logger.getLogger(JingDongCpaController.class);
     private static Logger logger = Logger.getLogger(JingDongCpaController.class);
@@ -23,8 +27,6 @@ public class JingDongCpaController {
     private RedisUtil redisUtil;
     private RedisUtil redisUtil;
 
 
 
 
-
-
     // 老链接 屏蔽5
     // 老链接 屏蔽5
     @RequestMapping(value = "/click")
     @RequestMapping(value = "/click")
     @ResponseBody
     @ResponseBody
@@ -65,7 +67,7 @@ public class JingDongCpaController {
     @RequestMapping(value = "/action")
     @RequestMapping(value = "/action")
     @ResponseBody
     @ResponseBody
     public JSONObject action(HttpServletRequest request,
     public JSONObject action(HttpServletRequest request,
-                            HttpServletResponse response) {
+                             HttpServletResponse response) {
         logger.info("行为回调数据:" + request.getQueryString());
         logger.info("行为回调数据:" + request.getQueryString());
         JSONObject returnJson = new JSONObject();
         JSONObject returnJson = new JSONObject();
         String queryString = request.getQueryString();
         String queryString = request.getQueryString();
@@ -75,6 +77,115 @@ public class JingDongCpaController {
             return returnJson;
             return returnJson;
         }
         }
         try {
         try {
+            String requestId = request.getParameter("cid");    //客户后台账户ID
+            String jd_event_type = request.getParameter("event_type");    //1 激活 4 表单提交
+            String event_time = request.getParameter("event_time");    //时间
+
+            if (jd_event_type.equals("1") || jd_event_type.equals("4")) {
+                String s = redisUtil.get(requestId);
+                if (!Check.isNull(s)) {
+                    JSONObject jsonObject = JSONObject.parseObject("s");
+                    Long accountId = jsonObject.getLong("accountId");
+                    String callback = jsonObject.getString("callback");
+                    if (Check.isNull(accountId) || Check.isNull(callback)) {
+                        returnJson.put("code", 200);
+                        returnJson.put("message", "SUCCESS");
+                        return returnJson;
+                    }
+                    TreeMap<String, Object> params = new TreeMap<>();
+                    String eventAccountKey = "event_" + accountId;
+                    String eventType = redisUtil.get(eventAccountKey);
+                    if (eventType.equals("1")) { // 转化类型为订单提交  订单提交回传订单提交 其他不关注
+                        if (jd_event_type.equals("4")) {
+                            params.put("event_type", 14);
+                            params.put("event_time", event_time);
+                            String eventAccountCountKey = "event_count_" + jd_event_type + accountId;
+                            String countStr = redisUtil.get(eventAccountCountKey);
+                            if (Check.isNull(countStr)) {
+                                redisUtil.add(eventAccountCountKey, 1);
+                            } else {
+                                Integer postCount = Integer.valueOf(countStr);
+                                if (postCount < 9) {
+                                    redisUtil.add(eventAccountCountKey, postCount + 1);
+                                } else {
+                                    redisUtil.add(eventAccountCountKey, 0);
+                                    log.info("扣量不回传,clickId:{}", requestId);
+                                    returnJson.put("code", 200);
+                                    returnJson.put("message", "SUCCESS");
+                                    return returnJson;
+
+                                }
+
+
+                            }
+
+
+                        } else {
+                            returnJson.put("code", 200);
+                            returnJson.put("message", "SUCCESS");
+                            return returnJson;
+                        }
+
+                    } else if (eventType.equals("2")) {
+                        if (jd_event_type.equals("1")) {
+                            params.put("event_type", 2);
+                            params.put("event_time", event_time);
+                            String eventAccountCountKey = "event_count_" + jd_event_type + accountId;
+                            String countStr = redisUtil.get(eventAccountCountKey);
+                            if (Check.isNull(countStr)) {
+                                redisUtil.add(eventAccountCountKey, 1);
+                            } else {
+                                Integer postCount = Integer.valueOf(countStr);
+                                if (postCount < 9) {
+                                    redisUtil.add(eventAccountCountKey, postCount + 1);
+                                } else {
+                                    redisUtil.add(eventAccountCountKey, 0);
+                                    log.info("扣量不回传,clickId:{}", requestId);
+                                    returnJson.put("code", 200);
+                                    returnJson.put("message", "SUCCESS");
+                                    return returnJson;
+                                }
+                            }
+
+                        } else if (jd_event_type.equals("4")) {
+                            params.put("event_type", 1);
+                            params.put("event_time", event_time);
+                            String eventAccountCountKey = "event_count_" + jd_event_type + accountId;
+                            String countStr = redisUtil.get(eventAccountCountKey);
+                            if (Check.isNull(countStr)) {
+                                redisUtil.add(eventAccountCountKey, 1);
+                            } else {
+                                Integer postCount = Integer.valueOf(countStr);
+                                if (postCount < 9) {
+                                    redisUtil.add(eventAccountCountKey, postCount + 1);
+                                } else {
+                                    redisUtil.add(eventAccountCountKey, 0);
+                                    log.info("扣量不回传,clickId:{}", requestId);
+                                    returnJson.put("code", 200);
+                                    returnJson.put("message", "SUCCESS");
+                                    return returnJson;
+                                }
+
+                            }
+
+                        } else {
+                            returnJson.put("code", 200);
+                            returnJson.put("message", "SUCCESS");
+                            return returnJson;
+                        }
+                    }
+                    StringBuffer stringBuffer = new StringBuffer();
+                    params.forEach((k, v) -> {
+                        stringBuffer.append("&").append(k).append("=").append(v);
+
+                    });
+                    callback += stringBuffer.toString();
+                    log.info("信息上报媒体信息:{}", callback);
+                    String result = HttpUtils.httpGetRequest(callback, null, null);
+                    log.info("信息上报媒体返回结果:{}", result.toString());
+                }
+            }
+
 
 
             returnJson.put("code", 200);
             returnJson.put("code", 200);
             returnJson.put("message", "SUCCESS");
             returnJson.put("message", "SUCCESS");
@@ -87,4 +198,10 @@ public class JingDongCpaController {
     }
     }
 
 
 
 
+    public static void main(String[] args) {
+        Integer i = 0;
+        i = i + 1;
+        System.err.println(i);
+    }
+
 }
 }