package com.mbridge.msdk.newreward.function.h; import android.text.TextUtils; import android.util.Base64; import com.ironsource.v8; import com.mbridge.msdk.MBridgeConstans; import com.mbridge.msdk.c.g; import com.mbridge.msdk.c.h; import com.mbridge.msdk.foundation.entity.CampaignEx; import com.mbridge.msdk.foundation.tools.af; import com.mbridge.msdk.foundation.tools.ak; import com.mbridge.msdk.foundation.tools.i; import java.util.Iterator; import java.util.List; import org.json.JSONArray; import org.json.JSONObject; /* loaded from: classes4.dex */ public final class b { public static CampaignEx a(String str, CampaignEx campaignEx) { JSONObject campaignToJsonObject; String str2; String str3; if (TextUtils.isEmpty(str)) { return campaignEx; } CampaignEx campaignEx2 = null; if (campaignEx != null) { try { campaignToJsonObject = CampaignEx.campaignToJsonObject(campaignEx); } catch (Throwable th) { af.b("HybridCommunicatorUtil", th.getMessage()); return campaignEx; } } else { campaignToJsonObject = null; } if (campaignToJsonObject != null) { JSONObject jSONObject = new JSONObject(str); String optString = jSONObject.optString(CampaignEx.JSON_KEY_NOTICE_URL); if (TextUtils.isEmpty(optString)) { optString = campaignEx.getNoticeUrl(); } String optString2 = jSONObject.optString(CampaignEx.JSON_KEY_CLICK_URL); if (TextUtils.isEmpty(optString2)) { optString2 = campaignEx.getClickURL(); } if (!str.contains("notice")) { JSONObject optJSONObject = jSONObject.optJSONObject(com.mbridge.msdk.foundation.same.a.j); if (optJSONObject != null) { str2 = String.valueOf(ak.a(com.mbridge.msdk.foundation.controller.c.m().c(), Integer.parseInt(optJSONObject.getString(com.mbridge.msdk.foundation.same.a.h)))); str3 = String.valueOf(ak.a(com.mbridge.msdk.foundation.controller.c.m().c(), Integer.parseInt(optJSONObject.getString(com.mbridge.msdk.foundation.same.a.i)))); } else { str2 = "-999"; str3 = "-999"; } if (optJSONObject != null && optJSONObject.length() > 0) { Iterator keys = optJSONObject.keys(); StringBuilder sb = new StringBuilder(); while (keys.hasNext()) { sb.append(v8.i.c); String next = keys.next(); String optString3 = optJSONObject.optString(next); if (com.mbridge.msdk.foundation.same.a.h.equals(next) || com.mbridge.msdk.foundation.same.a.i.equals(next)) { optString3 = String.valueOf(ak.a(com.mbridge.msdk.foundation.controller.c.m().c(), Integer.parseInt(optString3))); } sb.append(next); sb.append(v8.i.b); sb.append(optString3); } optString = optString + ((Object) sb); } optString2 = com.mbridge.msdk.click.c.a(campaignEx.getClickURL(), str2, str3); } else { if (!jSONObject.has(CampaignEx.JSON_KEY_DEEP_LINK_URL)) { campaignToJsonObject.put(CampaignEx.JSON_KEY_DEEP_LINK_URL, ""); } if (jSONObject.opt("akdlui") == null) { campaignToJsonObject.put("akdlui", ""); } } Iterator keys2 = jSONObject.keys(); while (keys2.hasNext()) { String next2 = keys2.next(); campaignToJsonObject.put(next2, jSONObject.getString(next2)); } if (!TextUtils.isEmpty(campaignEx.getCampaignUnitId())) { campaignToJsonObject.put("unitId", campaignEx.getCampaignUnitId()); } campaignToJsonObject.put(CampaignEx.JSON_KEY_CLICK_URL, optString2); campaignToJsonObject.put(CampaignEx.JSON_KEY_NOTICE_URL, optString); campaignEx2 = CampaignEx.parseCampaignWithBackData(campaignToJsonObject); } return campaignEx2 == null ? campaignEx : campaignEx2; } public static String a(String str, List list, boolean z) { JSONObject jSONObject = new JSONObject(); try { jSONObject.put(MBridgeConstans.PROPERTIES_UNIT_ID, str); jSONObject.put("sdk_info", "MAL_16.8.51,3.0.1"); JSONObject jSONObject2 = new JSONObject(); jSONObject2.put("isRootTemplateWebView", false); jSONObject2.put("playVideoMute", 2); jSONObject.put("sdkSetting", jSONObject2); jSONObject.put("device", new i(com.mbridge.msdk.foundation.controller.c.m().c()).a()); JSONArray jSONArray = new JSONArray(); if (list != null && !list.isEmpty()) { for (CampaignEx campaignEx : list) { jSONArray.put(CampaignEx.campaignToJsonObject(campaignEx, campaignEx.isReady(), a(campaignEx))); } } jSONObject.put("campaignList", jSONArray); String g = h.a().g(com.mbridge.msdk.foundation.controller.c.m().k()); if (!TextUtils.isEmpty(g)) { JSONObject jSONObject3 = new JSONObject(g); String c = h.a().c(str); if (!TextUtils.isEmpty(c)) { jSONObject3.put("ivreward", new JSONObject(c)); } jSONObject.put("appSetting", jSONObject3); } jSONObject.put("rewardSetting", com.mbridge.msdk.videocommon.d.b.a().b().k()); jSONObject.put("unitSetting", com.mbridge.msdk.videocommon.d.b.a().a(com.mbridge.msdk.foundation.controller.c.m().k(), str).E()); jSONObject.put("rw_plus", z ? "1" : "0"); } catch (Throwable th) { af.b("HybridCommunicatorUtil", th.getMessage()); } return jSONObject.toString(); } private static boolean a(CampaignEx campaignEx) { g b; try { String k = com.mbridge.msdk.foundation.controller.c.m().k(); long ad = (TextUtils.isEmpty(k) || (b = h.a().b(k)) == null) ? 0L : b.ad() * 1000; com.mbridge.msdk.videocommon.d.a b2 = com.mbridge.msdk.videocommon.d.b.a().b(); long f = b2 != null ? b2.f() : 0L; if (campaignEx != null) { return campaignEx.isSpareOffer(f, ad); } return false; } catch (Exception e) { af.b("HybridCommunicatorUtil", e.getMessage()); return false; } } public static String a(int i) { try { JSONObject jSONObject = new JSONObject(); jSONObject.put("code", i); String jSONObject2 = jSONObject.toString(); return !TextUtils.isEmpty(jSONObject2) ? Base64.encodeToString(jSONObject2.getBytes(), 2) : jSONObject2; } catch (Throwable th) { af.b("HybridCommunicatorUtil", th.getMessage()); return ""; } } public static String a(float f, float f2, int i) { int i2; JSONObject jSONObject = new JSONObject(); try { JSONObject jSONObject2 = new JSONObject(); jSONObject2.put(com.mbridge.msdk.foundation.same.a.h, ak.b(com.mbridge.msdk.foundation.controller.c.m().c(), f)); jSONObject2.put(com.mbridge.msdk.foundation.same.a.i, ak.b(com.mbridge.msdk.foundation.controller.c.m().c(), f2)); jSONObject2.put(com.mbridge.msdk.foundation.same.a.m, i); try { i2 = com.mbridge.msdk.foundation.controller.c.m().c().getResources().getConfiguration().orientation; } catch (Throwable th) { af.b("HybridCommunicatorUtil", th.getMessage()); i2 = 1; } jSONObject2.put(com.mbridge.msdk.foundation.same.a.k, i2); jSONObject2.put(com.mbridge.msdk.foundation.same.a.l, ak.d(com.mbridge.msdk.foundation.controller.c.m().c())); jSONObject.put(com.mbridge.msdk.foundation.same.a.j, jSONObject2); } catch (Throwable th2) { af.b("HybridCommunicatorUtil", th2.getMessage()); } return jSONObject.toString(); } }