From 19533a17aa55fafc70d0a385928e785cb50e1ebc Mon Sep 17 00:00:00 2001
From: admin <2780501319@qq.com>
Date: 星期五, 30 七月 2021 02:05:14 +0800
Subject: [PATCH] 爱奇艺视频更新

---
 src/main/java/com/yeshi/buwan/controller/parser/ConfigParser.java |   37 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/yeshi/buwan/controller/parser/ConfigParser.java b/src/main/java/com/yeshi/buwan/controller/parser/ConfigParser.java
index 7517485..df8131e 100644
--- a/src/main/java/com/yeshi/buwan/controller/parser/ConfigParser.java
+++ b/src/main/java/com/yeshi/buwan/controller/parser/ConfigParser.java
@@ -2,7 +2,9 @@
 
 import java.io.PrintWriter;
 import java.lang.reflect.Type;
+import java.math.BigDecimal;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -67,10 +69,35 @@
             // 榛樿涓哄簲鐢ㄥ疂
             channel = "qq";
         }
-        adConfig = new Gson().fromJson(jsonObject.optJSONObject(channel).toString(), ADConfig.class);
+        JSONObject channelAd = jsonObject.optJSONObject(channel);
+        adConfig = new Gson().fromJson(channelAd.toString(), ADConfig.class);
         if (version >= adConfig.getVersion()) {
             adConfig = null;
         }
+        //鏍煎紡濡備笅:
+        //{"typeProperties":{"csj":{"weight":1,"pid":"123123"},"gdt":{"weight":1,"pid":"123123"}}}
+        if (adConfig != null && channelAd.optJSONObject("typeProbability") != null) {
+            JSONObject properties = channelAd.optJSONObject("typeProbability");
+
+            BigDecimal total = new BigDecimal(0);
+            for (Iterator<String> its = properties.keys(); its.hasNext(); ) {
+                String k = its.next();
+                total = total.add(new BigDecimal(properties.optJSONObject(k).optString("weight")));
+            }
+            BigDecimal random = total.multiply(new BigDecimal(Math.random()));
+            total = new BigDecimal(0);
+            for (Iterator<String> its = properties.keys(); its.hasNext(); ) {
+                String k = its.next();
+                total = total.add(new BigDecimal(properties.optJSONObject(k).optString("weight")));
+                if (random.compareTo(total) < 0) {
+                    adConfig.setPid(properties.optJSONObject(k).optString("pid"));
+                    adConfig.setType(k);
+                    break;
+                }
+            }
+
+        }
+
 
         return adConfig;
     }
@@ -226,6 +253,12 @@
             adConfig = null;
         adNew.put("splashHotStart", gson.toJson(adConfig));
 
+        //鍏朵粬骞垮憡
+        adConfig = getAdShowType("ad_other", acceptData.getChannel(), acceptData.getVersion(), map);
+        if (hiddenAll)
+            adConfig = null;
+        adNew.put("other", gson.toJson(adConfig));
+
 
         data.put("ad", ad);
         data.put("adNew", adNew);
@@ -294,6 +327,8 @@
         public void setPid(String pid) {
             this.pid = pid;
         }
+
+
     }
 
 }

--
Gitblit v1.8.0