提交
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEditor;
|
||||
|
||||
public class BrigdeIOS
|
||||
{
|
||||
[DllImport("__Internal")]
|
||||
public static extern 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);
|
||||
// [DllImport("__Internal")]
|
||||
// public static extern void SetTouchWebview(bool flag, bool force = false);
|
||||
|
||||
// [DllImport("__Internal")]
|
||||
// public static extern void ScrollWebview(float dx, float dy);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void SetPadding(float left, float top, float right, float bottom);
|
||||
[DllImport("__Internal")]
|
||||
public static extern void SetDarkThough(bool though);
|
||||
[DllImport("__Internal")]
|
||||
public static extern void SetBtn(int left, int top, int right, int bottom);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void ShowH5View(bool flag);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void SetIconProgress(float val);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void ShowFlyBtn(bool flag);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void setFlyBtnTag(bool flag);
|
||||
[DllImport("__Internal")]
|
||||
public static extern void setRewardBtnTag(bool flag);
|
||||
[DllImport("__Internal")]
|
||||
public static extern void copyText(string text);
|
||||
[DllImport("__Internal")]
|
||||
public static extern void OpenWv();
|
||||
[DllImport("__Internal")]
|
||||
public static extern void showGameA(bool flag);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08a3414d3ce94b6783b0079b4fbe8a6e
|
||||
timeCreated: 1730193210
|
||||
@@ -126,7 +126,7 @@ namespace BingoBrain
|
||||
|
||||
if (!json.StartsWith("{"))
|
||||
{
|
||||
json = Encoding.UTF8.GetString(Base64Kit_sdk.Decrypt(Encoding.UTF8.GetBytes(json),
|
||||
json = Encoding.UTF8.GetString(Base64Kit_sdk.DecryptJson(Encoding.UTF8.GetBytes(json),
|
||||
NetworkManager.packName));
|
||||
}
|
||||
Debug.Log("转化后的json" + json);
|
||||
|
||||
@@ -32,8 +32,8 @@ public class LoginSystem_sdk
|
||||
// device_id ="E742FE8B-C32E-56A7-8F8A-6B3BC0F3169",
|
||||
pack_name = NetworkManager.packName,
|
||||
app_version = Application.version,
|
||||
// channel = BingoBea.Instance.attribution,
|
||||
// sim = WebviewManager.haveSimCard
|
||||
secret = "FJC3WBAF2", // 这里的值要和你们项目约定的 Secret 保持一致
|
||||
|
||||
};
|
||||
Debug.Log(JsonConvert.SerializeObject(requestLoginData));
|
||||
Debug.Log(SystemInfo.deviceUniqueIdentifier);
|
||||
@@ -77,7 +77,7 @@ public class LoginSystem_sdk
|
||||
|
||||
// return;
|
||||
// }
|
||||
|
||||
|
||||
NetworkKit_sdk.CDNUrl = $"{loginData.cdn_url}/";
|
||||
NetworkKit_sdk.SetCacheToken(loginData.token);
|
||||
|
||||
@@ -88,7 +88,7 @@ public class LoginSystem_sdk
|
||||
// {
|
||||
// RequestHeart();
|
||||
|
||||
// GameHelper.PostFunnelLogin("loginRecv", true);
|
||||
// GameHelper.PostFunnelLogin("loginRecv", true);
|
||||
ConfigSystem_sdk.Instance.OnRequestGetConfig();
|
||||
// if (GameHelper.IsGiftSwitch())
|
||||
// {
|
||||
@@ -170,4 +170,5 @@ public class RequestLoginData_sdk
|
||||
public string app_version;
|
||||
public string channel;
|
||||
public bool sim;
|
||||
public string secret;
|
||||
}
|
||||
@@ -12,6 +12,7 @@ using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using FutureCore;
|
||||
using ScrewsMaster;
|
||||
using System.IO;
|
||||
|
||||
|
||||
|
||||
@@ -35,16 +36,16 @@ public class NetworkKit_sdk
|
||||
PlayerPrefs.SetString(JarvisToken_SDK, token);
|
||||
}
|
||||
public const string DomainDebugUrl = @"https://sdkapi.jsoncompare.online/";
|
||||
public static string DomainRelease = "zoomatchsolo.top";
|
||||
|
||||
public static string DomainRelease = "web.zoomatchsolo.top";
|
||||
// https://web.zoomatchsolo.top
|
||||
// 改为只读属性,实时获取(等调用时 DomainRelease 早就初始化好了)
|
||||
public static string DomainReleaseUrl => $"https://{DomainRelease}/sdkapi/";
|
||||
public static string DomainReleaseUrl => $"https://{DomainRelease}/api/";
|
||||
|
||||
// 改为只读属性,实时获取
|
||||
#if JarvisRelease
|
||||
public static string CrazyUrl => DomainReleaseUrl;
|
||||
#else
|
||||
public static string CrazyUrl => DomainDebugUrl;
|
||||
public static string CrazyUrl => DomainDebugUrl;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -54,10 +55,10 @@ public class NetworkKit_sdk
|
||||
string requestJson = JsonConvert.SerializeObject(requestData);
|
||||
|
||||
string url2 = url;
|
||||
#if JarvisRelease
|
||||
url2 = Base64Kit_sdk.Encode(url);
|
||||
requestJson = Base64Kit_sdk.Encode(requestJson);
|
||||
#endif
|
||||
// #if JarvisRelease
|
||||
// url2 = Base64Kit_sdk.Encode(url);
|
||||
// requestJson = Base64Kit_sdk.Encode(requestJson);
|
||||
// #endif
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(requestJson);
|
||||
string url1 = CrazyUrl + url2;
|
||||
Debug.Log($"Url: {url1}");
|
||||
@@ -79,22 +80,24 @@ public class NetworkKit_sdk
|
||||
yield return loginRequest.SendWebRequest();
|
||||
if (loginRequest.result is not UnityWebRequest.Result.Success)
|
||||
{
|
||||
string receiveContent = loginRequest.downloadHandler.text;
|
||||
onCompleted?.Invoke(false, default);
|
||||
Debug.Log(url + "cuowude--------" + JsonConvert.SerializeObject(loginRequest));
|
||||
Debug.Log(url + "cuowude--------" + receiveContent);
|
||||
}
|
||||
else
|
||||
{
|
||||
string receiveContent = loginRequest.downloadHandler.text;
|
||||
Debug.Log(url + "--------" + receiveContent);
|
||||
#if JarvisRelease
|
||||
if (!receiveContent.IsNullOrWhiteSpace())
|
||||
{
|
||||
receiveContent = receiveContent.Substring(0, receiveContent.Length - 1);
|
||||
receiveContent = receiveContent.Substring(1);
|
||||
receiveContent = Base64Kit_sdk.Decode(receiveContent);
|
||||
receiveContent = Base64Kit_sdk.Decrypt(receiveContent, DomainRelease);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Debug.Log(url + "--------" + loginRequest.downloadHandler.text);
|
||||
Debug.Log(url + "--------" + receiveContent);
|
||||
|
||||
var response = JsonConvert.DeserializeObject<ResponseData_sdk>(receiveContent);
|
||||
|
||||
if (response?.code == 0)
|
||||
@@ -347,72 +350,82 @@ public class NetworkKit_sdk
|
||||
}
|
||||
public class Base64Kit_sdk
|
||||
{
|
||||
public static string Base64Encode(string source)
|
||||
public static string Decrypt(string encryptedBase64, string secret)
|
||||
{
|
||||
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 = NetworkKit_sdk.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)
|
||||
try
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
if (string.IsNullOrEmpty(encryptedBase64)) return string.Empty;
|
||||
|
||||
// 1. 容错处理:如果密文首尾有双引号,先去掉
|
||||
encryptedBase64 = encryptedBase64.Trim();
|
||||
if (encryptedBase64.StartsWith("\"") && encryptedBase64.EndsWith("\""))
|
||||
{
|
||||
(bytes[i], bytes[j]) = (bytes[j], bytes[i]);
|
||||
encryptedBase64 = encryptedBase64.Substring(1, encryptedBase64.Length - 2);
|
||||
}
|
||||
|
||||
// 2. 将 URL 安全的 Base64 替换为标准 Base64 字符
|
||||
string standardBase64 = encryptedBase64.Replace('-', '+').Replace('_', '/');
|
||||
int mod4 = standardBase64.Length % 4;
|
||||
if (mod4 > 0)
|
||||
{
|
||||
standardBase64 += new string('=', 4 - mod4);
|
||||
}
|
||||
|
||||
// 3. 将 Base64 转换为字节数组
|
||||
byte[] cipherData = Convert.FromBase64String(standardBase64);
|
||||
|
||||
if (cipherData.Length < 16)
|
||||
{
|
||||
throw new Exception("密文长度过短,不满足 AES 块大小要求");
|
||||
}
|
||||
|
||||
// 4. 【生成 Key】将 Secret 进行 SHA256 哈希,得到 32 字节的 AES Key
|
||||
byte[] keyBytes;
|
||||
using (SHA256 sha256 = SHA256.Create())
|
||||
{
|
||||
keyBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(secret));
|
||||
}
|
||||
|
||||
// 5. 【提取 IV】密文的前 16 字节是随机生成的初始化向量 (IV)
|
||||
byte[] iv = new byte[16];
|
||||
Array.Copy(cipherData, 0, iv, 0, 16);
|
||||
|
||||
// 6. 【提取实际密文】16 字节之后的数据才是真正的加密数据
|
||||
int encryptedDataLength = cipherData.Length - 16;
|
||||
byte[] encryptedData = new byte[encryptedDataLength];
|
||||
Array.Copy(cipherData, 16, encryptedData, 0, encryptedDataLength);
|
||||
|
||||
// 7. 进行 AES-256-CBC 解密
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
aes.KeySize = 256;
|
||||
aes.BlockSize = 128;
|
||||
aes.Mode = CipherMode.CBC;
|
||||
aes.Padding = PaddingMode.PKCS7; // 对应 Go 的 PKCS7Padding
|
||||
|
||||
aes.Key = keyBytes;
|
||||
aes.IV = iv;
|
||||
|
||||
using (ICryptoTransform decryptor = aes.CreateDecryptor())
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream(encryptedData))
|
||||
{
|
||||
using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
|
||||
{
|
||||
using (StreamReader sr = new StreamReader(cs, Encoding.UTF8))
|
||||
{
|
||||
return sr.ReadToEnd(); // 解密出来的明文 JSON 字符串
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
(bytes[i], bytes[j]) = (bytes[j], bytes[i]);
|
||||
}
|
||||
UnityEngine.Debug.LogError("解密失败: " + ex.Message);
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var str = Encoding.UTF8.GetString(bytes);
|
||||
var str1 = Base64EncodeUtil.Base64Decode(str);
|
||||
var key = NetworkKit_sdk.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)
|
||||
{
|
||||
@@ -420,30 +433,7 @@ public class Base64Kit_sdk
|
||||
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)
|
||||
internal static byte[] DecryptJson(byte[] encryptedBase64, string secret)
|
||||
{
|
||||
if (encryptedBase64 == null || encryptedBase64.Length == 0) return encryptedBase64;
|
||||
var key = GenerateKey(secret);
|
||||
@@ -464,36 +454,6 @@ public class Base64Kit_sdk
|
||||
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('_', '/');
|
||||
|
||||
Reference in New Issue
Block a user