Files
2024-07-22 00:43:14 +08:00

794 lines
34 KiB
C#

using System;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web;
using AppleBatch_June.ExecuteTasks;
using AppleBatch_June.Model;
using AppleBatch_June.Utils;
using DotNet.Utilities;
namespace AppleBatch_June.AppleWebServace
{
public class AppleiForgotWeb : AppleWebBase
{
private class CaptchaModel
{
public class Payload
{
public string contentType { get; set; }
public string content { get; set; }
}
public Payload payload { get; set; }
public string token { get; set; }
public string type { get; set; }
public int id { get; set; }
public string reust { get; set; } = "";
}
private string language = "zh_CN";
private AppleAcount acount = new AppleAcount();
public string appleId { get; set; }
public bool CheckAppleId { get; set; }
public AppleiForgotWeb(bool _openVpn, Action<string, DisplyType, string> _action, Action<string, DisplyType, string> _applyAtion, ITaskRunState _taskState)
: base(_action, _applyAtion, _taskState)
{
taskState = _taskState ?? throw new Exception("任务运行状态不能是空的");
base.openVpn = _openVpn;
}
public bool RetrievePassword(AppleAcount _acount, string newPwd, string _noticeKey, bool isCloseAuthen = false, bool ckTailNumber = false)
{
acount = _acount;
if (string.IsNullOrEmpty(base.ProxyIp))
{
base.ProxyIp = ProxyAccountCache.getProxyAccountIP(acount.appleId);
}
appleId = acount.appleId;
base.noticeKey = _noticeKey;
string url = "https://iforgot.apple.com/password/verify/appleid?language=" + language;
string[] array = acount.birthday.Split('-');
if (array.Length != 3)
{
acount.birthday = acount.birthday.Replace('/', '-');
array = acount.birthday.Split('-');
}
if (!(array.Length == 3 || ckTailNumber) && !CheckAppleId)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "生日未导入或者格式错误");
}
else
{
HttpResult webContent = getWebContent(url, "");
if (webContent.StatusCode == HttpStatusCode.OK)
{
string text = new Regex(AppSysConfig.getConfig("Regex_RetrievePassword")).Match(AppleNetworkBase.GetToken(webContent.Html, "boot_args", "script")).Groups[1].Value.Replace("\"", "").Replace(":", "").Replace(" ", "")
.Trim();
if (!string.IsNullOrEmpty(text))
{
text = HttpUtility.UrlEncode(text);
bool num = verifyAppleid(text, acount, newPwd, isCloseAuthen, 0, ckTailNumber);
if (num)
{
ProxyAccountCache.addProxyIp(appleId, base.ProxyIp);
}
return num;
}
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "未知错误");
}
return false;
}
private bool verifyAppleid(string sstt, AppleAcount acount, string newPwd, bool isCloseAuthen, int RetryCount = 0, bool ckTailNumber = false)
{
if (RetryCount >= 5)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证码获取失败,#3");
return false;
}
int num = 0;
CaptchaModel captchaModel = null;
bool flag = false;
do
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "获取验证码.." + (num + 1));
captchaModel = getCaptcha(sstt);
if (captchaModel == null)
{
Thread.Sleep(500);
}
else if (!string.IsNullOrEmpty(captchaModel.payload.content))
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "获取验证码..." + (num + 1));
HttpResult captcha = APIUtlis.getCaptcha(1, captchaModel.payload.content, flag);
if (captcha.StatusCode == HttpStatusCode.OK)
{
dynamic val = Tools.Todejosn<object>(captcha.Html);
if (val["Code"] == "0000")
{
string reust = val["Data"];
captchaModel.reust = reust;
break;
}
flag = !flag;
}
Thread.Sleep(500);
}
num++;
}
while (num <= 5);
if (captchaModel != null)
{
if (!string.IsNullOrEmpty(captchaModel.reust))
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "正在验证账号");
string postData = "{\"id\":\"" + acount.appleId + "\",\"captcha\":{\"id\":" + captchaModel.id + ",\"answer\":\"" + captchaModel.reust + "\",\"token\":\"" + captchaModel.token + "\"}}";
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.Add("X-Apple-I-FD-Client-Info", FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent));
webHeaderCollection.Add("sstt", sstt);
HttpResult httpResult = postWebContent("https://iforgot.apple.com/password/verify/appleid", postData, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeaderCollection);
if (httpResult.StatusCode == HttpStatusCode.OK)
{
APIUtlis.getCaptcha(3, captchaModel.payload.content);
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
string message = serviceErrorsModel.serviceErrors[0].message;
action?.Invoke(base.noticeKey, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
if (CheckAppleId && !message.Contains("未知") && !message.Contains("错误"))
{
return true;
}
return false;
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "不是有效的AppleId");
}
AppSysConfig.proxyModels.Push(new ProxyModel2
{
prixyIp = base.ProxyIp,
applyDate = DateTime.Now
});
return false;
}
if (httpResult.StatusCode == HttpStatusCode.Found)
{
httpResult.Header.AllKeys.Contains("sstt");
APIUtlis.getCaptcha(3, captchaModel.payload.content);
string redirectUrl = httpResult.RedirectUrl;
webHeaderCollection["X-Apple-I-FD-Client-Info"] = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
webHeaderCollection.Add("X-Requested-With", "XMLHttpRequest");
HttpResult webJsonContent = getWebJsonContent(redirectUrl, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeaderCollection);
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
if (isCloseAuthen)
{
if (redirectUrl.ToLower().StartsWith("https://iforgot.apple.com/password/verify/phone"))
{
if (ckTailNumber)
{
if (webJsonContent.Html.Contains("trustedPhones"))
{
IforgotVerifyPhoneModel iforgotVerifyPhoneModel = Tools.Todejosn<IforgotVerifyPhoneModel>(webJsonContent.Html);
if (iforgotVerifyPhoneModel != null)
{
string text = "";
IforgotVerifyPhoneModel.Trustedphone[] array = iforgotVerifyPhoneModel?.trustedPhones;
foreach (IforgotVerifyPhoneModel.Trustedphone trustedphone in array)
{
if (trustedphone != null)
{
text = text + "," + trustedphone.number;
}
}
text = ((!iforgotVerifyPhoneModel.recoverable) ? (text.TrimStart(',') + ", 无法关闭") : (text.TrimStart(',') + ", 可以关闭"));
APIUtlis.ApiApplyAct(44, "尾号查询");
action?.Invoke(base.noticeKey, DisplyType.xinxi, "查询到号码:" + text);
return false;
}
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "手机号码获取失败");
return false;
}
sstt = webJsonContent.Header["sstt"];
bool num2 = unenrollment(sstt, acount, newPwd);
if (num2)
{
AppSysConfig.proxyModels.Push(new ProxyModel2
{
prixyIp = base.ProxyIp,
applyDate = DateTime.Now
});
}
return num2;
}
acount.notAuthen = true;
action?.Invoke(base.noticeKey, DisplyType.xinxi, "没有双重认证");
AppSysConfig.proxyModels.Push(new ProxyModel2
{
prixyIp = base.ProxyIp,
applyDate = DateTime.Now
});
return false;
}
if (CheckAppleId)
{
string[] array2 = AppSysConfig.getConfig("CheckAppleIdReust").Split(',');
string text2 = "";
string[] array3 = array2;
for (int i = 0; i < array3.Length; i++)
{
string[] array4 = array3[i].Split('|');
if (webJsonContent.Html.Contains(array4[0]))
{
text2 = array4[1] + ",";
}
}
text2 = text2.TrimEnd(',');
if (string.IsNullOrEmpty(text2))
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "正常账号");
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, text2);
}
return true;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "正在获取重设方式");
if (webJsonContent.Html.Contains("reset_password") && webJsonContent.Header.AllKeys.Contains("sstt"))
{
sstt = webJsonContent.Header["sstt"];
webHeaderCollection["sstt"] = sstt;
webHeaderCollection["X-Apple-I-FD-Client-Info"] = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
HttpResult httpResult2 = postWebContent("https://iforgot.apple.com/recovery/options", "{\"recoveryOption\":\"reset_password\"}", "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeaderCollection);
if (httpResult2.StatusCode == HttpStatusCode.Found)
{
webJsonContent = getWebJsonContent(httpResult2.RedirectUrl, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeaderCollection);
if (webJsonContent.StatusCode == HttpStatusCode.OK && !webJsonContent.Html.Contains("questions") && !webJsonContent.RedirectUrl.ToLower().StartsWith("https://iforgot.apple.com/password/verify/birthday"))
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "没有重设密码的方式");
return false;
}
}
}
if (!webJsonContent.Html.Contains("questions") && !webJsonContent.RedirectUrl.ToLower().StartsWith("https://iforgot.apple.com/password/verify/birthday"))
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "没有重设密码的方式");
return false;
}
sstt = webJsonContent.Header["sstt"];
webHeaderCollection["sstt"] = sstt;
webHeaderCollection["X-Apple-I-FD-Client-Info"] = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
if (!webJsonContent.Html.Contains("questions"))
{
return VerifyBirthday(webJsonContent.RedirectUrl, acount, newPwd, webHeaderCollection);
}
string postData2 = "{\"type\":\"questions\"}";
HttpResult httpResult3 = postWebContent("https://iforgot.apple.com/password/authenticationmethod", postData2, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeaderCollection);
if (httpResult3.StatusCode == HttpStatusCode.Found && httpResult3.RedirectUrl.Contains("https://iforgot.apple.com/error"))
{
int num3 = new Random(Guid.NewGuid().GetHashCode()).Next(1, 5);
Thread.Sleep(1000 * num3);
httpResult3 = postWebContent("https://iforgot.apple.com/password/authenticationmethod", postData2, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeaderCollection);
}
if (httpResult3.StatusCode == HttpStatusCode.Found)
{
if (httpResult3.RedirectUrl.Contains("https://iforgot.apple.com/error"))
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密保选择加载失败.");
return false;
}
return VerifyBirthday(httpResult3.RedirectUrl, acount, newPwd, webHeaderCollection);
}
}
}
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "未知错误#2");
return false;
}
if (httpResult.Html.Contains("captchaAnswer.Invalid"))
{
APIUtlis.getCaptcha(2, captchaModel.payload.content);
return verifyAppleid(sstt, acount, newPwd, isCloseAuthen, RetryCount + 1, ckTailNumber);
}
ServiceErrorsModel serviceErrorsModel2 = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel2 != null)
{
if (serviceErrorsModel2.validationErrors != null && serviceErrorsModel2.validationErrors.Length != 0)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel2.validationErrors[0].message);
return false;
}
if (serviceErrorsModel2.service_errors != null && serviceErrorsModel2.service_errors.Length != 0)
{
string message2 = serviceErrorsModel2.service_errors[0].message;
action?.Invoke(base.noticeKey, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel2.service_errors[0].message);
if (CheckAppleId && !message2.Contains("未知") && !message2.Contains("错误"))
{
return true;
}
return false;
}
if (serviceErrorsModel2.serviceErrors != null && serviceErrorsModel2.serviceErrors.Length != 0)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel2.serviceErrors[0].message);
return false;
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "请求失败");
}
return false;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证码获取失败#2");
return false;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证码获取失败");
return false;
}
private bool VerifyBirthday(string RedirectUrl, AppleAcount acount, string newPwd, WebHeaderCollection webHeader)
{
string text = "";
action?.Invoke(base.noticeKey, DisplyType.xinxi, "正在验证生日");
HttpResult webJsonContent = getWebJsonContent(RedirectUrl, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeader);
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
text = webJsonContent.Header["sstt"];
webHeader["sstt"] = text;
string[] array = acount.birthday.Split('-');
string postData = "{\"monthOfYear\":\"" + array[1] + "\",\"dayOfMonth\":\"" + array[2] + "\",\"year\":\"" + array[0] + "\"}";
HttpResult httpResult = postWebContent("https://iforgot.apple.com/password/verify/birthday", postData, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeader);
if (httpResult.StatusCode != HttpStatusCode.Found)
{
if (httpResult.StatusCode == HttpStatusCode.BadRequest)
{
ServiceErrorsModel serviceErrors = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
string serviceError = getServiceError(serviceErrors);
if (!string.IsNullOrEmpty(serviceError))
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "生日验证失败:" + serviceError);
return false;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证生日出现未知错误");
return false;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "网络异常...#Birthday," + (int)httpResult.StatusCode);
return false;
}
if (!httpResult.RedirectUrl.ToLower().StartsWith("https://iforgot.apple.com/password/authenticationmethod"))
{
return VerifyQuestions(httpResult.RedirectUrl, acount, newPwd, webHeader);
}
webHeader["X-Apple-I-FD-Client-Info"] = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
HttpResult webJsonContent2 = getWebJsonContent(httpResult.RedirectUrl, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeader);
if (webJsonContent2.StatusCode != HttpStatusCode.OK)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密保获取失败2");
return false;
}
if (!webJsonContent2.Html.Contains("questions"))
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "没有重设密码的方式#2");
return false;
}
text = webJsonContent2.Header["sstt"];
webHeader["sstt"] = text;
HttpResult httpResult2 = postWebContent("https://iforgot.apple.com/password/authenticationmethod", "{\"type\":\"questions\"}", "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeader);
if (httpResult2.StatusCode == HttpStatusCode.Found)
{
return VerifyQuestions(httpResult2.RedirectUrl, acount, newPwd, webHeader);
}
}
return false;
}
public bool VerifyQuestions(string RedirectUrl, AppleAcount acount, string newPwd, WebHeaderCollection webHeader)
{
string text = "";
HttpResult webJsonContent = getWebJsonContent(RedirectUrl, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeader);
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
int num = 0;
HttpResult httpResult;
while (true)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "正在验证密保");
text = webJsonContent.Header["sstt"];
webHeader["sstt"] = text;
AothQuestions aothQuestions = Tools.Todejosn<AothQuestions>(webJsonContent.Html);
string[] array = new string[3] { acount.appleQt1, acount.appleQt2, acount.appleQt3 };
AothQuestions aothQuestions2 = new AothQuestions();
aothQuestions2.questions = new AothQuestions.Question[2];
int num2 = 0;
AothQuestions.Question[] questions = aothQuestions.questions;
foreach (AothQuestions.Question question in questions)
{
string answer = array[Tools.getAnwerId_Index(question.id) - 1];
aothQuestions2.questions[num2] = new AothQuestions.Question
{
id = question.id,
answer = answer,
number = question.number,
question = question.question
};
num2++;
}
string postData = Tools.Toenjson(aothQuestions2);
httpResult = postWebContent("https://iforgot.apple.com/password/verify/questions", postData, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeader);
if (httpResult.StatusCode == HttpStatusCode.Found)
{
HttpResult webJsonContent2 = getWebJsonContent(httpResult.RedirectUrl, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeader);
if (webJsonContent2.StatusCode == HttpStatusCode.Found)
{
text = httpResult.Header["sstt"];
webHeader["sstt"] = text;
return restPwd(webJsonContent2.RedirectUrl, newPwd, webHeader);
}
if (webJsonContent2.StatusCode == HttpStatusCode.OK && webJsonContent2.Html.Contains("unlock_account"))
{
text = webJsonContent2.Header["sstt"];
webHeader["sstt"] = text;
action?.Invoke(base.noticeKey, DisplyType.xinxi, "正在解锁密码");
HttpResult httpResult2 = postWebContent("https://iforgot.apple.com/password/reset/options", "{\"type\":\"unlock_account\"}", "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeader);
if (httpResult2.StatusCode == HttpStatusCode.Found)
{
HttpResult webJsonContent3 = getWebJsonContent(httpResult2.RedirectUrl, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeader);
if (webJsonContent3.StatusCode == HttpStatusCode.OK)
{
text = webJsonContent3.Header["sstt"];
webHeader["sstt"] = text;
HttpResult httpResult3 = postWebContent("https://iforgot.apple.com/password/unlock/forgot", "{}", "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeader);
if (httpResult3.StatusCode == HttpStatusCode.Found)
{
return restPwd(httpResult3.RedirectUrl, newPwd, webHeader);
}
}
}
}
}
else
{
if (httpResult.StatusCode != HttpStatusCode.BadRequest)
{
break;
}
ServiceErrorsModel serviceErrors = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
string serviceError = getServiceError(serviceErrors);
if (string.IsNullOrEmpty(serviceError))
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证密保出现未知错误");
return false;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证密保失败:" + serviceError);
if (!serviceError.Contains("发生未知错误") || num >= base.MaxRetryCount)
{
return false;
}
Thread.Sleep(3000);
if (num != 0)
{
base.ProxyIp = "";
}
num++;
}
if (num >= base.MaxRetryCount)
{
return false;
}
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, string.Concat("验证密保出现未知错误#1(", httpResult.StatusCode, ")"));
return false;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证密保获取失败");
return false;
}
private bool restPwd(string RedirectUrl, string newPwd, WebHeaderCollection webHeader, int retry = 0)
{
HttpResult webJsonContent = getWebJsonContent(RedirectUrl, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeader);
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
string value = webJsonContent.Header["sstt"];
webHeader["sstt"] = value;
action?.Invoke(base.noticeKey, DisplyType.xinxi, "正在设置新密码");
HttpResult httpResult = postWebContent("https://iforgot.apple.com/password/reset", "{\"password\":\"" + newPwd + "\"}", "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeader);
if (httpResult.StatusCode == HttpStatusCode.BadRequest || httpResult.StatusCode == HttpStatusCode.Unauthorized)
{
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "设置密码异常:" + serviceError);
if (serviceError.Contains("不能包含") || serviceError.Contains("未使用过的密码"))
{
acount.notRepeatPwd = true;
}
if (serviceError.Contains("发生未知错误") && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return restPwd(RedirectUrl, newPwd, webHeader, retry + 1);
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "请求失败");
}
return false;
}
if (httpResult.StatusCode == (HttpStatusCode)260)
{
action?.Invoke(base.noticeKey, DisplyType.mima, newPwd);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密码重置完成");
AppSysConfig.proxyModels.Push(new ProxyModel2
{
prixyIp = base.ProxyIp,
applyDate = DateTime.Now
});
return true;
}
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "未知错误");
return false;
}
public bool unenrollment(string sstt, AppleAcount acount, string newPwd)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "正在关闭双重认证");
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.Add("X-Apple-I-FD-Client-Info", FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent));
webHeaderCollection.Add("sstt", sstt);
webHeaderCollection.Add("X-Requested-With", "XMLHttpRequest");
HttpResult webContent = getWebContent("https://iforgot.apple.com/password/verify/phone", "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeaderCollection);
if (webContent.StatusCode == HttpStatusCode.OK)
{
sstt = new Regex(AppSysConfig.getConfig("Regex_unenrollment")).Match(AppleNetworkBase.GetToken(webContent.Html, "boot_args", "script")).Groups[1].Value.Replace("\"", "").Replace(":", "").Replace(" ", "")
.Trim();
webContent.Html.Contains("forgotPasswordFlow\":true}");
if (!string.IsNullOrEmpty(sstt))
{
sstt = HttpUtility.UrlEncode(sstt);
webHeaderCollection["sstt"] = sstt;
webHeaderCollection["X-Apple-I-FD-Client-Info"] = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
HttpResult httpResult = postWebContent("https://iforgot.apple.com/password/verify/phone/unenrollment", "", "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeaderCollection);
if (httpResult.StatusCode == HttpStatusCode.NotFound)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "该账户双重无法关闭");
return false;
}
if (httpResult.StatusCode == HttpStatusCode.Found)
{
HttpResult webJsonContent = getWebJsonContent(httpResult.RedirectUrl, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeaderCollection);
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
sstt = webJsonContent.Header["sstt"];
webHeaderCollection["sstt"] = sstt;
webHeaderCollection["X-Apple-I-FD-Client-Info"] = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "正在验证生日信息");
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
sstt = webJsonContent.Header["sstt"];
webHeaderCollection["sstt"] = sstt;
string[] array = acount.birthday.Split('-');
string postData = "{\"monthOfYear\":\"" + array[1].PadLeft(2, '0') + "\",\"dayOfMonth\":\"" + array[2].PadLeft(2, '0') + "\",\"year\":\"" + array[0] + "\"}";
HttpResult httpResult2 = postWebContent("https://iforgot.apple.com/unenrollment/verify/birthday", postData, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeaderCollection);
if (httpResult2.StatusCode == HttpStatusCode.Found)
{
HttpResult webJsonContent2 = getWebJsonContent(httpResult2.RedirectUrl, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeaderCollection);
if (webJsonContent2.StatusCode == HttpStatusCode.OK)
{
int num = 0;
HttpResult httpResult3;
while (true)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "正在验证密保");
sstt = webJsonContent2.Header["sstt"];
webHeaderCollection["sstt"] = sstt;
AothQuestions aothQuestions = Tools.Todejosn<AothQuestions>(webJsonContent2.Html);
string[] array2 = new string[3] { acount.appleQt1, acount.appleQt2, acount.appleQt3 };
AothQuestions aothQuestions2 = new AothQuestions();
aothQuestions2.questions = new AothQuestions.Question[2];
int num2 = 0;
AothQuestions.Question[] questions = aothQuestions.questions;
foreach (AothQuestions.Question question in questions)
{
string answer = array2[Tools.getAnwerId_Index(question.id) - 1];
aothQuestions2.questions[num2] = new AothQuestions.Question
{
id = question.id,
answer = answer,
number = question.number,
question = question.question
};
num2++;
}
string postData2 = Tools.Toenjson(aothQuestions2);
httpResult3 = postWebContent("https://iforgot.apple.com/unenrollment/verify/questions", postData2, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeaderCollection);
if (httpResult3.StatusCode == HttpStatusCode.Found && httpResult3.RedirectUrl.Contains("/error"))
{
Thread.Sleep(2000);
httpResult3 = postWebContent("https://iforgot.apple.com/unenrollment/verify/questions", postData2, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeaderCollection);
}
if (httpResult3.StatusCode != HttpStatusCode.Found)
{
if (httpResult3.StatusCode != HttpStatusCode.BadRequest)
{
break;
}
ServiceErrorsModel serviceErrors = Tools.Todejosn<ServiceErrorsModel>(httpResult3.Html);
string serviceError = getServiceError(serviceErrors);
if (!string.IsNullOrEmpty(serviceError))
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证密保失败:" + serviceError);
if (serviceError.Contains("发生未知错误") && num < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (num != 0)
{
base.ProxyIp = "";
}
num++;
if (num >= base.MaxRetryCount)
{
return false;
}
continue;
}
return false;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证密保出现未知错误");
return false;
}
if (httpResult3.RedirectUrl == "https://iforgot.apple.com/error")
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密保验证返回错误。");
return false;
}
return unenrollmentRestPwd(httpResult3.RedirectUrl, newPwd, webHeaderCollection);
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, string.Concat("验证密保出现未知错误#1(", httpResult3.StatusCode, ")"));
return false;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证密保获取失败");
return false;
}
if (httpResult2.StatusCode == HttpStatusCode.BadRequest)
{
ServiceErrorsModel serviceErrors2 = Tools.Todejosn<ServiceErrorsModel>(httpResult2.Html);
string serviceError2 = getServiceError(serviceErrors2);
if (!string.IsNullOrEmpty(serviceError2))
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "生日验证失败:" + serviceError2);
return false;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证生日出现未知错误");
return false;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "网络异常...2#Birthday," + (int)httpResult2.StatusCode);
return false;
}
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "网络异常");
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "网络异常");
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "双重手机号码认证失败");
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "双重手机号码获取失败");
}
return false;
}
private bool unenrollmentRestPwd(string RedirectUrl, string newPwd, WebHeaderCollection webHeader, int retry = 0)
{
HttpResult webJsonContent = getWebJsonContent(RedirectUrl, "https://iforgot.apple.com/unenrollment/verify/appleid?language=" + language, webHeader);
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
string value = webJsonContent.Header["sstt"];
webHeader["sstt"] = value;
webHeader["X-Apple-I-FD-Client-Info"] = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
HttpResult httpResult = postWebContent("https://iforgot.apple.com/unenrollment", "", "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeader);
if (httpResult.StatusCode == HttpStatusCode.Found)
{
value = httpResult.Header["sstt"];
webHeader["sstt"] = value;
webHeader["X-Apple-I-FD-Client-Info"] = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "正在设置新密码");
HttpResult httpResult2 = postWebContent("https://iforgot.apple.com/unenrollment/reset", "{\"password\":\"" + newPwd + "\"}", "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeader, "application/json, text/javascript, *; q=0.01");
if (httpResult2.StatusCode == HttpStatusCode.BadRequest || httpResult2.StatusCode == HttpStatusCode.Unauthorized)
{
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult2.Html);
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "设置新密码异常:" + serviceError);
if (serviceError.Contains("不能包含") || serviceError.Contains("未使用过的密码"))
{
acount.notRepeatPwd = true;
}
if (serviceError.Contains("发生未知错误") && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return unenrollmentRestPwd(RedirectUrl, newPwd, webHeader, retry + 1);
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "请求失败");
}
return false;
}
if (httpResult2.StatusCode == (HttpStatusCode)260)
{
acount.applePwd = newPwd;
action?.Invoke(base.noticeKey, DisplyType.mima, newPwd);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "双重关闭成功,密码重置完成");
return true;
}
}
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "未知错误");
return false;
}
private CaptchaModel getCaptcha(string sstt)
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.Add("X-Apple-I-FD-Client-Info", FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent));
webHeaderCollection.Add("sstt", sstt);
HttpResult httpResult = postWebContent("https://iforgot.apple.com/captcha", "{\"type\":\"IMAGE\"}", "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeaderCollection);
if (httpResult.StatusCode == HttpStatusCode.OK)
{
return Tools.Todejosn<CaptchaModel>(httpResult.Html);
}
return null;
}
}
}