Files
kami_itunes_june/AppleBatch_June.Utils/AppleGuidManage.cs
2024-07-22 00:43:14 +08:00

103 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
namespace AppleBatch_June.Utils
{
public static class AppleGuidManage
{
private static Dictionary<string, string> GuidIdKeyLists = new Dictionary<string, string>();
private static readonly object GuidIdKeyLock = new object();
public static string getIndeedApplePwd(string applePwd)
{
try
{
if (applePwd.Length <= 8)
{
return applePwd;
}
if (applePwd.Length >= 14 && int.TryParse(applePwd.Substring(applePwd.Length - 6), out var _))
{
return applePwd.Substring(0, applePwd.Length - 6);
}
return applePwd;
}
catch (Exception)
{
return applePwd;
}
}
public static string getIdGuid(string appleid, string pwd)
{
string mD5_ = Tools.GetMD5_32(appleid.Trim() + "|" + getIndeedApplePwd(pwd.Trim()) + "|liuyue_Bach_201ls");
lock (GuidIdKeyLock)
{
if (GuidIdKeyLists.ContainsKey(mD5_))
{
return GuidIdKeyLists[mD5_];
}
}
return "";
}
public static void UpIdGuid(string appleid, string pwd)
{
string mD5_ = Tools.GetMD5_32(appleid.Trim() + "|" + getIndeedApplePwd(pwd.Trim()) + "|liuyue_Bach_201ls");
string value = Tools.GenerateTimeStamp().ToString();
bool flag = false;
lock (GuidIdKeyLock)
{
if (GuidIdKeyLists.ContainsKey(mD5_))
{
GuidIdKeyLists[mD5_] = value;
}
else
{
GuidIdKeyLists.Add(mD5_, value);
flag = true;
}
}
try
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add("addTime", value);
if (flag)
{
dictionary.Add("type", "guidManage");
dictionary.Add("value1", mD5_);
SqliteHelper.ExecuteInsert("itunes_db", dictionary);
}
else
{
Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
dictionary2.Add("value1", mD5_);
SqliteHelper.ExecuteUpdate("itunes_db", dictionary2, dictionary);
}
}
catch (Exception)
{
}
}
public static void InitAppleGuid()
{
string text = "guidManage";
string total = "";
string fields = "addTime,value1";
foreach (DataRow row in SqliteHelper.QueryTable("itunes_db", ref total, fields, "type='" + text + "' and (value16 ='" + Tools.GetMD5_32(HttpUtility.UrlEncode(AppSysConfig.userName) + "aaa").Substring(10) + "' or value16 IS NULL ) ", "id desc", "").Rows)
{
long? num = row["addTime"] as long?;
string key = row["value1"] as string;
if (!GuidIdKeyLists.ContainsKey(key))
{
GuidIdKeyLists.Add(key, num.Value.ToString());
}
}
}
}
}