|
|
@@ -17,6 +17,7 @@ import org.springframework.web.server.ResponseStatusException;
|
|
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
import java.time.Instant;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.Semaphore;
|
|
|
@@ -95,6 +96,17 @@ public class TrackingController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @GetMapping("/tencent/v4/impression")
|
|
|
+ public Object tencentImpressionV4(HttpServletRequest request) throws Exception {
|
|
|
+ impressionSemaphore.acquire();
|
|
|
+ try {
|
|
|
+ return doImpression(request, "v4", 70);
|
|
|
+ } finally {
|
|
|
+ impressionSemaphore.release();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private Object doImpression(HttpServletRequest request, String trackingVersion, int deductionRate) throws Exception {
|
|
|
Map<String, String> params = flatQueryParams(request);
|
|
|
markTrackingVersion(params, trackingVersion, deductionRate);
|
|
|
@@ -178,6 +190,17 @@ public class TrackingController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @GetMapping("/tencent/v4/click")
|
|
|
+ public Object tencentClickV4(HttpServletRequest request, HttpServletResponse response)
|
|
|
+ throws Exception {
|
|
|
+ clickSemaphore.acquire();
|
|
|
+ try {
|
|
|
+ return doClick(request, response, "v4", 70);
|
|
|
+ } finally {
|
|
|
+ clickSemaphore.release();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private Object doClick(HttpServletRequest request, HttpServletResponse response,
|
|
|
String trackingVersion, int deductionRate)
|
|
|
throws Exception {
|
|
|
@@ -252,9 +275,9 @@ public class TrackingController {
|
|
|
// ─── 私有工具方法 ────────────────────────────────────────────────────────
|
|
|
|
|
|
private BidRecord bidRecordFromMediaResponse(NormalizedBidResponse response,
|
|
|
- String media, String traceId,
|
|
|
- String eventType,
|
|
|
- Map<String, String> mediaParams) {
|
|
|
+ String media, String traceId,
|
|
|
+ String eventType,
|
|
|
+ Map<String, String> mediaParams) {
|
|
|
BidRecord r = new BidRecord();
|
|
|
r.setQk(response.getQk());
|
|
|
r.setReqId(response.getReqId());
|
|
|
@@ -302,8 +325,8 @@ public class TrackingController {
|
|
|
}
|
|
|
|
|
|
private Map<String, Object> mediaBidRequest(HttpServletRequest request, String media,
|
|
|
- String traceId, Map<String, String> params,
|
|
|
- MediaPlacement placement) {
|
|
|
+ String traceId, Map<String, String> params,
|
|
|
+ MediaPlacement placement) {
|
|
|
MediaPlacement.Resolved resolved = placement.resolve(params);
|
|
|
List<Integer> actionTypes = placement.getActionTypes();
|
|
|
if (actionTypes == null || actionTypes.isEmpty()) actionTypes = List.of(0, 1, 2);
|
|
|
@@ -358,13 +381,13 @@ public class TrackingController {
|
|
|
|
|
|
private List<Map<String, Integer>> defaultBaiduAssets() {
|
|
|
return List.of(
|
|
|
- Map.of("templateId", 1, "ratio", 2),
|
|
|
- Map.of("templateId", 1, "ratio", 7),
|
|
|
- Map.of("templateId", 2, "ratio", 1),
|
|
|
- Map.of("templateId", 2, "ratio", 4),
|
|
|
- Map.of("templateId", 3, "ratio", 2),
|
|
|
- Map.of("templateId", 4, "ratio", 4),
|
|
|
- Map.of("templateId", 4, "ratio", 5)
|
|
|
+ Map.of("templateId", 1, "ratio", 2),
|
|
|
+ Map.of("templateId", 1, "ratio", 7),
|
|
|
+ Map.of("templateId", 2, "ratio", 1),
|
|
|
+ Map.of("templateId", 2, "ratio", 4),
|
|
|
+ Map.of("templateId", 3, "ratio", 2),
|
|
|
+ Map.of("templateId", 4, "ratio", 4),
|
|
|
+ Map.of("templateId", 4, "ratio", 5)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -377,7 +400,9 @@ public class TrackingController {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- /** 根据平台返回合理的移动设备UA,确保百度能识别为真实手机请求 */
|
|
|
+ /**
|
|
|
+ * 根据平台返回合理的移动设备UA,确保百度能识别为真实手机请求
|
|
|
+ */
|
|
|
private static String defaultMobileUa(String platform) {
|
|
|
if ("ios".equals(platform)) {
|
|
|
return "Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Mobile/15E148 Safari/604.1";
|
|
|
@@ -461,7 +486,9 @@ public class TrackingController {
|
|
|
return request.getRemoteAddr();
|
|
|
}
|
|
|
|
|
|
- private static String nvl(String s) { return s != null ? s : ""; }
|
|
|
+ private static String nvl(String s) {
|
|
|
+ return s != null ? s : "";
|
|
|
+ }
|
|
|
|
|
|
private String toJson(Object value) {
|
|
|
try {
|