mirror of
https://git.oceanpay.cc/danial/kami_itunes_june.git
synced 2025-12-18 22:31:24 +00:00
284 lines
9.9 KiB
C#
284 lines
9.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Threading.Tasks;
|
|
using AppleBatch_June.Model;
|
|
using AppleBatch_June.StartTaskModel;
|
|
using AppleBatch_June.Utils;
|
|
using DotNet.Utilities;
|
|
|
|
namespace AppleBatch_June.ExecuteTasks
|
|
{
|
|
public class AreaQueryTask : BaseTask
|
|
{
|
|
public static AreaQueryTask Instance { get; private set; }
|
|
|
|
static AreaQueryTask()
|
|
{
|
|
Instance = new AreaQueryTask("区域查询");
|
|
}
|
|
|
|
public AreaQueryTask(string _taskName)
|
|
: base(_taskName)
|
|
{
|
|
}
|
|
|
|
public void AreaRequestTask(int TaskSize, bool openVpn, List<AppleAcount> lvItems, Action startAct, Action endTakAct, Action<string, AreaRequestModel> resut, string type = "area")
|
|
{
|
|
TaskSize = Tools.getTaskSize(openVpn, lvItems.Count);
|
|
if (!base.isRun)
|
|
{
|
|
AppleExecuteTask.TaskRunAppleIdCount = 0L;
|
|
AppleExecuteTask.TaskRunModels.Clear();
|
|
startAct?.Invoke();
|
|
base.isRun = true;
|
|
Task.Run(delegate
|
|
{
|
|
base.TaskIsRun = true;
|
|
base.baseEndTakAct = endTakAct;
|
|
Task[] array = new Task[TaskSize];
|
|
for (int i = 0; i < TaskSize; i++)
|
|
{
|
|
ApiNetReq.startNowFun = ((type == "area") ? 5 : 2);
|
|
array[i] = Task.Run(delegate
|
|
{
|
|
string guid = Guid.NewGuid().ToString("n");
|
|
TaskRunModel taskRunModel = new TaskRunModel
|
|
{
|
|
guid = guid,
|
|
isRuning = false
|
|
};
|
|
AppleExecuteTask.TaskRunModels.Add(taskRunModel);
|
|
while (base.isRun)
|
|
{
|
|
AppleAcount appleAcount = null;
|
|
AreaRequestModel model = new AreaRequestModel();
|
|
model.state = 0;
|
|
try
|
|
{
|
|
lock (lvItems)
|
|
{
|
|
appleAcount = lvItems.Where((AppleAcount c) => !c.isAct).FirstOrDefault();
|
|
if (appleAcount == null)
|
|
{
|
|
break;
|
|
}
|
|
appleAcount.isAct = true;
|
|
}
|
|
string notityKey = appleAcount.guidTag;
|
|
if (BaseTask.startRuning(taskRunModel, delegate(string appleid, DisplyType reustType, string dasReust2)
|
|
{
|
|
resut?.Invoke(notityKey, model.Init(0, dasReust2));
|
|
}, notityKey))
|
|
{
|
|
resut?.Invoke(notityKey, model.Init(0, "正在处理"));
|
|
if (AppSysConfig.iTunesisRemoteLogin)
|
|
{
|
|
HttpResult httpResult = APIUtlis.QueryInfo(appleAcount.appleId, appleAcount.applePwd + (appleAcount.isDoubleModl ? appleAcount.DoublePwd : ""), type);
|
|
if (httpResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
object obj = Tools.Todejosn<object>(httpResult.Html);
|
|
string text = ((dynamic)obj)["Message"];
|
|
if (string.IsNullOrEmpty(text) || text == "失败:")
|
|
{
|
|
int num = 0;
|
|
do
|
|
{
|
|
httpResult = APIUtlis.QueryInfo(appleAcount.appleId, appleAcount.applePwd + ((!appleAcount.isDoubleModl) ? "" : appleAcount.DoublePwd), type);
|
|
if (httpResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
obj = Tools.Todejosn<object>(httpResult.Html);
|
|
text = ((dynamic)obj)["Message"];
|
|
if (text == "失败:")
|
|
{
|
|
text = "";
|
|
}
|
|
}
|
|
num++;
|
|
}
|
|
while (num < 5 && string.IsNullOrEmpty(text));
|
|
}
|
|
if (((dynamic)obj)["Code"] == "0000")
|
|
{
|
|
Dictionary<string, object> dictionary = ((dynamic)obj)["Data"] as Dictionary<string, object>;
|
|
object obj2 = ((dynamic)obj)["Data"]["ServerId"];
|
|
object obj3 = ((dynamic)obj)["Data"]["bannal"];
|
|
string value = ((dynamic)obj)["Data"]["Area"];
|
|
string text2 = ((dynamic)obj)["Data"]["msg"];
|
|
if (dictionary.ContainsKey("nextServerId"))
|
|
{
|
|
int num2 = Tools.ToInt((dynamic)dictionary["nextServerId"], 0);
|
|
bool flag;
|
|
if (((!(flag = num2 > 0)) ? ((object)flag) : (flag & string.IsNullOrEmpty((dynamic)obj3))) && string.IsNullOrEmpty((dynamic)obj2) && string.IsNullOrEmpty(value))
|
|
{
|
|
string[] array3 = AppSysConfig.getConfig("UpIdGuidKeyWork").Split('|');
|
|
foreach (string value2 in array3)
|
|
{
|
|
if (text2.Contains(value2))
|
|
{
|
|
AppleGuidManage.UpIdGuid(appleAcount.appleId, appleAcount.applePwd + (appleAcount.isDoubleModl ? appleAcount.DoublePwd : ""));
|
|
httpResult = APIUtlis.QueryInfo(appleAcount.appleId, appleAcount.applePwd + (appleAcount.isDoubleModl ? appleAcount.DoublePwd : ""), type);
|
|
if (httpResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
obj = Tools.Todejosn<object>(httpResult.Html);
|
|
text = ((dynamic)obj)["Message"];
|
|
if (text == "失败:")
|
|
{
|
|
text = "";
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (((dynamic)obj)["Code"] == "0000")
|
|
{
|
|
Dictionary<string, object> dictionary2 = ((dynamic)obj)["Data"] as Dictionary<string, object>;
|
|
object obj4 = ((dynamic)obj)["Data"]["ServerId"];
|
|
object obj5 = ((dynamic)obj)["Data"]["bannal"];
|
|
if (string.IsNullOrEmpty((dynamic)obj5))
|
|
{
|
|
obj5 = "0";
|
|
}
|
|
string area = ((dynamic)obj)["Data"]["Area"];
|
|
string isDisabledAccount = ((dynamic)obj)["Data"]["isDisabledAccount"];
|
|
if (dictionary2.ContainsKey("extend"))
|
|
{
|
|
model.extension = (dynamic)dictionary2["extend"];
|
|
}
|
|
model.msg = ((dynamic)obj)["Data"]["msg"];
|
|
model.ServerId = (dynamic)obj4;
|
|
model.balance = (dynamic)obj5;
|
|
model.Area = AppleUtlis.GetAreaByArea(area);
|
|
model.state = 1;
|
|
model.isDisabledAccount = isDisabledAccount;
|
|
resut?.Invoke(notityKey, model);
|
|
}
|
|
else
|
|
{
|
|
resut?.Invoke(notityKey, model.Init(1, ((dynamic)obj)["Message"]));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
resut?.Invoke(notityKey, model.Init(1, "网络请求失败:" + httpResult.StatusCode));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
HttpResult isLogin = APIUtlis.getIsLogin((type == "area") ? 5 : 2);
|
|
if (isLogin.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
object obj6 = Tools.Todejosn<object>(isLogin.Html);
|
|
if (((dynamic)obj6)["Code"] == "0000")
|
|
{
|
|
if (((dynamic)obj6)["Data"]["integral"] >= AppSysConfig.getTypeById((type == "area") ? 5 : 2).consNum)
|
|
{
|
|
resut?.Invoke(notityKey, model.Init(0, "开始登录.."));
|
|
ItunesUtlis itunesUtlis = new ItunesUtlis(this, notityKey, delegate(string apple, DisplyType Dtype, string reust)
|
|
{
|
|
if (Dtype == DisplyType.xinxi)
|
|
{
|
|
resut?.Invoke(notityKey, model.Init(-1, reust));
|
|
}
|
|
}, openVpn);
|
|
AppleItunesLogin appleItunesLogin = null;
|
|
bool isAppleSuccess = false;
|
|
string msgReust = "";
|
|
if (string.IsNullOrEmpty(itunesUtlis.ProxyIp))
|
|
{
|
|
itunesUtlis.ProxyIp = ProxyAccountCache.getProxyAccountIP(appleAcount.appleId);
|
|
}
|
|
appleItunesLogin = itunesUtlis.appleLogin(appleAcount.appleId, appleAcount.applePwd + (appleAcount.isDoubleModl ? appleAcount.DoublePwd : ""), 1, ref msgReust, out isAppleSuccess);
|
|
if (appleItunesLogin != null)
|
|
{
|
|
if (appleAcount.isDoubleModl)
|
|
{
|
|
appleItunesLogin.pwd = appleAcount.applePwd;
|
|
}
|
|
iTunesAccountLoginCache.addReddemUserInfo(appleAcount.appleId, appleItunesLogin);
|
|
string serverId = appleItunesLogin.ServerId.ToString();
|
|
model.ServerId = serverId;
|
|
model.balance = appleItunesLogin.Balance;
|
|
model.Area = appleItunesLogin.Area;
|
|
model.state = 1;
|
|
model.extension = appleItunesLogin.extension;
|
|
model.isDisabledAccount = appleItunesLogin.isDisabledAccount;
|
|
resut?.Invoke(notityKey, model.Init(1, "查询完成"));
|
|
}
|
|
else
|
|
{
|
|
resut?.Invoke(notityKey, model.Init(1, msgReust));
|
|
isAppleSuccess = false;
|
|
}
|
|
if (isAppleSuccess)
|
|
{
|
|
APIUtlis.ApiApplyAct((type == "area") ? 5 : 2, (type == "area") ? "区域查询" : "余额查询");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
resut?.Invoke(notityKey, model.Init(1, "点数不足,请联系客服充值"));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
resut?.Invoke(notityKey, model.Init(1, ((dynamic)obj6)["Message"]));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
resut?.Invoke(notityKey, model.Init(1, "网络请求失败"));
|
|
}
|
|
}
|
|
goto IL_1cb8;
|
|
}
|
|
}
|
|
catch (Exception ex2)
|
|
{
|
|
APIUtlis.ApiSeriveError(ex2);
|
|
if (appleAcount != null)
|
|
{
|
|
resut?.Invoke(appleAcount.guidTag, model.Init(-1, " 请求失败: " + ex2.Message));
|
|
}
|
|
goto IL_1cb8;
|
|
}
|
|
continue;
|
|
IL_1cb8:
|
|
BaseTask.endRuning(taskRunModel);
|
|
}
|
|
});
|
|
}
|
|
Task.WaitAll(array);
|
|
try
|
|
{
|
|
Task[] array2 = array;
|
|
foreach (Task task in array2)
|
|
{
|
|
if (task.Status == TaskStatus.RanToCompletion)
|
|
{
|
|
task.Dispose();
|
|
}
|
|
}
|
|
array = null;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
AppleExecuteTask.TaskRunModels.Clear();
|
|
base.TaskIsRun = false;
|
|
base.isRun = false;
|
|
endTakAct?.Invoke();
|
|
});
|
|
}
|
|
else
|
|
{
|
|
endTakAct?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
}
|