mirror of
https://git.oceanpay.cc/danial/kami_itunes_june.git
synced 2025-12-18 21:21:34 +00:00
294 lines
8.1 KiB
C#
294 lines
8.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using AppleBatch_June.ExecuteTasks;
|
|
using AppleBatch_June.Model;
|
|
using AppleBatch_June.Utils;
|
|
using DotNet.Utilities;
|
|
|
|
namespace AppleBatch_June.StartTaskModel
|
|
{
|
|
public class BaseTask : ITaskRunState
|
|
{
|
|
private bool _taskIsRun;
|
|
|
|
private AppleItunesLogin itunesLoginOld;
|
|
|
|
public virtual string TaskName { get; set; }
|
|
|
|
public bool TaskIsRun
|
|
{
|
|
get
|
|
{
|
|
return _taskIsRun;
|
|
}
|
|
set
|
|
{
|
|
_taskIsRun = value;
|
|
AppleExecuteTask.SetTaskIsRun(TaskName, _taskIsRun);
|
|
}
|
|
}
|
|
|
|
public bool isRun { get; set; }
|
|
|
|
protected Action baseEndTakAct { get; set; }
|
|
|
|
public BaseTask()
|
|
{
|
|
TaskName = "BaseTask";
|
|
}
|
|
|
|
public BaseTask(string _taskName)
|
|
{
|
|
TaskName = _taskName;
|
|
}
|
|
|
|
protected AppleItunesLogin getItunesLogin(AppleAcount account, int type, Action<string, DisplyType, string> _action, ItunesUtlis utlis, int isStore = 0, string newNotiyeKey = "")
|
|
{
|
|
if (string.IsNullOrEmpty(utlis.ProxyIp))
|
|
{
|
|
utlis.ProxyIp = ProxyAccountCache.getProxyAccountIP(account.appleId);
|
|
}
|
|
AppleItunesLogin appleItunesLogin = iTunesAccountLoginCache.getLoginIdUserInfo(account.appleId, account.applePwd);
|
|
if (appleItunesLogin == null || isStore == 2)
|
|
{
|
|
if (!string.IsNullOrEmpty(newNotiyeKey))
|
|
{
|
|
utlis.notyKey = newNotiyeKey;
|
|
}
|
|
appleItunesLogin = utlis.getItunesLogin(account, type, _action, isStore);
|
|
if (appleItunesLogin != null)
|
|
{
|
|
iTunesAccountLoginCache.addReddemUserInfo(account.appleId, appleItunesLogin);
|
|
}
|
|
}
|
|
return appleItunesLogin;
|
|
}
|
|
|
|
public AppleItunesLogin getItunesNewLogin(AppleAcount account, string notyKey, int type, Action<string, DisplyType, string> _action, ItunesUtlis utlis, bool isAgent = false)
|
|
{
|
|
_action?.Invoke(notyKey, DisplyType.xinxi, "正在处理");
|
|
HttpResult isLogin = APIUtlis.getIsLogin(type);
|
|
if (isLogin.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
dynamic val = Tools.Todejosn<object>(isLogin.Html);
|
|
if (val["Code"] == "0000")
|
|
{
|
|
if (val["Data"]["integral"] >= AppSysConfig.getTypeById(type).consNum)
|
|
{
|
|
if (AppSysConfig.iTunesisRemoteLogin)
|
|
{
|
|
_action?.Invoke(notyKey, DisplyType.chongzhi, "");
|
|
Dictionary<string, object> data = new Dictionary<string, object>
|
|
{
|
|
{ "appleId", account.appleId },
|
|
{
|
|
"applePwd",
|
|
account.applePwd + (account.isDoubleModl ? account.DoublePwd : "")
|
|
},
|
|
{ "type", "newLogion" }
|
|
};
|
|
HttpResult httpResult = APIUtlis.serviceSend(Tools.Toenjson(data));
|
|
if (httpResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
dynamic val2 = Tools.Todejosn<object>(httpResult.Html);
|
|
if (val2["Code"] != "0000")
|
|
{
|
|
int num = 0;
|
|
bool flag;
|
|
do
|
|
{
|
|
httpResult = APIUtlis.serviceSend(Tools.Toenjson(data));
|
|
if (httpResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
val2 = Tools.Todejosn<object>(httpResult.Html);
|
|
}
|
|
}
|
|
while ((!(flag = num < 2)) ? ((object)flag) : (flag & (val2["Code"] != "0000")));
|
|
}
|
|
if (val2["Code"] == "0000")
|
|
{
|
|
dynamic val3 = val2["Data"];
|
|
AppleItunesLogin appleItunesLogin = Tools.Todejosn<AppleItunesLogin>(val3);
|
|
if (!string.IsNullOrEmpty(appleItunesLogin.xtoken))
|
|
{
|
|
appleItunesLogin.serverIndex = val2["serverIndex"];
|
|
appleItunesLogin.account = account.appleId;
|
|
appleItunesLogin.pwd = account.applePwd;
|
|
itunesLoginOld = appleItunesLogin;
|
|
if (account.isDoubleModl)
|
|
{
|
|
if (AppSysConfig.DoubleGuid.ContainsKey(account.appleId))
|
|
{
|
|
AppSysConfig.DoubleGuid[account.appleId] = appleItunesLogin.Guid;
|
|
}
|
|
else
|
|
{
|
|
AppSysConfig.DoubleGuid.TryAdd(account.appleId, appleItunesLogin.Guid);
|
|
}
|
|
}
|
|
return appleItunesLogin;
|
|
}
|
|
if (appleItunesLogin.msg == "0000")
|
|
{
|
|
return getItunesNewLogin(account, notyKey, type, _action, utlis);
|
|
}
|
|
_action?.Invoke(notyKey, DisplyType.xinxi, appleItunesLogin.msg);
|
|
}
|
|
else
|
|
{
|
|
_action?.Invoke(notyKey, DisplyType.xinxi, val2["Message"]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!isAgent)
|
|
{
|
|
return getItunesNewLogin(account, notyKey, type, _action, utlis, isAgent: true);
|
|
}
|
|
_action?.Invoke(notyKey, DisplyType.xinxi, "网络请求失败");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string msgReust = "";
|
|
if (string.IsNullOrEmpty(utlis.ProxyIp))
|
|
{
|
|
utlis.ProxyIp = ProxyAccountCache.getProxyAccountIP(account.appleId);
|
|
}
|
|
bool isAppleSuccess;
|
|
AppleItunesLogin appleItunesLogin2 = utlis.appleLogin(account.appleId, account.applePwd + (account.isDoubleModl ? account.DoublePwd : ""), 2, ref msgReust, out isAppleSuccess);
|
|
if (appleItunesLogin2 != null)
|
|
{
|
|
appleItunesLogin2.account = account.appleId;
|
|
appleItunesLogin2.pwd = account.applePwd;
|
|
if (account.isDoubleModl)
|
|
{
|
|
appleItunesLogin2.pwd = account.applePwd;
|
|
}
|
|
itunesLoginOld = appleItunesLogin2;
|
|
return appleItunesLogin2;
|
|
}
|
|
_action?.Invoke(notyKey, DisplyType.xinxi, msgReust);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_action?.Invoke(notyKey, DisplyType.xinxi, "点数不足,请联系客服充值");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_action?.Invoke(notyKey, DisplyType.xinxi, val["Message"]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_action?.Invoke(notyKey, DisplyType.xinxi, "网络请求失败");
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static bool startRuning(TaskRunModel runModel, Action<string, DisplyType, string> _action, string appleId)
|
|
{
|
|
if (Tools.ToNetWorkInt(ConfigUtlis.getConfigValue("comNetworkConfig"), 0) == 3)
|
|
{
|
|
int num = Tools.ToInt(ConfigUtlis.getConfigValue("txtAdslIdCount"), 10);
|
|
if (AppleExecuteTask.TaskRunAppleIdCount >= num)
|
|
{
|
|
_action?.Invoke(appleId, DisplyType.xinxi, "等待拨号...");
|
|
bool flag = false;
|
|
do
|
|
{
|
|
flag = false;
|
|
foreach (TaskRunModel taskRunModel in AppleExecuteTask.TaskRunModels)
|
|
{
|
|
if (taskRunModel.isRuning)
|
|
{
|
|
flag = true;
|
|
break;
|
|
}
|
|
}
|
|
Thread.Sleep(new Random().Next(100, 300));
|
|
}
|
|
while (flag);
|
|
lock (AppleExecuteTask.obj)
|
|
{
|
|
if (AppleExecuteTask.TaskRunAppleIdCount >= num)
|
|
{
|
|
string configValue = ConfigUtlis.getConfigValue("txtAdslUserName");
|
|
string configValue2 = ConfigUtlis.getConfigValue("txtAdslPwd");
|
|
Thread.Sleep(new Random().Next(500, 1000));
|
|
_action?.Invoke(appleId, DisplyType.xinxi, "断开宽带连接");
|
|
RasTools.Disconnect();
|
|
Thread.Sleep(new Random().Next(200, 500));
|
|
_action?.Invoke(appleId, DisplyType.xinxi, "开始宽带重新拨号");
|
|
if (!RasTools.Connect(configValue, configValue2, out var errMsg))
|
|
{
|
|
_action?.Invoke(appleId, DisplyType.xinxi, "拨号失败:" + errMsg);
|
|
return false;
|
|
}
|
|
_action?.Invoke(appleId, DisplyType.xinxi, "重新拨号成功");
|
|
Thread.Sleep(new Random().Next(500, 1000));
|
|
AppleExecuteTask.TaskRunAppleIdCount = 0L;
|
|
}
|
|
}
|
|
}
|
|
AppleExecuteTask.TaskRunAppleIdCount++;
|
|
}
|
|
runModel.isRuning = true;
|
|
return true;
|
|
}
|
|
|
|
public static void endRuning(TaskRunModel runModel)
|
|
{
|
|
runModel.isRuning = false;
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
isRun = false;
|
|
Task.Run(delegate
|
|
{
|
|
try
|
|
{
|
|
int num = 0;
|
|
while (TaskIsRun)
|
|
{
|
|
Thread.Sleep(500);
|
|
num++;
|
|
if (num >= 80 && !isRun)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
if (TaskIsRun && !isRun)
|
|
{
|
|
TaskIsRun = false;
|
|
baseEndTakAct?.Invoke();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
});
|
|
}
|
|
|
|
public T getDicValue<T>(Dictionary<string, dynamic> data, string key)
|
|
{
|
|
if (data.ContainsKey(key))
|
|
{
|
|
return data[key];
|
|
}
|
|
return default(T);
|
|
}
|
|
|
|
public void ApiApplyAct(int type, string typeName)
|
|
{
|
|
APIUtlis.ApiApplyAct(type, typeName);
|
|
}
|
|
}
|
|
}
|