|
|
@@ -40,12 +40,12 @@ public class MediaPlacement {
|
|
|
public Resolved resolve(Map<String, String> params) {
|
|
|
String tagId = firstParam(params, "baidu_tag_id", "tag_id", "tagid");
|
|
|
if (tagId != null && !tagId.isBlank()) {
|
|
|
- Resolved r = resolveByTagId(tagId);
|
|
|
+ Resolved r = resolveAnyTagByPlatform(tagId, inferPlatform(params));
|
|
|
if (r != null) return r;
|
|
|
- throw new IllegalArgumentException("unknown baidu tag id: " + tagId);
|
|
|
+ throw new IllegalArgumentException("missing baidu appId for tag id: " + tagId);
|
|
|
}
|
|
|
|
|
|
- String platform = normalizePlatform(firstParam(params, "platform", "os", "system", "device_os"));
|
|
|
+ String platform = inferPlatform(params);
|
|
|
if (platform != null && !platform.isBlank()) {
|
|
|
Resolved r = resolveByPlatform(platform);
|
|
|
if (r != null) return r;
|
|
|
@@ -66,33 +66,26 @@ public class MediaPlacement {
|
|
|
throw new IllegalArgumentException("missing baidu_tag_id or platform");
|
|
|
}
|
|
|
|
|
|
- private Resolved resolveByTagId(String tagId) {
|
|
|
- if (platforms != null) {
|
|
|
- for (Map.Entry<String, BaiduAppPlacement> e : platforms.entrySet()) {
|
|
|
- BaiduAppPlacement p = e.getValue();
|
|
|
- if (p.getAppId() != null && p.getTagIds() != null && p.getTagIds().contains(tagId)) {
|
|
|
- return new Resolved(e.getKey(), p.getAppId(), tagId);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (baiduAppId != null && tagId.equals(baiduTagId)) {
|
|
|
- return new Resolved(null, baiduAppId, baiduTagId);
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
private Resolved resolveByPlatform(String platform) {
|
|
|
if (platforms == null) return null;
|
|
|
BaiduAppPlacement p = platforms.get(platform);
|
|
|
- if (p == null || p.getAppId() == null || p.getTagIds() == null || p.getTagIds().isEmpty()) {
|
|
|
+ if (p == null || p.getAppId() == null || p.getAppId().isBlank() || baiduTagId == null || baiduTagId.isBlank()) {
|
|
|
return null;
|
|
|
}
|
|
|
- if (p.getTagIds().size() > 1) {
|
|
|
- throw new IllegalArgumentException(
|
|
|
- "baidu_tag_id is required for platform " + platform
|
|
|
- + " because multiple tag ids are configured");
|
|
|
+ return new Resolved(platform, p.getAppId(), baiduTagId);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Resolved resolveAnyTagByPlatform(String tagId, String platform) {
|
|
|
+ if (platform != null && !platform.isBlank() && platforms != null) {
|
|
|
+ BaiduAppPlacement p = platforms.get(platform);
|
|
|
+ if (p != null && p.getAppId() != null && !p.getAppId().isBlank()) {
|
|
|
+ return new Resolved(platform, p.getAppId(), tagId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (baiduAppId != null && !baiduAppId.isBlank()) {
|
|
|
+ return new Resolved(platform, baiduAppId, tagId);
|
|
|
}
|
|
|
- return new Resolved(platform, p.getAppId(), p.getTagIds().get(0));
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
private static String firstParam(Map<String, String> p, String... keys) {
|
|
|
@@ -108,20 +101,41 @@ public class MediaPlacement {
|
|
|
if (value == null) return null;
|
|
|
return switch (value.toLowerCase().trim()) {
|
|
|
case "ios", "iphone", "ipad", "1" -> "ios";
|
|
|
- case "android", "安卓", "2" -> "android";
|
|
|
+ case "android", "安卓", "0", "2" -> "android";
|
|
|
default -> null;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ private static String inferPlatform(Map<String, String> params) {
|
|
|
+ String platform = normalizePlatform(firstParam(params, "platform", "os", "system", "device_os"));
|
|
|
+ if (platform != null) {
|
|
|
+ return platform;
|
|
|
+ }
|
|
|
+ if (hasAny(params, "idfaMD5", "idfa_md5", "idfaSHA1", "idfa_sha1", "idfa", "kenyid_caa", "kenyIdCaa", "caid")) {
|
|
|
+ return "ios";
|
|
|
+ }
|
|
|
+ if (hasAny(params, "oaidMD5", "oaid_md5", "oaid", "imeiMD5", "imei_md5", "imei", "androidIdMD5", "android_id_md5", "androidid", "androidId", "android_id")) {
|
|
|
+ return "android";
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean hasAny(Map<String, String> params, String... keys) {
|
|
|
+ for (String key : keys) {
|
|
|
+ String value = params.get(key);
|
|
|
+ if (value != null && !value.isBlank()) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
// ─── 嵌套类型 ─────────────────────────────────────────────────────────────
|
|
|
|
|
|
public static class BaiduAppPlacement {
|
|
|
private String appId;
|
|
|
- private List<String> tagIds;
|
|
|
public String getAppId() { return appId; }
|
|
|
public void setAppId(String v) { this.appId = v; }
|
|
|
- public List<String> getTagIds() { return tagIds; }
|
|
|
- public void setTagIds(List<String> v) { this.tagIds = v; }
|
|
|
}
|
|
|
|
|
|
/** 解析结果(对应 Go resolvedMediaPlacement) */
|