mirror of
https://git.oceanpay.cc/danial/kami_itunes_june.git
synced 2025-12-18 22:31:24 +00:00
551 lines
14 KiB
C#
551 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using AppleBatch_June.ExecuteTasks;
|
|
using AppleBatch_June.Model;
|
|
using AppleBatch_June.Utils;
|
|
using DotNet.Utilities;
|
|
|
|
namespace AppleBatch_June
|
|
{
|
|
public static class APIUtlis
|
|
{
|
|
private class DeductioCoun
|
|
{
|
|
public long useCount { get; set; }
|
|
|
|
public long deductioCount { get; set; }
|
|
}
|
|
|
|
private static Dictionary<int, DeductioCoun> UserDeductioCounts = new Dictionary<int, DeductioCoun>();
|
|
|
|
private static StringBuilder requestHtml { get; set; } = new StringBuilder(4000, 4000);
|
|
|
|
|
|
public static string requestUrl { get; set; } = "";
|
|
|
|
|
|
public static void AddUserDeductio(int fun, int type)
|
|
{
|
|
lock (UserDeductioCounts)
|
|
{
|
|
if (UserDeductioCounts.ContainsKey(fun))
|
|
{
|
|
if (type == 1)
|
|
{
|
|
UserDeductioCounts[fun].useCount = UserDeductioCounts[fun].useCount + 1L;
|
|
}
|
|
else
|
|
{
|
|
UserDeductioCounts[fun].deductioCount = UserDeductioCounts[fun].deductioCount + 1L;
|
|
}
|
|
return;
|
|
}
|
|
DeductioCoun deductioCoun = new DeductioCoun();
|
|
if (type == 1)
|
|
{
|
|
deductioCoun.useCount = 1L;
|
|
}
|
|
else
|
|
{
|
|
deductioCoun.deductioCount = 1L;
|
|
}
|
|
UserDeductioCounts.Add(fun, deductioCoun);
|
|
}
|
|
}
|
|
|
|
public static string getUserDeductioInfo(int fun)
|
|
{
|
|
lock (UserDeductioCounts)
|
|
{
|
|
if (UserDeductioCounts.ContainsKey(fun))
|
|
{
|
|
DeductioCoun deductioCoun = UserDeductioCounts[fun];
|
|
return deductioCoun.useCount + "-" + deductioCoun.deductioCount;
|
|
}
|
|
}
|
|
return "-";
|
|
}
|
|
|
|
public static async void rechargeCodeAsync(string code, Action<HttpResult> invoke)
|
|
{
|
|
invoke(await Task.Run(delegate
|
|
{
|
|
Dictionary<string, object> postData = new Dictionary<string, object>
|
|
{
|
|
{
|
|
"token",
|
|
AppSysConfig.userToken
|
|
},
|
|
{ "code", code }
|
|
};
|
|
return new ApiNetReq().doPost(postData, "ApiCodeRecharge");
|
|
}));
|
|
}
|
|
|
|
public static async void getIsLogin(Action<HttpResult> invoke)
|
|
{
|
|
HttpResult httpResult = await Task.Run(delegate
|
|
{
|
|
Dictionary<string, object> postData = new Dictionary<string, object>
|
|
{
|
|
{
|
|
"token",
|
|
AppSysConfig.userToken
|
|
},
|
|
{ "type", 0 }
|
|
};
|
|
return new ApiNetReq().doPost(postData, "ApiIsLogin");
|
|
});
|
|
if (httpResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
invoke(httpResult);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("网络请求失败");
|
|
}
|
|
}
|
|
|
|
public static HttpResult getIsLogin(int type)
|
|
{
|
|
AddUserDeductio(type, 1);
|
|
ProxyRunService.nowFun = type;
|
|
Dictionary<string, object> postData = new Dictionary<string, object>
|
|
{
|
|
{
|
|
"token",
|
|
AppSysConfig.userToken
|
|
},
|
|
{ "type", type }
|
|
};
|
|
HttpResult httpResult = new ApiNetReq().doPost(postData, "ApiIsLogin");
|
|
if (httpResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
try
|
|
{
|
|
dynamic val = Tools.Todejosn<object>(httpResult.Html);
|
|
if (!((val["Code"] == "0000") ? true : false))
|
|
{
|
|
return httpResult;
|
|
}
|
|
AppSysConfig.integral = val["Data"]["integral"];
|
|
return httpResult;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return httpResult;
|
|
}
|
|
}
|
|
return httpResult;
|
|
}
|
|
|
|
public static HttpResult ApiInitNewProxy(IpInfoModel info)
|
|
{
|
|
Dictionary<string, object> postData = new Dictionary<string, object>
|
|
{
|
|
{
|
|
"token",
|
|
AppSysConfig.userToken
|
|
},
|
|
{
|
|
"isp",
|
|
Tools.ToUrlEncode(info.isp)
|
|
},
|
|
{
|
|
"myipTopIip",
|
|
Tools.ToUrlEncode(info.ip)
|
|
},
|
|
{
|
|
"country",
|
|
Tools.ToUrlEncode(info.country)
|
|
}
|
|
};
|
|
return new ApiNetReq().doPost(postData, "ApiInitNewProxy");
|
|
}
|
|
|
|
public static HttpResult ApiProxyIp(IpInfoModel info, int routeLine, int type)
|
|
{
|
|
string text = info?.isp + "," + ProxyRunService.nowFun;
|
|
text = text + "," + getUserDeductioInfo(ProxyRunService.nowFun);
|
|
Dictionary<string, object> postData = new Dictionary<string, object>
|
|
{
|
|
{
|
|
"token",
|
|
AppSysConfig.userToken
|
|
},
|
|
{ "type", type },
|
|
{
|
|
"routeLine",
|
|
routeLine.ToString()
|
|
},
|
|
{
|
|
"isp",
|
|
Tools.ToUrlEncode(text)
|
|
},
|
|
{
|
|
"myipTopIip",
|
|
Tools.ToUrlEncode(info?.ip)
|
|
},
|
|
{
|
|
"country",
|
|
Tools.ToUrlEncode(info?.country)
|
|
}
|
|
};
|
|
return new ApiNetReq().doPost(postData, "ApiProxyIp");
|
|
}
|
|
|
|
public static HttpResult ApiCheckUseIP(string platformName, List<string> ipLists)
|
|
{
|
|
Dictionary<string, object> postData = new Dictionary<string, object>
|
|
{
|
|
{
|
|
"token",
|
|
AppSysConfig.userToken
|
|
},
|
|
{ "platformName", platformName },
|
|
{ "ipLists", ipLists }
|
|
};
|
|
return new ApiNetReq().doPost(postData, "ApiCheckUseIP");
|
|
}
|
|
|
|
public static HttpResult getCaptcha(int type, string imageContent, bool standby = false)
|
|
{
|
|
Dictionary<string, object> postData = new Dictionary<string, object>
|
|
{
|
|
{
|
|
"token",
|
|
AppSysConfig.userToken
|
|
},
|
|
{ "type", type },
|
|
{
|
|
"imageContent",
|
|
(type == 1) ? imageContent : "111"
|
|
},
|
|
{
|
|
"captchaId",
|
|
Tools.GetMD5_32(imageContent)
|
|
},
|
|
{
|
|
"standby",
|
|
standby ? 1 : 0
|
|
}
|
|
};
|
|
return new ApiNetReq().doPost(postData, "ApiCaptcha");
|
|
}
|
|
|
|
public static async void outLogin()
|
|
{
|
|
await Task.Run(delegate
|
|
{
|
|
Dictionary<string, object> postData = new Dictionary<string, object> {
|
|
{
|
|
"token",
|
|
AppSysConfig.userToken
|
|
} };
|
|
return new ApiNetReq().doPost(postData, "ApiOutLogin");
|
|
});
|
|
}
|
|
|
|
public static void ApiApplyAct(int type, string typeName)
|
|
{
|
|
//AddUserDeductio(type, 2);
|
|
//Task.Run(delegate
|
|
//{
|
|
// AppSysConfig.integral -= AppSysConfig.getTypeById(type).consNum;
|
|
// Dictionary<string, object> postData = new Dictionary<string, object>
|
|
// {
|
|
// {
|
|
// "token",
|
|
// AppSysConfig.userToken
|
|
// },
|
|
// { "type", type },
|
|
// { "reqData", typeName }
|
|
// };
|
|
// new ApiNetReq().doPost(postData, "ApiApplyAct");
|
|
//});
|
|
}
|
|
|
|
public static void AppRequestHtml(string html)
|
|
{
|
|
try
|
|
{
|
|
requestHtml.Clear();
|
|
if (html.Length > 4000)
|
|
{
|
|
requestHtml.Append(html, 0, 4000);
|
|
}
|
|
else
|
|
{
|
|
requestHtml.Append(html, 0, html.Length);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
|
|
public static void ApiSeriveError(Exception ex, string title = "")
|
|
{
|
|
if (ex.Message.Contains("停止执行"))
|
|
{
|
|
return;
|
|
}
|
|
Task.Run(delegate
|
|
{
|
|
try
|
|
{
|
|
string text = ErrorMessage(ex);
|
|
if (!text.Contains("system.data.sqlite") && !text.Contains("System.Data.SQLite"))
|
|
{
|
|
if (!string.IsNullOrEmpty(title))
|
|
{
|
|
long totalMemory = GC.GetTotalMemory(forceFullCollection: true);
|
|
title = title + "[" + totalMemory + "]";
|
|
}
|
|
if (text.Contains("System.OutOfMemoryException") || text.Contains("内存不足") || text.Contains("没有足够的内存"))
|
|
{
|
|
GC.Collect();
|
|
GC.WaitForPendingFinalizers();
|
|
GC.GetTotalMemory(forceFullCollection: true);
|
|
}
|
|
text = title + text + "\n url=" + requestUrl + "\n html=" + requestHtml.ToString();
|
|
string value = ApiNetReq.startNowFun.ToString();
|
|
Dictionary<string, object> postData = new Dictionary<string, object>
|
|
{
|
|
{
|
|
"token",
|
|
AppSysConfig.userToken
|
|
},
|
|
{
|
|
"errMeeges",
|
|
Tools.ToUrlEncode(text)
|
|
},
|
|
{
|
|
"versions",
|
|
FormLogin.versions
|
|
},
|
|
{ "funNum", value }
|
|
};
|
|
new ApiNetReq().doPost(postData, "ApiSeriveError");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
});
|
|
}
|
|
|
|
private static string ErrorMessage(Exception exception)
|
|
{
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
stringBuilder.AppendLine("【Message】:" + exception.Message);
|
|
stringBuilder.AppendLine("【Source】:" + exception.Source);
|
|
stringBuilder.AppendLine("【TargetSite】:" + ((exception.TargetSite != null) ? exception.TargetSite.Name : "无"));
|
|
stringBuilder.AppendLine("【StackTrace】:" + exception.StackTrace);
|
|
stringBuilder.AppendLine("【exception】:" + exception);
|
|
if (exception.InnerException != null)
|
|
{
|
|
stringBuilder.AppendLine("----INNER EXCEPTION----");
|
|
stringBuilder.AppendLine("【Message】:" + exception.InnerException.Message);
|
|
stringBuilder.AppendLine("【Source】:" + exception.InnerException.Source);
|
|
stringBuilder.AppendLine("【TargetSite】:" + ((exception.InnerException.TargetSite != null) ? exception.InnerException.TargetSite.Name : "无"));
|
|
stringBuilder.AppendLine("【StackTrace】:" + exception.InnerException.StackTrace);
|
|
stringBuilder.AppendLine("【InnerException】:" + exception.InnerException);
|
|
}
|
|
return stringBuilder.ToString().Replace("/r", "").Replace("/n", "")
|
|
.TrimEnd('\n');
|
|
}
|
|
|
|
public static HttpResult QueryInfo(string account, string pwd, string type)
|
|
{
|
|
string idGuid = AppleGuidManage.getIdGuid(account, pwd);
|
|
if (!string.IsNullOrEmpty(idGuid))
|
|
{
|
|
pwd = pwd + ":{" + idGuid + "}";
|
|
}
|
|
Dictionary<string, object> postData = new Dictionary<string, object>
|
|
{
|
|
{
|
|
"token",
|
|
AppSysConfig.userToken
|
|
},
|
|
{ "account", account },
|
|
{ "pwd", pwd },
|
|
{ "type", type }
|
|
};
|
|
HttpResult httpResult = new ApiNetReq().doPost(postData, "ApiBannaQuery");
|
|
if (httpResult.StatusCode == (HttpStatusCode)0)
|
|
{
|
|
httpResult = new ApiNetReq().doPost(postData, "ApiBannaQuery");
|
|
}
|
|
return httpResult;
|
|
}
|
|
|
|
public static HttpResult getItunesLogin(string account, string pwd, int isStore)
|
|
{
|
|
string value = "";
|
|
if (AppSysConfig.DoubleGuid.ContainsKey(account))
|
|
{
|
|
value = AppSysConfig.DoubleGuid[account];
|
|
}
|
|
if (AppSysConfig.ReddemVerifyGuid.ContainsKey(account))
|
|
{
|
|
value = AppSysConfig.ReddemVerifyGuid[account];
|
|
}
|
|
int num = -1;
|
|
if (isStore == 1 && AppSysConfig.ReddemStoreSeriveIndex.ContainsKey(account))
|
|
{
|
|
num = AppSysConfig.ReddemStoreSeriveIndex[account];
|
|
}
|
|
string idGuid = AppleGuidManage.getIdGuid(account, pwd);
|
|
if (!string.IsNullOrEmpty(idGuid))
|
|
{
|
|
pwd = pwd + ":{" + idGuid + "}";
|
|
}
|
|
Dictionary<string, object> postData = new Dictionary<string, object>
|
|
{
|
|
{
|
|
"token",
|
|
AppSysConfig.userToken
|
|
},
|
|
{ "account", account },
|
|
{ "pwd", pwd },
|
|
{ "isStore", isStore },
|
|
{ "guid", value },
|
|
{ "serviceIpIndex", num }
|
|
};
|
|
return new ApiNetReq().doPost(postData, "ApiItunesLogin");
|
|
}
|
|
|
|
public static HttpResult serviceSend(string message)
|
|
{
|
|
dynamic val = Tools.Todejosn<object>(message);
|
|
val["timeStamp"] = Tools.GetTimestamp2();
|
|
Tools.Toenjson(val);
|
|
return new ApiNetReq().doPost(message, "ApiServiceSend");
|
|
}
|
|
|
|
public static HttpResult serviceOtherSend(string message)
|
|
{
|
|
dynamic val = Tools.Todejosn<object>(message);
|
|
val["timeStamp"] = Tools.GetTimestamp2();
|
|
Tools.Toenjson(val);
|
|
return new ApiNetReq().doPost(message, "ApiServiceSendOther");
|
|
}
|
|
|
|
public static string ApiGetCodeHC(string value)
|
|
{
|
|
return APPLEHCHelp.getHkCode(value).ToString();
|
|
}
|
|
|
|
public static Dictionary<string, string> ApiGetInitLoginPwd(string type, string privateData, string salt, string serverPublicValue, string account, string accountPwd, string iteration, string protocol)
|
|
{
|
|
Dictionary<string, object> postData = new Dictionary<string, object>
|
|
{
|
|
{
|
|
"token",
|
|
AppSysConfig.userToken
|
|
},
|
|
{ "type", type },
|
|
{ "privateData", privateData },
|
|
{ "salt", salt },
|
|
{ "serverPublicValue", serverPublicValue },
|
|
{ "account", account },
|
|
{ "accountPwd", accountPwd },
|
|
{ "iteration", iteration },
|
|
{ "protocol", protocol }
|
|
};
|
|
HttpResult httpResult = new ApiNetReq().doPost(postData, "ApiGetInitLoginPwd");
|
|
if (httpResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
dynamic val = Tools.Todejosn<object>(httpResult.Html);
|
|
if (val["Code"] == "0000")
|
|
{
|
|
string obj = val["Data"];
|
|
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
|
string[] array = obj.Split('\n');
|
|
foreach (string text in array)
|
|
{
|
|
string[] array2 = text.Split('=');
|
|
if (array2.Length >= 2)
|
|
{
|
|
string text2 = array2[0].Trim();
|
|
array2[1].Trim();
|
|
if (!dictionary.ContainsKey(text2))
|
|
{
|
|
dictionary.Add(text2, text.Replace(text2 + "=", ""));
|
|
}
|
|
}
|
|
}
|
|
return dictionary;
|
|
}
|
|
}
|
|
return new Dictionary<string, string>();
|
|
}
|
|
|
|
public static Dictionary<string, string> ApiNasQualify(int nasType)
|
|
{
|
|
Dictionary<string, object> postData = new Dictionary<string, object>
|
|
{
|
|
{
|
|
"token",
|
|
AppSysConfig.userToken
|
|
},
|
|
{ "type", "get" },
|
|
{ "nasType", nasType }
|
|
};
|
|
HttpResult httpResult = new ApiNetReq().doPost(postData, "ApiNasQualify");
|
|
if (httpResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
dynamic val = Tools.Todejosn<object>(httpResult.Html);
|
|
if (val["Code"] == "0000")
|
|
{
|
|
string value = val["Data"]["clientInfo"];
|
|
string value2 = val["Data"]["nasQualify"];
|
|
string value3 = val["Data"]["postData"];
|
|
string value4 = val["Data"]["userAgent"];
|
|
return new Dictionary<string, string>
|
|
{
|
|
{ "clientInfo", value },
|
|
{ "nasQualify", value2 },
|
|
{ "postData", value3 },
|
|
{ "userAgent", value4 }
|
|
};
|
|
}
|
|
}
|
|
return new Dictionary<string, string>();
|
|
}
|
|
|
|
public static GetIpProxyModel.ProxyModel[] ApiGetIpProxy(int number, int type)
|
|
{
|
|
if (number > 20)
|
|
{
|
|
number = 20;
|
|
}
|
|
Dictionary<string, object> postData = new Dictionary<string, object>
|
|
{
|
|
{
|
|
"token",
|
|
AppSysConfig.userToken
|
|
},
|
|
{ "number", number },
|
|
{ "type", type }
|
|
};
|
|
HttpResult httpResult = new ApiNetReq().doPost(postData, "ApiGetIpProxy");
|
|
if (httpResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
GetIpProxyModel getIpProxyModel = Tools.Todejosn<GetIpProxyModel>(httpResult.Html);
|
|
if (getIpProxyModel.Code == "0000")
|
|
{
|
|
return getIpProxyModel.Data;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|