mirror of
https://git.oceanpay.cc/danial/kami_itunes_june.git
synced 2025-12-18 21:21:34 +00:00
203 lines
6.7 KiB
C#
203 lines
6.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using AppleBatch_June.Model;
|
|
using AppleBatch_June.StartTaskModel;
|
|
|
|
namespace AppleBatch_June.ExecuteTasks
|
|
{
|
|
public class TiedCardTask : BaseTask
|
|
{
|
|
public static TiedCardTask Instance { get; private set; }
|
|
|
|
static TiedCardTask()
|
|
{
|
|
Instance = new TiedCardTask("绑定支付方式");
|
|
}
|
|
|
|
public TiedCardTask(string _taskName)
|
|
: base(_taskName)
|
|
{
|
|
}
|
|
|
|
public void ExecuteTiedCard(int TaskSize, bool openVpn, List<AppleAcount> lvItems, Action startAct, Action endTakAct, Action<string> sucessAct, Action<string, DisplyType, string> _action)
|
|
{
|
|
TaskSize = Tools.getTaskSize(openVpn, lvItems.Count);
|
|
if (!ShopBalanceTask.Instance.isRun)
|
|
{
|
|
AppleExecuteTask.TaskRunAppleIdCount = 0L;
|
|
AppleExecuteTask.TaskRunModels.Clear();
|
|
startAct?.Invoke();
|
|
Instance.isRun = true;
|
|
Instance.TaskIsRun = true;
|
|
base.baseEndTakAct = endTakAct;
|
|
Task.Run(delegate
|
|
{
|
|
ApiNetReq.startNowFun = 28;
|
|
Task[] array = new Task[TaskSize];
|
|
for (int i = 0; i < TaskSize; i++)
|
|
{
|
|
array[i] = Task.Run(delegate
|
|
{
|
|
string guid = Guid.NewGuid().ToString("n");
|
|
TaskRunModel taskRunModel = new TaskRunModel
|
|
{
|
|
guid = guid,
|
|
isRuning = false
|
|
};
|
|
AppleExecuteTask.TaskRunModels.Add(taskRunModel);
|
|
while (Instance.isRun)
|
|
{
|
|
AppleAcount appleAcount = null;
|
|
try
|
|
{
|
|
lock (lvItems)
|
|
{
|
|
appleAcount = lvItems.Where((AppleAcount c) => !c.isAct).FirstOrDefault();
|
|
if (appleAcount == null)
|
|
{
|
|
break;
|
|
}
|
|
appleAcount.isAct = true;
|
|
}
|
|
if (BaseTask.startRuning(taskRunModel, _action, appleAcount.appleId))
|
|
{
|
|
_action?.Invoke(appleAcount.appleId, DisplyType.chongzhi, "");
|
|
ItunesUtlis itunesUtlis = new ItunesUtlis(this, appleAcount.appleId, _action, openVpn)
|
|
{
|
|
appleId = appleAcount.appleId
|
|
};
|
|
AppleItunesLogin itunesLogin = getItunesLogin(appleAcount, 28, _action, itunesUtlis);
|
|
if (itunesLogin != null)
|
|
{
|
|
itunesLogin.account = appleAcount.appleId;
|
|
itunesUtlis.appleId = itunesLogin.account;
|
|
_action?.Invoke(appleAcount.appleId, DisplyType.area, itunesLogin.Area);
|
|
if (appleAcount.addres.Contains("-"))
|
|
{
|
|
string[] array3 = appleAcount.addres.Split('-');
|
|
if (array3.Length == 3)
|
|
{
|
|
string text = array3[1];
|
|
if (text.Length == 6)
|
|
{
|
|
string creditCardNumber = array3[0];
|
|
string creditCardExpirationYear = text.Substring(0, 4);
|
|
string creditCardExpirationMonth = text.Substring(4, 2);
|
|
string creditVerificationNumber = array3[2];
|
|
if (itunesUtlis.addOrEditBillingInfoSrv(itunesLogin, creditCardNumber, creditCardExpirationYear, creditCardExpirationMonth, creditVerificationNumber))
|
|
{
|
|
ApiApplyAct(28, "添加支付方式");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_action?.Invoke(appleAcount.appleId, DisplyType.xinxi, "卡过期时间导入错误");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_action?.Invoke(appleAcount.appleId, DisplyType.xinxi, "卡号信息导入错误");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_action?.Invoke(appleAcount.appleId, DisplyType.xinxi, "激活或验证支付方式");
|
|
PaymentList paymentInfos = itunesUtlis.getPaymentInfos(itunesLogin);
|
|
if (paymentInfos != null)
|
|
{
|
|
string text2 = appleAcount.addres.Trim();
|
|
PaymentList.Paymentinfo[] array4 = paymentInfos?.data?.attributes?.paymentInfos;
|
|
foreach (PaymentList.Paymentinfo paymentinfo in array4)
|
|
{
|
|
if (paymentinfo != null && paymentinfo.requiresPSD2Check)
|
|
{
|
|
string text3 = "--";
|
|
if (paymentinfo.last4CCDigits != null)
|
|
{
|
|
text3 = paymentinfo.last4CCDigits;
|
|
}
|
|
PaymentList.ValidationErrors[] validationErrors = paymentinfo.validationErrors;
|
|
if (validationErrors != null && validationErrors.Length != 0 && paymentinfo.validationErrors[0].error != null)
|
|
{
|
|
_ = paymentinfo.validationErrors[0].error;
|
|
}
|
|
if (!string.IsNullOrEmpty(text2))
|
|
{
|
|
_action?.Invoke(appleAcount.appleId, DisplyType.xinxi, "正在激活支付方式,卡尾号:" + text3);
|
|
string paymentId = paymentinfo.paymentId;
|
|
string creditCardExpirationMonth2 = "••";
|
|
string creditCardExpirationYear2 = "••••";
|
|
if (paymentinfo.creditCardExpirationMonth != null)
|
|
{
|
|
creditCardExpirationMonth2 = paymentinfo.creditCardExpirationMonth;
|
|
}
|
|
if (paymentinfo.creditCardExpirationYear != null)
|
|
{
|
|
creditCardExpirationYear2 = paymentinfo.creditCardExpirationYear;
|
|
}
|
|
string msg = "";
|
|
if (itunesUtlis.PaymentChallengeInitiate(paymentId, text2, creditCardExpirationMonth2, creditCardExpirationYear2, itunesLogin, ref msg))
|
|
{
|
|
_action?.Invoke(appleAcount.appleId, DisplyType.xinxi, msg + ",卡尾号:" + text3);
|
|
_action?.Invoke(appleAcount.appleId, DisplyType.forbidden, "成功");
|
|
ApiApplyAct(28, "添加支付方式");
|
|
break;
|
|
}
|
|
_action?.Invoke(appleAcount.appleId, DisplyType.error, "失败");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
sucessAct?.Invoke(appleAcount.appleId);
|
|
goto IL_0484;
|
|
}
|
|
}
|
|
catch (Exception ex2)
|
|
{
|
|
APIUtlis.ApiSeriveError(ex2);
|
|
if (appleAcount != null)
|
|
{
|
|
_action?.Invoke(appleAcount.appleId, DisplyType.xinxi, "请求失败:" + ex2.Message);
|
|
}
|
|
goto IL_0484;
|
|
}
|
|
continue;
|
|
IL_0484:
|
|
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();
|
|
Instance.TaskIsRun = false;
|
|
Instance.isRun = false;
|
|
endTakAct?.Invoke();
|
|
});
|
|
}
|
|
else
|
|
{
|
|
endTakAct?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
}
|