mirror of
https://git.oceanpay.cc/danial/kami_itunes_june.git
synced 2025-12-18 22:31:24 +00:00
832 lines
27 KiB
C#
832 lines
27 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using AppleBatch_June.Model;
|
|
using AppleBatch_June.StartTaskModel;
|
|
using DotNet.Utilities;
|
|
|
|
namespace AppleBatch_June.ExecuteTasks
|
|
{
|
|
public class PurchaseQueryTask : BaseTask
|
|
{
|
|
public class MethodsPayTotal
|
|
{
|
|
public string mnethods { get; set; }
|
|
|
|
public string currency { get; set; }
|
|
|
|
public int year { get; set; }
|
|
|
|
public decimal money { get; set; }
|
|
}
|
|
|
|
public string dirName = "";
|
|
|
|
private static readonly object wirteFileLock;
|
|
|
|
public string mergeName = DateTime.Now.ToString("MMddHHmm");
|
|
|
|
public static PurchaseQueryTask Instance { get; private set; }
|
|
|
|
static PurchaseQueryTask()
|
|
{
|
|
Instance = null;
|
|
wirteFileLock = new object();
|
|
Instance = new PurchaseQueryTask("账单查询");
|
|
}
|
|
|
|
public PurchaseQueryTask(string _taskName)
|
|
: base(_taskName)
|
|
{
|
|
}
|
|
|
|
public void ApplePurchase(int TaskSize, bool openVpn, int selectIndex, bool isExport, bool feeApp, bool CkBillMergeData, List<AppleAcount> lvItems, Action startAct, Action endTakAct, Action<string> sucessAct, Action<string, DisplyType, string> _action)
|
|
{
|
|
TaskSize = Tools.getTaskSize(openVpn, lvItems.Count);
|
|
if (!base.isRun)
|
|
{
|
|
AppleExecuteTask.TaskRunAppleIdCount = 0L;
|
|
AppleExecuteTask.TaskRunModels.Clear();
|
|
startAct?.Invoke();
|
|
base.isRun = true;
|
|
Task.Run(delegate
|
|
{
|
|
dirName = ConfigUtlis.path + "账单查询记录\\账单查询" + DateTime.Now.ToString("yyyy-MM-dd-HH点mm分");
|
|
base.TaskIsRun = true;
|
|
base.baseEndTakAct = endTakAct;
|
|
Task[] array = new Task[TaskSize];
|
|
ApiNetReq.startNowFun = 6;
|
|
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 (base.isRun)
|
|
{
|
|
AppleAcount appleAcount = null;
|
|
try
|
|
{
|
|
lock (lvItems)
|
|
{
|
|
appleAcount = lvItems.Where((AppleAcount c) => !c.isAct).FirstOrDefault();
|
|
if (appleAcount == null)
|
|
{
|
|
break;
|
|
}
|
|
appleAcount.isAct = true;
|
|
}
|
|
string guidTag = appleAcount.guidTag;
|
|
if (BaseTask.startRuning(taskRunModel, _action, guidTag))
|
|
{
|
|
_action?.Invoke(guidTag, DisplyType.xinxi, "正在处理");
|
|
ItunesUtlis itunesUtlis = new ItunesUtlis(this, guidTag, _action, openVpn);
|
|
AppleItunesLogin itunesLogin = getItunesLogin(appleAcount, 6, _action, itunesUtlis);
|
|
if (itunesLogin != null)
|
|
{
|
|
itunesLogin.account = appleAcount.appleId;
|
|
itunesUtlis.appleId = itunesLogin.account;
|
|
_action?.Invoke(guidTag, DisplyType.area, itunesLogin.Area.ToString());
|
|
string error = "";
|
|
DateTime gameLastDate = DateTime.Now.AddDays(2.0);
|
|
DateTime gameLatelyDate = DateTime.Parse("1990-01-01");
|
|
Tuple<string, DateTime, DateTime, string, string> puileYeas = getPuileYeas(itunesLogin, openVpn, selectIndex, isExport, feeApp, CkBillMergeData, _action, guidTag, itunesUtlis, ref error, ref gameLastDate, ref gameLatelyDate);
|
|
if (error == "0000")
|
|
{
|
|
string text = ((puileYeas.Item2.Date == DateTime.Now.AddDays(2.0).Date) ? "无" : puileYeas.Item2.ToString("yyyy-MM-dd"));
|
|
string text2 = ((puileYeas.Item3.Date == DateTime.Parse("1990-01-01").Date) ? "无" : puileYeas.Item3.ToString("yyyy-MM-dd"));
|
|
string text3 = ((gameLastDate.Date == DateTime.Now.AddDays(2.0).Date) ? "无" : gameLastDate.ToString("yyyy-MM-dd"));
|
|
string text4 = ((gameLatelyDate.Date == DateTime.Parse("1990-01-01").Date) ? "无" : gameLatelyDate.ToString("yyyy-MM-dd"));
|
|
_action?.Invoke(guidTag, DisplyType.xiaofeiriqi, (text == "无") ? text3 : text);
|
|
_action?.Invoke(guidTag, DisplyType.xiaofeiriqiNow, (text2 == "无") ? text4 : text2);
|
|
_action?.Invoke(guidTag, DisplyType.xiaofeijine, puileYeas.Item1.ToString());
|
|
_action?.Invoke(guidTag, DisplyType.lostBillNo, puileYeas.Item4.ToString());
|
|
APIUtlis.ApiApplyAct(6, "Apple消费日期查询");
|
|
string text5 = "";
|
|
if (selectIndex == 1)
|
|
{
|
|
text5 = ",最近30天消费记录";
|
|
}
|
|
if (selectIndex == 2)
|
|
{
|
|
text5 = ",最近90天消费记录";
|
|
}
|
|
_action?.Invoke(guidTag, DisplyType.xinxi, "账号余额:" + (string.IsNullOrEmpty(itunesLogin.Balance.Trim()) ? "0" : itunesLogin.Balance) + ",退款记录:" + puileYeas.Item5 + ",查询完成" + text5);
|
|
}
|
|
else
|
|
{
|
|
_action?.Invoke(guidTag, DisplyType.xinxi, error);
|
|
}
|
|
sucessAct?.Invoke(guidTag);
|
|
}
|
|
goto IL_0493;
|
|
}
|
|
}
|
|
catch (Exception ex2)
|
|
{
|
|
APIUtlis.ApiSeriveError(ex2);
|
|
if (appleAcount != null)
|
|
{
|
|
_action?.Invoke(appleAcount.guidTag, DisplyType.xinxi, "请求失败:" + ex2.Message);
|
|
}
|
|
goto IL_0493;
|
|
}
|
|
continue;
|
|
IL_0493:
|
|
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();
|
|
}
|
|
}
|
|
|
|
private Tuple<string, DateTime, DateTime, string, string> getPuileYeas(AppleItunesLogin itunelogin, bool openVpn, int selectIndex, bool isExport, bool feeApp, bool ckBillMergeData, Action<string, DisplyType, string> _action, string notityKey, ItunesUtlis utlis, ref string error, ref DateTime gameLastDate, ref DateTime gameLatelyDate)
|
|
{
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
if (isExport)
|
|
{
|
|
try
|
|
{
|
|
if (!Directory.Exists(ConfigUtlis.path + "账单查询记录\\"))
|
|
{
|
|
Directory.CreateDirectory(ConfigUtlis.path + "账单查询记录\\");
|
|
}
|
|
if (!Directory.Exists(dirName))
|
|
{
|
|
Directory.CreateDirectory(dirName);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
if (ckBillMergeData)
|
|
{
|
|
stringBuilder.Append("账号,国家,消费总金额,订单号,账号流水号,购买时间,账单金额,支付方式,购买设备,退款金额,账单内容\n");
|
|
}
|
|
else
|
|
{
|
|
stringBuilder.Append("订单号,账号流水号,购买时间,账单金额,支付方式,购买设备,退款金额,账单内容\n");
|
|
}
|
|
}
|
|
Dictionary<string, decimal> dictionary = new Dictionary<string, decimal>();
|
|
Dictionary<string, decimal> dictionary2 = new Dictionary<string, decimal>();
|
|
List<MethodsPayTotal> list = new List<MethodsPayTotal>();
|
|
Dictionary<string, int> dictionary3 = new Dictionary<string, int>();
|
|
DateTime dateTime = DateTime.Now.AddDays(2.0);
|
|
DateTime dateTime2 = DateTime.Parse("1990-01-01");
|
|
string text = "";
|
|
string text2 = "";
|
|
string item = "";
|
|
HttpItem httpItem = new HttpItem
|
|
{
|
|
Method = "GET",
|
|
Timeout = 100000,
|
|
UserAgent = itunelogin.UserAgent,
|
|
Accept = "*/*",
|
|
ResultType = ResultType.String,
|
|
ProtocolVersion = HttpVersion.Version11
|
|
};
|
|
string referer = (httpItem.URL = "https://p" + itunelogin.ServerId + "-buy.itunes.apple.com/commerce/account/purchases/count?isJsonApiFormat=true&page=1");
|
|
HttpResult httpResult = null;
|
|
httpItem.Header.Add("X-Dsid", itunelogin.dsis);
|
|
httpItem.Header.Add("X-Token", itunelogin.xtoken);
|
|
httpItem.Header.Add("Accept-Encoding", "gzip, deflate");
|
|
httpItem.Header.Add("Accept-Language", "zh-CN,zh;q=0.9,en;q=0");
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
string text4 = "";
|
|
foreach (KeyValuePair<string, string> cooki in itunelogin.cookis)
|
|
{
|
|
text4 = text4 + cooki.Key + "=" + cooki.Value + ";";
|
|
if (cooki.Key == "wosid-lite")
|
|
{
|
|
_ = cooki.Value;
|
|
}
|
|
}
|
|
httpItem.Cookie = text4;
|
|
httpResult = utlis.GetHttpReuslt(httpItem);
|
|
if (httpResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
break;
|
|
}
|
|
if (httpResult.Html.Contains("authentication"))
|
|
{
|
|
APIUtlis.serviceSend(Tools.Toenjson(new Dictionary<string, object>
|
|
{
|
|
{ "cookies", text4 },
|
|
{ "dsis", itunelogin.dsis },
|
|
{ "serverId", itunelogin.ServerId },
|
|
{ "xtoken", itunelogin.xtoken },
|
|
{ "userAgent", itunelogin.UserAgent },
|
|
{ "type", "IAgreeTTU" }
|
|
}));
|
|
_action?.Invoke(notityKey, DisplyType.xinxi, "账号掉线了,重新登录");
|
|
itunelogin = getItunesLogin(new AppleAcount
|
|
{
|
|
appleId = itunelogin.account,
|
|
applePwd = itunelogin.pwd
|
|
}, 6, _action, utlis, 2);
|
|
}
|
|
else
|
|
{
|
|
utlis.ProxyIp = "";
|
|
}
|
|
}
|
|
if (httpResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
dynamic val = Tools.Todejosn<object>(httpResult.Html);
|
|
httpItem.Header.Add("X-Apple-Store-Front", "143441-1,17");
|
|
httpItem.Header.Add("X-Apple-Software-Cuid", "d33ae51e148a7245b69e0b6eeb8e48ddc5280a30");
|
|
httpItem.Header.Add("X-Apple-Partner", "origin.0");
|
|
httpItem.Header.Add("X-Apple-Client-Application", "Software");
|
|
httpItem.Header.Add("X-Apple-Connection-Type", "WiFi");
|
|
httpItem.Header.Add("X-Apple-Client-Versions", "GameCenter/2.0");
|
|
Regex regex = new Regex("(\\p{Sc})?");
|
|
dynamic years = AppleUtlis.getYears(val, selectIndex);
|
|
try
|
|
{
|
|
foreach (object item2 in val["data"]["attributes"]["dates"]["years"])
|
|
{
|
|
foreach (KeyValuePair<string, object> item3 in (Dictionary<string, object>)(dynamic)item2)
|
|
{
|
|
if (item3.Key == "last90Days")
|
|
{
|
|
int value = ((dynamic)item3.Value)["items"];
|
|
dictionary3.Add("90", value);
|
|
}
|
|
else
|
|
{
|
|
string key = item3.Key;
|
|
int value2 = ((dynamic)item3.Value)["months"][0]["items"];
|
|
dictionary3.Add(key, value2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex2)
|
|
{
|
|
APIUtlis.ApiSeriveError(ex2);
|
|
}
|
|
DateTime dateTime3 = DateTime.Now.Date.AddDays(-30.0);
|
|
foreach (dynamic item4 in years)
|
|
{
|
|
int num = 1;
|
|
bool flag = false;
|
|
int num2 = 0;
|
|
do
|
|
{
|
|
flag = false;
|
|
string uRL = "https://p" + itunelogin.ServerId + "-buy.itunes.apple.com/commerce/account/purchases?isJsonApiFormat=true&page=" + num + "&range=" + item4;
|
|
httpItem.URL = uRL;
|
|
httpItem.Referer = referer;
|
|
_action?.Invoke(notityKey, DisplyType.xinxi, "查询" + item4 + "消费记录,第" + num + "页");
|
|
httpResult = utlis.GetHttpReuslt(httpItem);
|
|
if (httpResult.StatusCode == HttpStatusCode.OK && httpResult.Html != "操作已超时。" && !string.IsNullOrEmpty(httpResult.Html))
|
|
{
|
|
if (httpResult.Html.Contains("authentication"))
|
|
{
|
|
_action?.Invoke(notityKey, DisplyType.xinxi, "账号掉线了,重新登录");
|
|
itunelogin = getItunesLogin(new AppleAcount
|
|
{
|
|
appleId = itunelogin.account,
|
|
applePwd = itunelogin.pwd
|
|
}, 6, _action, utlis, 2);
|
|
if (itunelogin == null)
|
|
{
|
|
error = "重新登陆失败,请重新检测";
|
|
text = "0";
|
|
return new Tuple<string, DateTime, DateTime, string, string>(text, dateTime, dateTime2, item, text2);
|
|
}
|
|
continue;
|
|
}
|
|
num2 = 0;
|
|
num++;
|
|
dynamic val2 = Tools.Todejosn<object>(httpResult.Html);
|
|
flag = !(bool)val2["data"]["attributes"]["is-complete"];
|
|
foreach (object item5 in val2["data"]["attributes"]["purchases"])
|
|
{
|
|
Dictionary<string, object> dictionary4 = (Dictionary<string, object>)(dynamic)item5;
|
|
bool flag2 = (dynamic)dictionary4["pending"];
|
|
string text5 = "";
|
|
string value3 = "";
|
|
if (dictionary4.ContainsKey("items"))
|
|
{
|
|
{
|
|
IEnumerator enumerator5 = ((IEnumerable)(dynamic)dictionary4["items"]).GetEnumerator();
|
|
try
|
|
{
|
|
if (enumerator5.MoveNext())
|
|
{
|
|
Dictionary<string, object> data = (Dictionary<string, object>)(dynamic)enumerator5.Current;
|
|
text5 = getDicValue<string>(data, "item-name");
|
|
value3 = getDicValue<string>(data, "kind");
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
IDisposable disposable = enumerator5 as IDisposable;
|
|
if (disposable != null)
|
|
{
|
|
disposable.Dispose();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (AppSysConfig.getConfig("BillExcludeKind").Split(',').Contains(value3) || text5 == "iTunes Gift" || text5 == "Gift Card" || text5.Contains("Add Funds to Apple\u00a0ID"))
|
|
{
|
|
continue;
|
|
}
|
|
string text6 = "";
|
|
if (dictionary4.ContainsKey("billed-to"))
|
|
{
|
|
Dictionary<string, object> dictionary5 = (dynamic)dictionary4["billed-to"];
|
|
if (dictionary5.ContainsKey("methods"))
|
|
{
|
|
foreach (dynamic item6 in (dynamic)dictionary5["methods"])
|
|
{
|
|
text6 = (string)(text6 + item6["name"]);
|
|
}
|
|
}
|
|
}
|
|
if (flag2)
|
|
{
|
|
foreach (object item7 in (dynamic)dictionary4["items"])
|
|
{
|
|
Dictionary<string, object> data2 = (Dictionary<string, object>)(dynamic)item7;
|
|
string text7 = getDicValue<string>(data2, "price");
|
|
if (text7 == null)
|
|
{
|
|
text7 = "0";
|
|
}
|
|
if (!text7.Contains(".") && !ContetCuure(text7))
|
|
{
|
|
byte[] bytes = new byte[2] { 194, 160 };
|
|
string @string = Encoding.GetEncoding("UTF-8").GetString(bytes);
|
|
text7 = text7.Replace(",", ".").Replace(' ', '-').Replace("-", "")
|
|
.Replace("\u00a0", "")
|
|
.Replace(@string, "");
|
|
}
|
|
else
|
|
{
|
|
text7 = text7.Replace(",", "");
|
|
}
|
|
string text8 = Regex.Replace(text7, "[^\\d.\\d]", "");
|
|
text8 = text8.TrimStart('.');
|
|
if (!Regex.IsMatch(text8, "^[+-]?\\d*[.]?\\d*$"))
|
|
{
|
|
continue;
|
|
}
|
|
string text9 = text7.Replace(text8, "").TrimStart().Trim();
|
|
if (text9.Contains("¥"))
|
|
{
|
|
text9 = "¥";
|
|
}
|
|
if (!decimal.TryParse(regex.Replace(text8, ""), out var result))
|
|
{
|
|
continue;
|
|
}
|
|
DateTime dateTime4 = AppleUtlis.toDate(getDicValue<string>(data2, "purchase-date"));
|
|
if (result > 0m || feeApp)
|
|
{
|
|
if (result > 0m)
|
|
{
|
|
list.Add(new MethodsPayTotal
|
|
{
|
|
mnethods = text6,
|
|
money = result,
|
|
year = dateTime4.Year,
|
|
currency = text9
|
|
});
|
|
}
|
|
string text10 = "";
|
|
string dicValue = getDicValue<string>(data2, "report-a-problem-url");
|
|
if (!string.IsNullOrEmpty(dicValue))
|
|
{
|
|
text10 = new Regex("wo=([\\s\\S]*?)&").Match(dicValue).Groups[1].Value;
|
|
}
|
|
text10 = ((!string.IsNullOrEmpty(text10)) ? (text10 + "[待处理]") : "待处理");
|
|
string text11 = "";
|
|
try
|
|
{
|
|
text11 = ((dynamic)getDicValue<object>(data2, "item-id")).ToString();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
string text12 = dateTime4.ToString("yyyy-MM-dd");
|
|
string text13 = getDicValue<string>(data2, "price");
|
|
if (text13 == null)
|
|
{
|
|
text13 = "0";
|
|
}
|
|
text13 = ((ContetCuure(text13) || text13.Contains(".")) ? text13.Replace(",", "") : text13.Replace(",", "."));
|
|
string dicValue2 = getDicValue<string>(data2, "purchased-from");
|
|
bool dicValue3 = getDicValue<bool>(data2, "refunded");
|
|
string text14 = "";
|
|
if (dicValue3)
|
|
{
|
|
text14 = getDicValue<string>(data2, "refund-amount");
|
|
try
|
|
{
|
|
string text15 = "";
|
|
if (!text14.Contains(".") && !ContetCuure(text14))
|
|
{
|
|
byte[] bytes2 = new byte[2] { 194, 160 };
|
|
string string2 = Encoding.GetEncoding("UTF-8").GetString(bytes2);
|
|
text15 = text14.Replace(",", ".").Replace(' ', '-').Replace("-", "")
|
|
.Replace("\u00a0", "")
|
|
.Replace(string2, "");
|
|
}
|
|
else
|
|
{
|
|
text15 = text14.Replace(",", "");
|
|
}
|
|
string text16 = Regex.Replace(text15, "[^\\d.\\d]", "");
|
|
if (Regex.IsMatch(text16, "^[+-]?\\d*[.]?\\d*$"))
|
|
{
|
|
string text17 = text15.Replace(text16, "").TrimStart();
|
|
if (text17.Contains("¥"))
|
|
{
|
|
text17 = "¥";
|
|
}
|
|
if (decimal.TryParse(regex.Replace(text16, ""), out var result2) && result2 > 0m)
|
|
{
|
|
if (!dictionary2.ContainsKey(text17))
|
|
{
|
|
dictionary2.Add(text17, 0m);
|
|
}
|
|
dictionary2[text17] += result2;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex4)
|
|
{
|
|
APIUtlis.ApiSeriveError(ex4);
|
|
}
|
|
}
|
|
string text18 = getDicValue<string>(data2, "item-name").Replace(",", " ");
|
|
if (isExport)
|
|
{
|
|
stringBuilder.Append(text10 + "," + text11 + "," + text12 + "," + text13 + "," + text6 + "," + dicValue2 + "," + text14 + "," + text18 + "\n");
|
|
}
|
|
if (selectIndex == 1 && dateTime4 < dateTime3)
|
|
{
|
|
continue;
|
|
}
|
|
if (!dictionary.ContainsKey(text9))
|
|
{
|
|
dictionary.Add(text9, 0m);
|
|
}
|
|
dictionary[text9] += result;
|
|
if (dateTime4 < dateTime)
|
|
{
|
|
dateTime = dateTime4;
|
|
}
|
|
if (dateTime4 > dateTime2)
|
|
{
|
|
if (text10 != "待处理")
|
|
{
|
|
item = text10;
|
|
}
|
|
dateTime2 = dateTime4;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (dateTime4 < gameLastDate)
|
|
{
|
|
gameLastDate = dateTime4;
|
|
}
|
|
if (dateTime4 > gameLatelyDate)
|
|
{
|
|
gameLatelyDate = dateTime4;
|
|
}
|
|
}
|
|
}
|
|
continue;
|
|
}
|
|
string text19 = (dynamic)dictionary4["total"];
|
|
if (text19 == null)
|
|
{
|
|
text19 = "0";
|
|
}
|
|
string text20 = "";
|
|
if (!text19.Contains(".") && !ContetCuure(text19))
|
|
{
|
|
byte[] bytes3 = new byte[2] { 194, 160 };
|
|
string string3 = Encoding.GetEncoding("UTF-8").GetString(bytes3);
|
|
text20 = text19.Replace(",", ".").Replace(' ', '-').Replace("-", "")
|
|
.Replace("\u00a0", "")
|
|
.Replace(string3, "");
|
|
}
|
|
else
|
|
{
|
|
text20 = text19.Replace(",", "");
|
|
}
|
|
string text21 = Regex.Replace(text20, "[^\\d.\\d]", "");
|
|
text21 = text21.TrimStart('.');
|
|
if (!Regex.IsMatch(text21, "^[+-]?\\d*[.]?\\d*$"))
|
|
{
|
|
continue;
|
|
}
|
|
string text22 = text20.Replace(text21, "").TrimStart().Trim();
|
|
if (!decimal.TryParse(regex.Replace(text21, ""), out var result3))
|
|
{
|
|
continue;
|
|
}
|
|
DateTime dateTime5 = AppleUtlis.toDate(getDicValue<string>(dictionary4, "invoice-date"));
|
|
if (result3 > 0m || feeApp)
|
|
{
|
|
if (!dictionary.ContainsKey(text22))
|
|
{
|
|
dictionary.Add(text22, 0m);
|
|
}
|
|
if (result3 > 0m)
|
|
{
|
|
list.Add(new MethodsPayTotal
|
|
{
|
|
mnethods = text6,
|
|
money = result3,
|
|
year = dateTime5.Year,
|
|
currency = text22
|
|
});
|
|
}
|
|
if (selectIndex == 1 && dateTime5 < dateTime3)
|
|
{
|
|
continue;
|
|
}
|
|
dictionary[text22] += result3;
|
|
string dicValue4 = getDicValue<string>(dictionary4, "order-id");
|
|
if (dateTime5 < dateTime)
|
|
{
|
|
dateTime = dateTime5;
|
|
}
|
|
if (dateTime5 > dateTime2)
|
|
{
|
|
item = dicValue4;
|
|
dateTime2 = dateTime5;
|
|
}
|
|
foreach (object item8 in (dynamic)dictionary4["items"])
|
|
{
|
|
Dictionary<string, object> data3 = (Dictionary<string, object>)(dynamic)item8;
|
|
string text23 = "";
|
|
try
|
|
{
|
|
text23 = ((dynamic)getDicValue<object>(data3, "item-id")).ToString();
|
|
}
|
|
catch (Exception ex5)
|
|
{
|
|
APIUtlis.ApiSeriveError(ex5);
|
|
}
|
|
string text24 = dateTime5.ToString("yyyy-MM-dd");
|
|
string dicValue5 = getDicValue<string>(data3, "price");
|
|
if (dicValue5 != null)
|
|
{
|
|
dicValue5 = ((ContetCuure(dicValue5) || dicValue5.Contains(".")) ? dicValue5.Replace(",", "") : dicValue5.Replace(",", "."));
|
|
}
|
|
else
|
|
{
|
|
dicValue5 = text19;
|
|
dicValue5 = ((ContetCuure(text19) || text19.Contains(".")) ? text19.Replace(",", "") : text19.Replace(",", "."));
|
|
}
|
|
string dicValue6 = getDicValue<string>(data3, "purchased-from");
|
|
bool dicValue7 = getDicValue<bool>(data3, "refunded");
|
|
string text25 = "";
|
|
if (dicValue7)
|
|
{
|
|
text25 = getDicValue<string>(data3, "refund-amount");
|
|
try
|
|
{
|
|
string text26 = "";
|
|
if (!text25.Contains(".") && !ContetCuure(text25))
|
|
{
|
|
byte[] bytes4 = new byte[2] { 194, 160 };
|
|
string string4 = Encoding.GetEncoding("UTF-8").GetString(bytes4);
|
|
text26 = text25.Replace(",", ".").Replace(' ', '-').Replace("-", "")
|
|
.Replace("\u00a0", "")
|
|
.Replace(string4, "");
|
|
}
|
|
else
|
|
{
|
|
text26 = text25.Replace(",", "");
|
|
}
|
|
string text27 = Regex.Replace(text26, "[^\\d.\\d]", "");
|
|
if (Regex.IsMatch(text27, "^[+-]?\\d*[.]?\\d*$"))
|
|
{
|
|
string text28 = text26.Replace(text27, "").TrimStart();
|
|
if (text28.Contains("¥"))
|
|
{
|
|
text28 = "¥";
|
|
}
|
|
if (decimal.TryParse(regex.Replace(text27, ""), out var result4) && result4 > 0m)
|
|
{
|
|
if (!dictionary2.ContainsKey(text28))
|
|
{
|
|
dictionary2.Add(text28, 0m);
|
|
}
|
|
dictionary2[text28] += result4;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex6)
|
|
{
|
|
APIUtlis.ApiSeriveError(ex6);
|
|
}
|
|
}
|
|
string text29 = getDicValue<string>(data3, "item-name").Replace(",", " ");
|
|
if (isExport)
|
|
{
|
|
if (ckBillMergeData)
|
|
{
|
|
stringBuilder.Append(itunelogin.account + "," + itunelogin.Area + ",<total>," + dicValue4 + "," + text23 + "," + text24 + "," + dicValue5 + "," + text6 + "," + dicValue6 + "," + text25 + "," + text29 + "\n");
|
|
}
|
|
else
|
|
{
|
|
stringBuilder.Append(dicValue4 + "," + text23 + "," + text24 + "," + dicValue5 + "," + text6 + "," + dicValue6 + "," + text25 + "," + text29 + "\n");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (dateTime5 < gameLastDate)
|
|
{
|
|
gameLastDate = dateTime5;
|
|
}
|
|
if (dateTime5 > gameLatelyDate)
|
|
{
|
|
gameLatelyDate = dateTime5;
|
|
}
|
|
}
|
|
}
|
|
continue;
|
|
}
|
|
if (httpResult.StatusCode == HttpStatusCode.NoContent)
|
|
{
|
|
num++;
|
|
flag = true;
|
|
continue;
|
|
}
|
|
if (httpResult.Html.Contains("authentication"))
|
|
{
|
|
_action?.Invoke(notityKey, DisplyType.xinxi, "账号掉线了,重新登录");
|
|
itunelogin = getItunesLogin(new AppleAcount
|
|
{
|
|
appleId = itunelogin.account,
|
|
applePwd = itunelogin.pwd
|
|
}, 6, _action, utlis, 2);
|
|
if (itunelogin == null)
|
|
{
|
|
error = "重新登陆失败,请重新检测";
|
|
text = "0";
|
|
return new Tuple<string, DateTime, DateTime, string, string>(text, dateTime, dateTime2, item, text2);
|
|
}
|
|
}
|
|
flag = true;
|
|
num2++;
|
|
if (num2 >= 5)
|
|
{
|
|
error = "多次请求失败,请重新检测";
|
|
text = "0";
|
|
return new Tuple<string, DateTime, DateTime, string, string>(text, dateTime, dateTime2, item, text2);
|
|
}
|
|
}
|
|
while (flag);
|
|
}
|
|
foreach (KeyValuePair<string, decimal> item9 in dictionary)
|
|
{
|
|
if (item9.Value > 0m)
|
|
{
|
|
text = text + item9.Key + item9.Value + " - ";
|
|
}
|
|
}
|
|
text = text.TrimEnd(' ', '-');
|
|
if (string.IsNullOrEmpty(text))
|
|
{
|
|
text = "0";
|
|
}
|
|
foreach (KeyValuePair<string, decimal> item10 in dictionary2)
|
|
{
|
|
text2 = text2 + item10.Key + item10.Value + " - ";
|
|
}
|
|
text2 = text2.TrimEnd(' ', '-');
|
|
if (string.IsNullOrEmpty(text))
|
|
{
|
|
text2 = "无退款";
|
|
}
|
|
error = "0000";
|
|
if (!ckBillMergeData)
|
|
{
|
|
stringBuilder.Append("消费总金额:" + text + "\n");
|
|
stringBuilder.Append("最早消费时间:" + dateTime.ToString("yyyy-MM-dd") + "\n");
|
|
stringBuilder.Append("最晚消费时间:" + dateTime2.ToString("yyyy-MM-dd") + "\n\n");
|
|
stringBuilder.Append("支付方式消费统计\n");
|
|
foreach (IGrouping<string, MethodsPayTotal> item11 in from c in list
|
|
group c by c.mnethods)
|
|
{
|
|
stringBuilder.Append($"{item11.Key},{item11.FirstOrDefault().currency} {item11.Sum((MethodsPayTotal c) => c.money)}\n");
|
|
foreach (IGrouping<int, MethodsPayTotal> item12 in from c in item11
|
|
group c by c.year)
|
|
{
|
|
stringBuilder.Append($"{item12.Key},{item11.FirstOrDefault().currency} {item12.Sum((MethodsPayTotal c) => c.money)}\n");
|
|
}
|
|
stringBuilder.Append("\n");
|
|
}
|
|
stringBuilder.Append("每年的消费总次数\n");
|
|
stringBuilder.Append("年份,消费总次数\n");
|
|
foreach (KeyValuePair<string, int> item13 in dictionary3)
|
|
{
|
|
stringBuilder.Append($"{item13.Key},{item13.Value}" + "\n");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
stringBuilder.Replace("<total>", text);
|
|
}
|
|
if (isExport)
|
|
{
|
|
try
|
|
{
|
|
if (!ckBillMergeData)
|
|
{
|
|
File.WriteAllText(dirName + "\\" + itunelogin.account + ".csv", stringBuilder.ToString(), Encoding.UTF8);
|
|
}
|
|
else
|
|
{
|
|
lock (wirteFileLock)
|
|
{
|
|
File.AppendAllText(dirName + "\\" + mergeName + "账单查询数据合集.csv", stringBuilder.ToString(), Encoding.UTF8);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex7)
|
|
{
|
|
APIUtlis.ApiSeriveError(ex7);
|
|
}
|
|
}
|
|
return new Tuple<string, DateTime, DateTime, string, string>(text, dateTime, dateTime2, item, text2);
|
|
}
|
|
error = "请求查询账单服务器失败,请重新检测";
|
|
text = "0";
|
|
return new Tuple<string, DateTime, DateTime, string, string>(text, dateTime, dateTime2, item, text2);
|
|
}
|
|
|
|
private bool ContetCuure(string value)
|
|
{
|
|
string[] array = AppSysConfig.getConfig("currencySymbols").Split(',');
|
|
int num = 0;
|
|
while (true)
|
|
{
|
|
if (num < array.Length)
|
|
{
|
|
string value2 = array[num];
|
|
if (value.Contains(value2))
|
|
{
|
|
break;
|
|
}
|
|
num++;
|
|
continue;
|
|
}
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|