mirror of
https://git.oceanpay.cc/danial/kami_itunes_june.git
synced 2025-12-18 22:31:24 +00:00
558 lines
16 KiB
C#
558 lines
16 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Web;
|
|
using AppleBatch_June.Domain;
|
|
|
|
namespace AppleBatch_June
|
|
{
|
|
public class AppleUtlis
|
|
{
|
|
private static string[] UserAgents = new string[20]
|
|
{
|
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3872.400 QQBrowser/10.8.4455.400", "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1",
|
|
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.84 Safari/535.11 LBBROWSER", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.11 TaoBrowser/2.0 Safari/536.11", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.71 Safari/537.1 LBBROWSER", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36", "Opera/9.80 (Windows NT 6.1; WOW64; U; en) Presto/2.10.229 Version/11.62", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0", "Mozilla/5.0 (compatible; WOW64; MSIE 10.0; Windows NT 6.2)"
|
|
};
|
|
|
|
public static DataTable dataTable_0 { get; set; }
|
|
|
|
public static DataTable dataTable_2 { get; set; }
|
|
|
|
public static string GetAreaByArea(string area)
|
|
{
|
|
LoadCountryCode();
|
|
IEnumerator enumerator = null;
|
|
if (string.IsNullOrEmpty(area))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
string result = area;
|
|
try
|
|
{
|
|
foreach (DataRow row in dataTable_0.Rows)
|
|
{
|
|
string strB = row["area"].ToString();
|
|
if (string.Compare(area, strB, ignoreCase: true) == 0)
|
|
{
|
|
result = row["name"].ToString();
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
finally
|
|
{
|
|
if (enumerator is IDisposable)
|
|
{
|
|
(enumerator as IDisposable).Dispose();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static string GetAreaByCode(string code, bool addArer = false)
|
|
{
|
|
LoadCountryCode();
|
|
IEnumerator enumerator = null;
|
|
if (string.IsNullOrEmpty(code))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
string result = code;
|
|
try
|
|
{
|
|
foreach (DataRow row in dataTable_0.Rows)
|
|
{
|
|
string strB = row["code"].ToString();
|
|
if (string.Compare(code, strB, ignoreCase: true) == 0)
|
|
{
|
|
result = ((!addArer) ? row["name"].ToString() : (row["area"].ToString().ToUpper() + "-" + row["name"].ToString()));
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
finally
|
|
{
|
|
if (enumerator is IDisposable)
|
|
{
|
|
(enumerator as IDisposable).Dispose();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static string GetNameBydisplayName(string displayName)
|
|
{
|
|
LoadCountryCode();
|
|
IEnumerator enumerator = null;
|
|
if (string.IsNullOrEmpty(displayName))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
string result = displayName;
|
|
try
|
|
{
|
|
foreach (DataRow row in dataTable_0.Rows)
|
|
{
|
|
string strB = row["displayName"].ToString();
|
|
if (string.Compare(displayName, strB, ignoreCase: true) == 0)
|
|
{
|
|
result = row["area"].ToString().ToUpper() + "-" + row["name"].ToString();
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
finally
|
|
{
|
|
if (enumerator is IDisposable)
|
|
{
|
|
(enumerator as IDisposable).Dispose();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static string GetAreaCodeByCode(string code)
|
|
{
|
|
LoadCountryCode();
|
|
IEnumerator enumerator = null;
|
|
if (string.IsNullOrEmpty(code))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
string result = code;
|
|
try
|
|
{
|
|
foreach (DataRow row in dataTable_0.Rows)
|
|
{
|
|
string strB = row["code"].ToString();
|
|
if (string.Compare(code, strB, ignoreCase: true) == 0)
|
|
{
|
|
result = row["area"].ToString();
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
finally
|
|
{
|
|
if (enumerator is IDisposable)
|
|
{
|
|
(enumerator as IDisposable).Dispose();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static string GetStoreIdByCode(string code)
|
|
{
|
|
LoadCountryCode();
|
|
IEnumerator enumerator = null;
|
|
if (string.IsNullOrEmpty(code))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
string result = code;
|
|
try
|
|
{
|
|
foreach (DataRow row in dataTable_0.Rows)
|
|
{
|
|
string strB = row["code"].ToString();
|
|
if (string.Compare(code, strB, ignoreCase: true) == 0)
|
|
{
|
|
result = row["description"].ToString();
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
finally
|
|
{
|
|
if (enumerator is IDisposable)
|
|
{
|
|
(enumerator as IDisposable).Dispose();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static string GetCountryCodeByArea(string area)
|
|
{
|
|
LoadCountryCode();
|
|
IEnumerator enumerator = null;
|
|
if (string.IsNullOrEmpty(area))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
string result = area;
|
|
try
|
|
{
|
|
foreach (DataRow row in dataTable_0.Rows)
|
|
{
|
|
string strB = row["area"].ToString();
|
|
if (string.Compare(area, strB, ignoreCase: true) == 0)
|
|
{
|
|
result = row["code"].ToString();
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
finally
|
|
{
|
|
if (enumerator is IDisposable)
|
|
{
|
|
(enumerator as IDisposable).Dispose();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void LoadCountryCode2()
|
|
{
|
|
if (dataTable_2 == null || dataTable_2.Rows.Count == 0)
|
|
{
|
|
dataTable_2 = new CountryCodeData().getDataBriefTable();
|
|
}
|
|
}
|
|
|
|
private static string GetAreaByStoreId(string storeId)
|
|
{
|
|
IEnumerator enumerator = null;
|
|
if (string.IsNullOrEmpty(storeId))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
string result = string.Empty;
|
|
try
|
|
{
|
|
enumerator = dataTable_2.Rows.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
DataRow dataRow = (DataRow)enumerator.Current;
|
|
string strB = dataRow["id"].ToString();
|
|
if (string.Compare(storeId, strB, ignoreCase: true) == 0)
|
|
{
|
|
result = dataRow["area"].ToString();
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
finally
|
|
{
|
|
if (enumerator is IDisposable)
|
|
{
|
|
(enumerator as IDisposable).Dispose();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static string GetAreaByDescription(string description)
|
|
{
|
|
LoadCountryCode2();
|
|
string storeId = description;
|
|
int num = description.IndexOf("-");
|
|
if (num < 0)
|
|
{
|
|
num = description.IndexOf(",");
|
|
}
|
|
if (num > -1)
|
|
{
|
|
storeId = description.Substring(0, num);
|
|
}
|
|
return GetAreaByStoreId(storeId);
|
|
}
|
|
|
|
public static List<string> restTxt(string patch)
|
|
{
|
|
try
|
|
{
|
|
if (!string.IsNullOrEmpty(patch) && File.Exists(patch))
|
|
{
|
|
return (from c in Tools.readFile(patch, Encoding.UTF8).Split('\n')
|
|
where !string.IsNullOrEmpty(c) && (c.Contains("itunes.apple.com") || c.Contains("apps.apple.com") || c.Contains("music.apple.com") || c.Contains("books.apple.com"))
|
|
select c).ToList();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
return new List<string>();
|
|
}
|
|
|
|
public static void LoadCountryCode()
|
|
{
|
|
if (dataTable_0 == null || dataTable_0.Rows.Count == 0)
|
|
{
|
|
dataTable_0 = new CountryCodeData().getDataTable();
|
|
LoadCountryCode2();
|
|
}
|
|
}
|
|
|
|
public static string Html2Text(string htmlStr, bool isEmorp = true)
|
|
{
|
|
if (string.IsNullOrEmpty(htmlStr))
|
|
{
|
|
return "";
|
|
}
|
|
htmlStr = HttpUtility.HtmlDecode(htmlStr);
|
|
string pattern = "<style[^>]*?>[\\s\\S]*?<\\/style>";
|
|
string pattern2 = "<script[^>]*?>[\\s\\S]*?<\\/script>";
|
|
string pattern3 = "<[^>]+>";
|
|
htmlStr = Regex.Replace(htmlStr, pattern, "");
|
|
htmlStr = Regex.Replace(htmlStr, pattern2, "");
|
|
htmlStr = Regex.Replace(htmlStr, pattern3, "");
|
|
if (isEmorp)
|
|
{
|
|
htmlStr = Regex.Replace(htmlStr, "\\s*|\t|\r|\n", "");
|
|
htmlStr = htmlStr.Replace(" ", "");
|
|
}
|
|
htmlStr = htmlStr.Replace("\"", "");
|
|
return htmlStr.Trim();
|
|
}
|
|
|
|
public static List<AppleAcount> accountInput(string input, string[] guidFields = null, bool removePwd = false, bool isdeWeight = true, bool forceAotuIdent = false)
|
|
{
|
|
List<AppleAcount> list = new List<AppleAcount>();
|
|
string config = AppSysConfig.getConfig("AccountInputRegex");
|
|
string configValue = ConfigUtlis.getConfigValue("txtSeparator");
|
|
string configValue2 = ConfigUtlis.getConfigValue("ckReplace");
|
|
string text = ConfigUtlis.getConfigValue("ckAotuIdent");
|
|
if (forceAotuIdent)
|
|
{
|
|
text = "True";
|
|
}
|
|
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
|
string[] array = input.Split('\n');
|
|
foreach (string text2 in array)
|
|
{
|
|
if (string.IsNullOrEmpty(text2))
|
|
{
|
|
continue;
|
|
}
|
|
string text3 = text2.Trim();
|
|
string pattern = "(\\d{4})(-)(\\d{1,2})(-)(\\d{1,2})";
|
|
string text4 = Regex.Match(text3, config).Value;
|
|
string value = Regex.Match(text3, pattern).Value;
|
|
if (string.IsNullOrEmpty(value))
|
|
{
|
|
pattern = "(\\d{4})(/)(\\d{1,2})(/)(\\d{1,2})";
|
|
value = Regex.Match(text3, pattern).Value;
|
|
}
|
|
char separator = '-';
|
|
bool flag = false;
|
|
if (!string.IsNullOrEmpty(configValue) && configValue2 == "True")
|
|
{
|
|
separator = configValue[0];
|
|
flag = true;
|
|
}
|
|
string text5 = text3;
|
|
if (!string.IsNullOrEmpty(value))
|
|
{
|
|
text5 = text3.Trim().Replace(value, "");
|
|
}
|
|
if (!text5.Contains("\t") && !text5.Contains(separator.ToString()))
|
|
{
|
|
text5 = text5.Replace(" ", separator.ToString());
|
|
}
|
|
text5 = text5.Trim().Replace("\t", separator.ToString()).Replace("\r", "");
|
|
if (text != "False")
|
|
{
|
|
text5 = text5.Replace("账号:", "").Replace("密码:", "").Replace("问题1:", "")
|
|
.Replace("问题2:", "")
|
|
.Replace("问题3:", "")
|
|
.Replace("密码", "")
|
|
.Replace("密保:", "")
|
|
.Replace("密保", "")
|
|
.Replace("朋友", "")
|
|
.Replace("问题1", "")
|
|
.Replace("问题2", "")
|
|
.Replace("问题3", "")
|
|
.Replace("工作", "")
|
|
.Replace("父母", "")
|
|
.Replace("手机号码", "");
|
|
}
|
|
if (!string.IsNullOrEmpty(text4) && text4.Contains(".") && !(text == "False"))
|
|
{
|
|
if (text5.Length > text4.Length)
|
|
{
|
|
text5 = text5.Substring(text4.Length);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
text4 = ((!text5.Contains("----") || flag) ? text5.Split(separator)[0] : text5.Replace("----", "/").Split('/')[0]);
|
|
if (text5.Length > text4.Length)
|
|
{
|
|
text5 = text5.Substring(text4.Length);
|
|
}
|
|
}
|
|
if (text4 == "xxxx@xxx.com")
|
|
{
|
|
continue;
|
|
}
|
|
string[] array2 = (from c in text5.Replace("[-]", "{\0}").Replace("{-}", "{\0}").Split(separator)
|
|
where !string.IsNullOrEmpty(c.Trim())
|
|
select c.Replace("{\0}", separator.ToString())).ToArray();
|
|
if (array2.Length == 0 || array2[0].Length < 1)
|
|
{
|
|
continue;
|
|
}
|
|
AppleAcount appleAcount = new AppleAcount();
|
|
appleAcount.sourceInputData = text2;
|
|
appleAcount.appleId = text4.Trim();
|
|
if (!removePwd)
|
|
{
|
|
appleAcount.applePwd = array2[0].Trim().Split(' ')[0];
|
|
if (array2.Length >= 4)
|
|
{
|
|
appleAcount.appleQt1 = array2[1].Trim();
|
|
appleAcount.appleQt2 = array2[2].Trim();
|
|
appleAcount.appleQt3 = array2[3].Trim();
|
|
string text6 = "";
|
|
for (int j = 4; j < array2.Length; j++)
|
|
{
|
|
text6 = text6 + array2[j] + "-";
|
|
}
|
|
appleAcount.overflow = ((text6.Length > 0) ? text6.TrimEnd('-') : "");
|
|
}
|
|
else
|
|
{
|
|
string text7 = "";
|
|
for (int k = 1; k < array2.Length; k++)
|
|
{
|
|
text7 = text7 + array2[k] + "-";
|
|
}
|
|
appleAcount.overflow = ((text7.Length > 0) ? text7.TrimEnd('-') : "");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
appleAcount.applePwd = "";
|
|
if (array2.Length >= 3)
|
|
{
|
|
appleAcount.appleQt1 = array2[0].Trim();
|
|
appleAcount.appleQt2 = array2[1].Trim();
|
|
appleAcount.appleQt3 = array2[2].Trim();
|
|
string text8 = "";
|
|
for (int l = 3; l < array2.Length; l++)
|
|
{
|
|
text8 = text8 + array2[l] + "-";
|
|
}
|
|
appleAcount.overflow = ((text8.Length > 0) ? text8.TrimEnd('-') : "");
|
|
}
|
|
else
|
|
{
|
|
string text9 = "";
|
|
for (int m = 0; m < array2.Length; m++)
|
|
{
|
|
text9 = text9 + array2[m] + "-";
|
|
}
|
|
appleAcount.overflow = ((text9.Length > 0) ? text9.TrimEnd('-') : "");
|
|
}
|
|
}
|
|
appleAcount.birthday = value;
|
|
if (guidFields != null && guidFields.Length != 0)
|
|
{
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
foreach (string name in guidFields)
|
|
{
|
|
object obj = appleAcount.GetType().GetProperty(name)?.GetValue(appleAcount);
|
|
if (obj != null && obj is string)
|
|
{
|
|
stringBuilder.Append((obj as string) + "|");
|
|
}
|
|
}
|
|
if (stringBuilder.Length > 0)
|
|
{
|
|
appleAcount.lvItemGuid = Tools.GetMD5_32(stringBuilder.ToString());
|
|
}
|
|
else
|
|
{
|
|
appleAcount.lvItemGuid = Tools.GetMD5_32(Tools.Toenjson(appleAcount));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
appleAcount.lvItemGuid = Tools.GetMD5_32(Tools.Toenjson(appleAcount));
|
|
}
|
|
if (isdeWeight)
|
|
{
|
|
if (!dictionary.TryGetValue(appleAcount.appleId, out var _))
|
|
{
|
|
dictionary.Add(appleAcount.appleId, appleAcount.appleId);
|
|
list.Add(appleAcount);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
list.Add(appleAcount);
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public static string getAppleWenUserAgent()
|
|
{
|
|
int num = new Random(Guid.NewGuid().GetHashCode()).Next(0, UserAgents.Length);
|
|
return UserAgents[num];
|
|
}
|
|
|
|
public static DateTime toDate(string invoicedate)
|
|
{
|
|
byte[] bytes = new byte[2] { 194, 160 };
|
|
string @string = Encoding.GetEncoding("UTF-8").GetString(bytes);
|
|
string text = invoicedate.ToUpper().Replace("JAN", "1").Replace("FEB", "2")
|
|
.Replace("MAR", "3")
|
|
.Replace("APR", "4")
|
|
.Replace("MAY", "5")
|
|
.Replace("JUN", "6")
|
|
.Replace("JUL", "7")
|
|
.Replace("AUG", "8")
|
|
.Replace("SEP", "9")
|
|
.Replace("OCT", "10")
|
|
.Replace("NOV", "11")
|
|
.Replace("DEC", "12")
|
|
.Replace(' ', '-')
|
|
.Replace(@string, "-")
|
|
.Replace(",", "");
|
|
string text2 = "";
|
|
string[] array = text.Split('-');
|
|
foreach (string text3 in array)
|
|
{
|
|
text2 = ((text3.Length > 1) ? (text2 + text3 + "-") : (text2 + text3.PadLeft(2, '0') + "-"));
|
|
}
|
|
text2 = text2.TrimEnd('-');
|
|
DateTime result = DateTime.Now;
|
|
try
|
|
{
|
|
result = DateTime.ParseExact(text2, "MM-dd-yyyy", CultureInfo.InvariantCulture);
|
|
return result;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public static List<string> getYears(Dictionary<string, dynamic> obj, int selectIndex)
|
|
{
|
|
List<string> list = new List<string>();
|
|
foreach (object item in obj["data"]["attributes"]["dates"]["years"])
|
|
{
|
|
foreach (string key in ((Dictionary<string, object>)(dynamic)item).Keys)
|
|
{
|
|
if (selectIndex == 0)
|
|
{
|
|
if (key != "last90Days")
|
|
{
|
|
list.Add(key + "-all");
|
|
}
|
|
}
|
|
else if (key == "last90Days")
|
|
{
|
|
list.Add(key);
|
|
}
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
}
|
|
}
|