Files
kami_itunes_june/AppleBatch_June/NewAppleManageWebUtlis.cs
danial cb905409f8 Refactor AppleBatch_June project:
- Removed DotRas library dependency in RasTools.cs, providing empty implementations for Connect and Disconnect methods.
- Updated context menu implementation in ReddemHelp.cs to use ToolStripMenuItem and ContextMenuStrip.
- Replaced caching mechanism in SiteHelper.cs with a custom dictionary-based implementation, removing reliance on HttpRuntime.Cache.
- Switched from JavaScriptSerializer to Newtonsoft.Json for JSON serialization/deserialization in multiple files (Tools.cs, addMaterial.cs).
- Added WebHeaderCollection property to HttpItem.cs for better header management.
- Deleted obsolete AssemblyInfo.cs file.
- Introduced apple_balance_query.py for querying Apple ID balance via Privacy Center, implementing authentication and balance retrieval logic.
2025-11-10 17:38:18 +08:00

3758 lines
149 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web;
using Newtonsoft.Json;
using AppleBatch_June.ExecuteTasks;
using AppleBatch_June.Model;
using AppleBatch_June.Utils;
using DotNet.Utilities;
namespace AppleBatch_June
{
public class NewAppleManageWebUtlis
{
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; } = "";
}
public List<CookieItem> listCookie = new List<CookieItem>();
private Dictionary<string, string> handelDic = new Dictionary<string, string>();
private static string homeLanguage = "zh_CN";
protected string Apple_Widget_Key = "af1139274f266b22b68c2a3e7ad932cb3c0bbe854e13a79af78dcc73136882c3";
private string verifyquestionsUrl = "https://idmsa.apple.com/appleauth/auth/verify/questions";
private string appleHomeUrl = "https://appleid.apple.com/account/manage";
private string apiKey = "cbf64fd6843ee630b463f358ea0b707b";
private AvailableSecurityQuestions securityQuestions;
private LoginAppleInfo loginAppleInfo;
public Action<string, DisplyType, string> action;
protected Action<string, DisplyType, string> applyAtion;
public ITaskRunState taskState;
public AppleChangeItem _changeItem;
private bool isPwdViey;
private bool isViey;
private bool isVieyBirthday;
public bool openVpn;
private AppleAcount acount = new AppleAcount();
private Func<string, int, string> getCodeAct_;
private bool isError;
public string checkDisableScnt = "";
public string widgKey = string.Empty;
private string dataR = "";
private static readonly object lockSendMsmObj = new object();
public bool AuthenDoubleOpenState;
private string redirectURI = "https://appleid.apple.com";
private string language = "zh_CN";
private string userAgent { get; set; }
private string authUrl => "https://idmsa.apple.com/appleauth/auth/signin?widgetKey=" + Apple_Widget_Key + "&language=" + homeLanguage;
public string appleId { get; set; }
private string iframeId { get; set; } = "auth-w78m90aa-d7ll-rirf-04xy-rsvumkpw";
public bool idIsNormal { get; set; }
private string accountFirstName { get; set; }
private string accountLastName { get; set; }
private string XAppleIDAccountCountry { get; set; } = "";
public bool openHsa2 { get; set; }
public bool isChangAppleId { get; set; }
public string ProxyIp { get; set; }
public bool isUpProxyAccountCache { get; set; } = true;
private string scnt { get; set; }
public NewAppleManageWebUtlis(Action<string, DisplyType, string> _action, Action<string, DisplyType, string> _applyAtion, ITaskRunState _taskState)
{
taskState = _taskState ?? throw new Exception("任务运行状态不能是空的");
action = _action;
applyAtion = _applyAtion;
userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36";
userAgent = Tools.GetRandomUserAgent();
}
public bool applyChangeAcount(AppleAcount acount, AppleChangeItem changeItem, bool errorGoint, bool _openVpn, ref string accountName)
{
if (string.IsNullOrEmpty(ProxyIp))
{
ProxyAccountModel proxyAccountInfo = ProxyAccountCache.getProxyAccountInfo(acount.appleId);
if (proxyAccountInfo != null)
{
ProxyIp = proxyAccountInfo.ProxyIp;
if (string.IsNullOrEmpty(proxyAccountInfo.accountWebUserAgent))
{
proxyAccountInfo.accountWebUserAgent = userAgent;
}
else
{
userAgent = proxyAccountInfo.accountWebUserAgent;
}
}
}
openVpn = _openVpn;
listCookie.Add(new CookieItem
{
Key = "idclient",
Value = "web"
});
this.acount = acount;
appleId = acount.appleId;
try
{
_changeItem = changeItem;
string errMsg = "";
if (authsignin(this.acount.appleId, this.acount.applePwd, ref errMsg))
{
if (!handelDic.ContainsKey("scnt"))
{
ProxyIp = "";
authsignin(this.acount.appleId, this.acount.applePwd, ref errMsg);
if (!handelDic.ContainsKey("scnt"))
{
action?.Invoke(appleId, DisplyType.xinxi, "登录初始化失败,请重试");
return false;
}
}
if (isPwdViey)
{
changeItem.newPwd = "";
}
if (isViey)
{
acount.appleQt1 = changeItem.newQt1;
acount.appleQt2 = changeItem.newQt2;
acount.appleQt3 = changeItem.newQt3;
changeItem.newQt1 = "";
if (isPwdViey && isChangAppleId && isVieyBirthday)
{
action?.Invoke(appleId, DisplyType.xinxi, "账号修改完成");
return true;
}
isViey = false;
handelDic.Clear();
return applyChangeAcount(this.acount, _changeItem, errorGoint, openVpn, ref accountName);
}
if (appleauthAuth(acount))
{
action?.Invoke(appleId, DisplyType.xinxi, "登录成功");
ProxyAccountCache.addProxyIp(acount.appleId, ProxyIp);
if (intoHome())
{
manageFamily();
bool flag = true;
getSecuritydevices();
if (!string.IsNullOrEmpty(changeItem.newQt1))
{
if (!(flag = changQuestions(changeItem.newQt1, changeItem.newQt2, changeItem.newQt3)))
{
flag = false;
}
if (!flag && !errorGoint)
{
return false;
}
}
if (!string.IsNullOrEmpty(changeItem.newPwd))
{
if (!(flag = changePwd(acount.applePwd, changeItem.newPwd)))
{
flag = false;
}
if (!flag && !errorGoint)
{
return false;
}
}
if (!string.IsNullOrEmpty(changeItem.newshengri) && !isVieyBirthday)
{
if (!(flag = changeBirthDate(changeItem.newshengri)))
{
flag = false;
}
if (!flag && !errorGoint)
{
return false;
}
}
if (!string.IsNullOrEmpty(changeItem.editAddrs))
{
flag = editAddrs(changeItem.editAddrs);
}
if (!string.IsNullOrEmpty(acount.newAppleId) && !isChangAppleId)
{
flag = setAccnount(acount.newAppleId, acount.newApplePopPwd, "cbf64fd6843ee630b463f358ea0b707b");
}
if (changeItem.pay != null)
{
flag = changenPayment(changeItem.pay);
}
if (flag && !string.IsNullOrEmpty(ProxyIp))
{
AppSysConfig.proxyModels.Push(new ProxyModel2
{
prixyIp = ProxyIp,
applyDate = DateTime.Now
});
}
return flag;
}
}
}
}
catch (Exception ex)
{
action?.Invoke(appleId, DisplyType.xinxi, ex.Message);
}
finally
{
accountName = appleId;
try
{
signout();
}
catch (Exception)
{
}
}
return false;
}
public bool applyQueryAuthBalance(AppleAcount acount, bool _openVpn)
{
Apple_Widget_Key = "04659e25236376d440c224638c1cdd6a001abdd7f186cdcfa120abf35417efab";
openVpn = _openVpn;
listCookie.Add(new CookieItem
{
Key = "idclient",
Value = "web"
});
this.acount = acount;
appleId = acount.appleId;
try
{
HttpResult webContent = getWebContent("https://privacy.apple.com/account", "");
if (webContent.StatusCode == HttpStatusCode.OK)
{
string val = new Regex(AppSysConfig.getConfig("Regex_apply_CsrfToken")).Match(webContent.Html).Groups[1].Value.Trim();
string errMsg = "";
if (authsignin(this.acount.appleId, this.acount.applePwd, ref errMsg) && appleauthAuth(acount))
{
string value = "";
handelDic.TryGetValue("X-Apple-OAuth-Grant-Code", out value);
string val2 = Tools.EncodeBase64(Encoding.UTF8.GetBytes(Apple_Widget_Key + ":" + value));
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("x-csrf-token", val);
webHeaderCollection.AddWebHander("x-apple-authentication", val2);
getWebJsonContent("https://privacy.apple.com/session/create", "https://privacy.apple.com/account", webHeaderCollection, "application/json, text/plain, */*");
action?.Invoke(appleId, DisplyType.xinxi, "正在获取余额");
HttpResult webJsonContent = getWebJsonContent("https://privacy.apple.com/section/delete-account", "https://privacy.apple.com/account", webHeaderCollection, "application/json, text/plain, */*");
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
if (webJsonContent.Html.Contains("store_balance"))
{
string text = new Regex(AppSysConfig.getConfig("Regex_applyQueryAuthBalance")).Match(webJsonContent.Html).Groups[1].Value.Trim().TrimEnd(',');
if (string.IsNullOrEmpty(text))
{
action?.Invoke(appleId, DisplyType.xinxi, "余额解析失败");
return false;
}
Dictionary<string, object> dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>("{" + text + "}");
decimal num = (dynamic)dictionary["balance"];
string text2 = (dynamic)dictionary["currency"];
action?.Invoke(appleId, DisplyType.balance, num + " " + text2);
}
else
{
action?.Invoke(appleId, DisplyType.balance, "0");
}
action?.Invoke(appleId, DisplyType.xinxi, "查询完成");
return true;
}
action?.Invoke(appleId, DisplyType.xinxi, "正在重新获取余额");
webJsonContent = getWebJsonContent("https://privacy.apple.com/section/deactivate-account", "https://privacy.apple.com/account");
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
if (webJsonContent.Html.Contains("store_balance"))
{
string text3 = new Regex(AppSysConfig.getConfig("Regex_applyQueryAuthBalance")).Match(webJsonContent.Html).Groups[1].Value.Trim().TrimEnd(',');
if (string.IsNullOrEmpty(text3))
{
action?.Invoke(appleId, DisplyType.xinxi, "余额解析失败");
return false;
}
Dictionary<string, object> dictionary2 = JsonConvert.DeserializeObject<Dictionary<string, object>>("{" + text3 + "}");
decimal num2 = (dynamic)dictionary2["balance"];
string text4 = (dynamic)dictionary2["currency"];
action?.Invoke(appleId, DisplyType.balance, num2 + " " + text4);
}
else
{
action?.Invoke(appleId, DisplyType.balance, "0");
}
action?.Invoke(appleId, DisplyType.xinxi, "查询完成");
return true;
}
action?.Invoke(appleId, DisplyType.xinxi, "余额获取失败");
}
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, "页面加载失败#1");
}
}
catch (Exception ex)
{
action?.Invoke(appleId, DisplyType.xinxi, ex.Message);
}
finally
{
try
{
priveSignout();
}
catch (Exception)
{
}
}
return false;
}
public bool OpenAuthen(AppleAcount acount, AppleChangeItem changeItem, bool _openVpn, Func<string, int, string> getCodeAct)
{
if (string.IsNullOrEmpty(ProxyIp))
{
ProxyIp = ProxyAccountCache.getProxyAccountIP(acount.appleId);
}
openVpn = _openVpn;
listCookie.Add(new CookieItem
{
Key = "idclient",
Value = "web"
});
this.acount = acount;
appleId = acount.appleId;
_changeItem = changeItem;
string errMsg = "";
getCodeAct_ = getCodeAct;
openHsa2 = true;
try
{
if (authsignin(this.acount.appleId, this.acount.applePwd, ref errMsg))
{
if (appleauthAuth(acount) && !AuthenDoubleOpenState)
{
action?.Invoke(appleId, DisplyType.xinxi, "登录成功");
ProxyAccountCache.addProxyIp(acount.appleId, ProxyIp);
if (intoHome())
{
if (string.IsNullOrEmpty(acount.moblie))
{
action?.Invoke(appleId, DisplyType.xinxi, "请先导入手机号码");
return false;
}
getSecuritydevices();
AuthenDoubleOpenState = OpenHsa2Act(_changeItem.mode, _changeItem.countryCode, apiKey);
}
}
return AuthenDoubleOpenState;
}
}
catch (Exception ex)
{
action?.Invoke(appleId, DisplyType.xinxi, ex.Message);
}
finally
{
try
{
signout();
}
catch (Exception)
{
}
}
return false;
}
public bool editAddrs(string addres)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
string[] array = addres.Split(',');
foreach (string text in array)
{
if (string.IsNullOrEmpty(text))
{
continue;
}
string[] array2 = text.Split(':');
if (array2.Length != 2)
{
continue;
}
string text2 = array2[0];
if (!(text2 == "姓氏"))
{
if (!(text2 == "名字"))
{
dictionary2.Add(ConverUTF8(array2[0].Trim()), ConverUTF8(array2[1].Trim()));
}
else
{
dictionary.Add("firstName", ConverUTF8(array2[1].Trim()));
}
}
else
{
dictionary.Add("lastName", ConverUTF8(array2[1].Trim()));
}
}
if (dictionary.Count > 0)
{
if (dictionary.Count == 1)
{
if (dictionary.ContainsKey("firstName"))
{
dictionary.Add("lastName", accountLastName);
}
else
{
dictionary.Add("firstName", accountFirstName);
}
}
dictionary.Add("middleName", "");
EditMangName(JsonConvert.SerializeObject(dictionary));
}
return EditAddres(dictionary2);
}
public bool EditMangName(string putJson)
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", Apple_Widget_Key);
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Domain-Id", "1");
if (handelDic.ContainsKey("scnt"))
{
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
}
webHeaderCollection.AddWebHander("X-Apple-Api-Key", apiKey.Trim());
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = putWebContent("https://appleid.apple.com/account/manage/name", putJson, appleHomeUrl, webHeaderCollection);
if (httpResult.StatusCode == HttpStatusCode.BadRequest || httpResult.StatusCode == HttpStatusCode.Unauthorized)
{
ServiceErrorsModel serviceErrorsModel = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "名称修改失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "名称修改失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
}
if (httpResult.StatusCode == HttpStatusCode.OK)
{
action?.Invoke(appleId, DisplyType.xinxi, "名称修改完成");
return true;
}
if (httpResult.StatusCode == HttpStatusCode.Forbidden)
{
action?.Invoke(appleId, DisplyType.xinxi, "名称修改失败,请求错误");
}
action?.Invoke(appleId, DisplyType.xinxi, "名称修改失败,未知异常");
return false;
}
public string getDicValue(Dictionary<string, string> suos, string key, string dfValue)
{
if (suos.ContainsKey(key))
{
return suos[key].Trim();
}
return dfValue;
}
private string ConverUTF8(string value)
{
return Encoding.UTF8.GetString(Encoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(value)));
}
public bool EditAddres(Dictionary<string, string> pairs)
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Domain-Id", "1");
webHeaderCollection.AddWebHander("X-Apple-Api-Key", apiKey.Trim());
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult webJsonContent = getWebJsonContent("https://appleid.apple.com/account/manage/payment", "https://appleid.apple.com/account/manage", webHeaderCollection);
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
action?.Invoke(appleId, DisplyType.xinxi, "正在修改内容");
string text = "ownerName";
ManagePayment managePayment = JsonConvert.DeserializeObject<ManagePayment>(webJsonContent.Html);
string text2 = "";
if (pairs.ContainsKey("税号"))
{
text2 = "\"taxId\":\"" + getDicValue(pairs, "税号", "") + "\",";
}
else if (managePayment.primaryPaymentMethod.taxId != null)
{
text2 = "\"taxId\":\"" + managePayment.primaryPaymentMethod.taxId + "\",";
}
string text3 = "";
if (pairs.ContainsKey("卡号"))
{
text3 = text3 + "\"number\":\"" + getDicValue(pairs, "卡号", "") + "\",";
text = "nameOnCard";
}
else if (managePayment.primaryPaymentMethod.number != null)
{
text3 = text3 + "\"number\":\"" + managePayment.primaryPaymentMethod.number + "\",";
}
if (pairs.ContainsKey("有效期限年"))
{
text3 = text3 + "\"expirationYear\":\"" + getDicValue(pairs, "有效期限年", "") + "\",";
}
else if (managePayment.primaryPaymentMethod.expirationYear.HasValue)
{
text3 = text3 + "\"expirationYear\":\"" + managePayment.primaryPaymentMethod.expirationYear + "\",";
}
if (pairs.ContainsKey("有效期限月"))
{
text3 = text3 + "\"expirationMonth\":\"" + getDicValue(pairs, "有效期限月", "") + "\",";
}
else if (managePayment.primaryPaymentMethod.expirationMonth.HasValue)
{
text3 = text3 + "\"expirationMonth\":\"" + managePayment.primaryPaymentMethod.expirationMonth + "\",";
}
if (pairs.ContainsKey("安全码"))
{
text3 = text3 + "\"cvv\":\"" + getDicValue(pairs, "安全码", "") + "\",";
}
if (managePayment.primaryPaymentMethod.nameOnCard != null)
{
text = "nameOnCard";
}
string putData = string.Concat("{\"" + text + "\":{\"firstName\":\"" + getDicValue(pairs, "账单名字", managePayment.primaryPaymentMethod.ownerName.firstName) + "\",\"lastName\":\"" + getDicValue(pairs, "账单姓氏", managePayment.primaryPaymentMethod.ownerName.lastName) + "\"},\"phoneNumber\":{\"areaCode\":\"" + (getDicValue(pairs, "电话", managePayment.primaryPaymentMethod.phoneNumber.number).Contains(getDicValue(pairs, "区号", managePayment.primaryPaymentMethod.phoneNumber.areaCode)) ? "" : getDicValue(pairs, "区号", managePayment.primaryPaymentMethod.phoneNumber.areaCode)) + "\",\"number\":\"" + getDicValue(pairs, "电话", managePayment.primaryPaymentMethod.phoneNumber.number).Replace("(", "").Replace(")", "").Replace("-", "")
.Replace(" ", "") + "\",\"countryCode\":\"" + managePayment.primaryPaymentMethod.phoneNumber.countryCode + "\"},\"billingAddress\":{\"line1\":\"" + getDicValue(pairs, "街道地址", managePayment.primaryPaymentMethod.billingAddress.line1) + "\",\"line2\":\"" + getDicValue(pairs, "楼号单元", managePayment.primaryPaymentMethod.billingAddress.line2) + "\",\"line3\":\"", "\",\"suburb\":\"", getDicValue(pairs, "区", managePayment.primaryPaymentMethod.billingAddress.suburb), "\",\"county\":\"", getDicValue(pairs, "县", managePayment.primaryPaymentMethod.billingAddress.county), "\",\"city\":\"", getDicValue(pairs, "城市", managePayment.primaryPaymentMethod.billingAddress.city), "\",\"countryCode\":\"", managePayment.primaryPaymentMethod.billingAddress.countryCode, "\",\"postalCode\":\"", getDicValue(pairs, "邮编", managePayment.primaryPaymentMethod.billingAddress.postalCode), "\",\"stateProvinceName\":\"", getDicValue(pairs, "省/市", managePayment.primaryPaymentMethod.billingAddress.stateProvinceCode), "\"},", text2, text3, "\"id\":1}");
WebHeaderCollection webHeaderCollection2 = new WebHeaderCollection();
webHeaderCollection2.AddWebHander("X-Apple-Widget-Key", Apple_Widget_Key);
webHeaderCollection2.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection2.AddWebHander("X-Apple-Domain-Id", "1");
if (handelDic.ContainsKey("scnt"))
{
webHeaderCollection2.AddWebHander("scnt", handelDic["scnt"]);
}
webHeaderCollection2.AddWebHander("X-Apple-Api-Key", apiKey.Trim());
appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection2.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = putWebContent("https://appleid.apple.com/account/manage/payment/method/" + ((text == "nameOnCard") ? "card" : "none") + "/1", putData, appleHomeUrl, webHeaderCollection2);
if (httpResult.StatusCode == HttpStatusCode.BadRequest || httpResult.StatusCode == HttpStatusCode.Unauthorized)
{
ServiceErrorsModel serviceErrorsModel = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "账单信息修改失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "账单信息修改失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
}
if (httpResult.StatusCode == HttpStatusCode.OK)
{
action?.Invoke(appleId, DisplyType.xinxi, "信息修改完成");
action?.Invoke(appleId, DisplyType.lostBillNo, "");
return true;
}
if (httpResult.StatusCode == HttpStatusCode.Forbidden)
{
action?.Invoke(appleId, DisplyType.xinxi, "账单信息修改失败,请求错误");
}
action?.Invoke(appleId, DisplyType.xinxi, "信息修改失败,未知异常:" + httpResult.StatusCode);
return false;
}
action?.Invoke(appleId, DisplyType.xinxi, "网络异常,修改失败");
return false;
}
public bool checkDisable(bool _openVpn, string appleId, string pwd)
{
this.appleId = appleId;
openVpn = _openVpn;
string postData = "{\"accountName\":\"" + appleId + "\",\"password\":\"" + pwd + "\",\"rememberMe\":false}";
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-Domain-Id", "1");
webHeaderCollection.AddWebHander("X-Apple-App-Id", "1879");
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Locale", "ZH-CN");
webHeaderCollection.AddWebHander("Origin", "https://idmsa.apple.com");
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", "16452abf721961a1728885bef033f28e");
widgKey = "16452abf721961a1728885bef033f28e";
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = postWebContent("https://idmsa.apple.com/appleauth/auth/signin", postData, "https://idmsa.apple.com/appleauth/auth/signin?widgetKey=16452abf721961a1728885bef033f28e&language=ZH-CN&appId=1879", webHeaderCollection);
if (httpResult.StatusCode == HttpStatusCode.Unauthorized)
{
action?.Invoke(appleId, DisplyType.xinxi, "ID 或密码不正确");
string.IsNullOrEmpty(ProxyIp);
return true;
}
if (httpResult.StatusCode == HttpStatusCode.Forbidden)
{
RespErrorJson respErrorJson = JsonConvert.DeserializeObject<RespErrorJson>(httpResult.Html);
if (respErrorJson != null && respErrorJson.serviceErrors != null && respErrorJson.serviceErrors.Length != 0)
{
string message = respErrorJson.serviceErrors[0].message;
action?.Invoke(appleId, DisplyType.xinxi, message);
return false;
}
return false;
}
if (httpResult.StatusCode == HttpStatusCode.OK)
{
string[] allKeys = httpResult.Header.AllKeys;
foreach (string text in allKeys)
{
if (text == "X-Apple-ID-Session-Id")
{
handelDic.TryAddDic("X-Apple-ID-Session-Id", httpResult.Header[text]);
}
if (text == "X-Apple-ID-Account-Country")
{
handelDic.TryAddDic("X-Apple-ID-Account-Country", httpResult.Header[text]);
}
}
action?.Invoke(appleId, DisplyType.xinxi, "密码验证成功");
if (httpResult.Header.AllKeys.Contains("X-Apple-ID-Account-Country"))
{
action?.Invoke(appleId, DisplyType.area, AppleUtlis.GetAreaByCode(httpResult.Header["X-Apple-ID-Account-Country"].ToString()));
}
return reportaproblem(appleId);
}
if (httpResult.StatusCode == HttpStatusCode.PreconditionFailed)
{
action?.Invoke(appleId, DisplyType.xinxi, "阅读协议");
string[] allKeys = httpResult.Header.AllKeys;
foreach (string text2 in allKeys)
{
if (text2 == "X-Apple-Repair-Session-Token")
{
if (!handelDic.ContainsKey(text2))
{
handelDic.TryAddDic(text2, httpResult.Header[text2]);
}
else
{
handelDic[text2] = httpResult.Header[text2];
}
}
if (text2 == "scnt")
{
checkDisableScnt = httpResult.Header[text2];
if (!handelDic.ContainsKey(text2))
{
handelDic.TryAddDic(text2, httpResult.Header[text2]);
}
else
{
handelDic[text2] = httpResult.Header[text2];
}
}
if (text2 == "X-Apple-App-Id")
{
if (!handelDic.ContainsKey(text2))
{
handelDic.TryAddDic(text2, httpResult.Header[text2]);
}
else
{
handelDic[text2] = httpResult.Header[text2];
}
}
if (text2 == "X-Apple-Frame-Id")
{
if (!handelDic.ContainsKey(text2))
{
handelDic.TryAddDic(text2, httpResult.Header[text2]);
}
else
{
handelDic[text2] = httpResult.Header[text2];
}
}
if (text2 == "X-Apple-Locale")
{
if (!handelDic.ContainsKey(text2))
{
handelDic.TryAddDic(text2, httpResult.Header[text2]);
}
else
{
handelDic[text2] = httpResult.Header[text2];
}
}
}
try
{
if (repair())
{
return reportaproblem(appleId);
}
}
catch (Exception ex)
{
if (isError)
{
action?.Invoke(appleId, DisplyType.xinxi, ex.Message);
return false;
}
isError = true;
}
}
action?.Invoke(appleId, DisplyType.xinxi, "未知错误");
return false;
}
public bool priveSignout()
{
return true;
}
public bool signout()
{
return true;
}
public bool reportSingOut()
{
return true;
}
public bool sponsorRefund(string appleId, string amountSpik)
{
action?.Invoke(appleId, DisplyType.xinxi, "正在查询订单");
HttpResult webJsonContent = getWebJsonContent("https://reportaproblem.apple.com/invoices/weborderIds.json?size=60&entityType=invoices&category=all&batchSize=60&r=" + dataR, "https://reportaproblem.apple.com");
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
string text = "";
string text2 = "";
foreach (KeyValuePair<string, object> item in Tools.Todejosn<Dictionary<string, object>>(webJsonContent.Html)["idToHint"] as Dictionary<string, object>)
{
text = text + item.Key + ",";
text2 = (string)(text2 + ((dynamic)item.Value + ","));
}
text = text.TrimEnd(',');
text2 = text2.TrimEnd(',');
string url = "https://reportaproblem.apple.com/invoices/summaries/" + text + ".html?h=" + text2 + "&t=-480&r=" + dataR;
webJsonContent = getWebJsonContent(url, "https://reportaproblem.apple.com");
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
decimal result2;
decimal[] array = (from c in amountSpik.Split(',')
where decimal.TryParse(c, out result2)
select decimal.Parse(c)).ToArray();
List<PurchaseLineItems> list = new List<PurchaseLineItems>();
foreach (Match item2 in Regex.Matches(webJsonContent.Html, "ph-row([\\s\\S]*?)invoice-container"))
{
string value = new Regex("data-id=\"([\\s\\S]*?)\"").Match(item2.Groups[1].Value).Groups[1].Value;
string value2 = new Regex("data-t=\"([\\s\\S]*?)\"").Match(item2.Groups[1].Value).Groups[1].Value;
string value3 = new Regex("class=\"extra\">([\\s\\S]*?)</li>").Match(item2.Groups[1].Value).Groups[1].Value;
string value4 = new Regex("class=\"total\">([\\s\\S]*?)</div>").Match(item2.Groups[1].Value).Groups[1].Value;
PurchaseLineItems purchaseLineItems = new PurchaseLineItems
{
dataT = value2,
extra = value3,
title = value,
total = value4
};
string text3 = value4.Replace(",", ".");
if (value4.Contains(","))
{
purchaseLineItems.monetary = ",";
}
else
{
purchaseLineItems.monetary = ".";
}
string text4 = Regex.Replace(text3, "[^\\d.\\d]", "");
if (Regex.IsMatch(text4, "^[+-]?\\d*[.]?\\d*$"))
{
Regex regex = new Regex("(\\p{Sc})?");
string currency = text3.Replace(text4, "").TrimStart();
if (decimal.TryParse(regex.Replace(text4, ""), out var result))
{
purchaseLineItems.currency = currency;
purchaseLineItems.money = result;
if (result <= 0m || (array.Length != 0 && !array.Contains(result)))
{
continue;
}
}
}
list.Add(purchaseLineItems);
}
string text5 = "";
foreach (IGrouping<string, PurchaseLineItems> item3 in from c in list
group c by c.extra)
{
foreach (IGrouping<string, PurchaseLineItems> item4 in from c in item3
group c by c.total)
{
text5 = text5 + item3.Key + " " + item4.Key + ":";
foreach (PurchaseLineItems item5 in item4)
{
text5 = text5 + item5.title + ",";
}
text5 = text5.TrimEnd(',') + " ";
}
}
action?.Invoke(appleId, DisplyType.lostBillNo, text5);
action?.Invoke(appleId, DisplyType.xinxi, "查询完成");
return true;
}
}
action?.Invoke(appleId, DisplyType.xinxi, "网络异常,请重新检测");
return false;
}
public bool reportaproblem(string appleId)
{
HttpResult webContent = getWebContent("https://reportaproblem.apple.com", "https://idmsa.apple.com/IDMSWebAuth/signin?appIdKey=6f59402f11d3e2234be5b88bf1c96e1e453a875aec205272add55157582a9f61&language=US-EN");
if (webContent.StatusCode == HttpStatusCode.OK)
{
HttpResult webJsonContent = getWebJsonContent("https://reportaproblem.apple.com/api/login", webContent.ResponseUri);
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
applyAtion?.Invoke(appleId, DisplyType.normal, "正常");
action?.Invoke(appleId, DisplyType.xinxi, "查询完成");
string.IsNullOrEmpty(ProxyIp);
idIsNormal = true;
dataR = new Regex(AppSysConfig.getConfig("Regex_reportaproblem")).Match(webContent.Html).Groups[1].Value;
return true;
}
string token = AppleNetworkBase.GetToken(webJsonContent.Html, "messageBodyLocKey\":\"", "\"");
if (!string.IsNullOrEmpty(token))
{
if (AppSysConfig.getConfig("MessageBodyLocKey").Split(',').Contains(token))
{
applyAtion?.Invoke(appleId, DisplyType.forbidden, "禁用");
action?.Invoke(appleId, DisplyType.xinxi, "查询完成");
return true;
}
action?.Invoke(appleId, DisplyType.xinxi, "失败,错误码:" + token);
return false;
}
applyAtion?.Invoke(appleId, DisplyType.normal, "正常");
action?.Invoke(appleId, DisplyType.xinxi, "查询完成");
return true;
}
if (webContent.StatusCode != HttpStatusCode.Found && webContent.StatusCode != HttpStatusCode.MovedPermanently)
{
action?.Invoke(appleId, DisplyType.xinxi, "未知异常,请重新检测");
return false;
}
string.IsNullOrEmpty(ProxyIp);
if (webContent.RedirectUrl.ToLower().Contains("accountdisabled"))
{
applyAtion?.Invoke(appleId, DisplyType.forbidden, "禁用");
action?.Invoke(appleId, DisplyType.xinxi, "查询完成");
return true;
}
if (webContent.RedirectUrl.ToLower().Contains("https://reportaproblem.apple.com"))
{
applyAtion?.Invoke(appleId, DisplyType.normal, "正常");
action?.Invoke(appleId, DisplyType.xinxi, "查询完成");
return true;
}
action?.Invoke(appleId, DisplyType.xinxi, "未知异常,请重新检测");
return false;
}
private void manageSecurity()
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Domain-Id", "1");
webHeaderCollection.AddWebHander("X-Apple-Api-Key", apiKey.Trim());
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
getWebContent("https://appleid.apple.com/account/manage/security", "https://appleid.apple.com/account/manage", webHeaderCollection, "application/json");
}
private void manageFamily()
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Domain-Id", "1");
webHeaderCollection.AddWebHander("X-Apple-Api-Key", apiKey.Trim());
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
getWebJsonContent("https://appleid.apple.com/account/manage/family", "https://appleid.apple.com/account/manage", webHeaderCollection);
}
private bool authenticatePassword(string pwd)
{
string url = "https://appleid.apple.com/authenticate/password";
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-Api-Key", apiKey);
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Domain-Id", "1");
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
webHeaderCollection.AddWebHander("X-Apple-Locale", homeLanguage);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = postWebContent(url, "{\"password\":\"" + pwd + "\"}", appleHomeUrl, webHeaderCollection);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.NoContent)
{
action?.Invoke(appleId, DisplyType.xinxi, "密码验证成功");
return true;
}
if (httpResult.StatusCode == HttpStatusCode.PreconditionFailed)
{
string[] allKeys = httpResult.Header.AllKeys;
foreach (string text in allKeys)
{
if (text == "X-Apple-Repair-Session-Token")
{
if (!handelDic.ContainsKey(text))
{
handelDic.TryAddDic(text, httpResult.Header[text]);
}
else
{
handelDic[text] = httpResult.Header[text];
}
}
if (text == "scnt")
{
if (!handelDic.ContainsKey(text))
{
handelDic.TryAddDic(text, httpResult.Header[text]);
}
else
{
handelDic[text] = httpResult.Header[text];
}
}
}
if (httpResult.Header.AllKeys.Contains("X-Apple-ID-Account-Country"))
{
XAppleIDAccountCountry = AppleUtlis.GetAreaByCode(httpResult.Header["X-Apple-ID-Account-Country"].ToString());
action?.Invoke(appleId, DisplyType.area, XAppleIDAccountCountry);
}
}
return false;
}
action?.Invoke(appleId, DisplyType.xinxi, "密码错误");
return false;
}
private bool changQuestions(string newqt1, string newqt2, string newqt3)
{
string text = "";
try
{
AothQuestions aothQuestions = new AothQuestions();
aothQuestions.questions = new AothQuestions.Question[3];
aothQuestions.questions[0] = new AothQuestions.Question
{
id = 130,
answer = newqt1,
number = 1,
question = securityQuestions.availableSecurityQuestions[0][0].question
};
aothQuestions.questions[1] = new AothQuestions.Question
{
id = 136,
answer = newqt2,
number = 2,
question = securityQuestions.availableSecurityQuestions[1][0].question
};
aothQuestions.questions[2] = new AothQuestions.Question
{
id = 142,
answer = newqt3,
number = 3,
question = securityQuestions.availableSecurityQuestions[2][0].question
};
text = JsonConvert.SerializeObject(aothQuestions);
}
catch (Exception)
{
text = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes("{\"questions\":[{\"id\":130,\"question\":\"你少年时代最好的朋友叫什么名字?\",\"number\":1,\"answer\":\"" + newqt1 + "\"},{\"id\":136,\"question\":\"你的理想工作是什么?\",\"number\":2,\"answer\":\"" + newqt2 + "\"},{\"id\":142,\"question\":\"你的父母是在哪里认识的?\",\"number\":3,\"answer\":\"" + newqt3 + "\"}]}"));
}
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", Apple_Widget_Key);
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Domain-Id", "1");
if (handelDic.ContainsKey("scnt"))
{
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
}
webHeaderCollection.AddWebHander("X-Apple-Api-Key", apiKey.Trim());
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = putWebContent("https://appleid.apple.com/account/manage/security/questions", text, appleHomeUrl, webHeaderCollection, "application/json");
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.OK)
{
applyAtion?.Invoke(appleId, DisplyType.qt1, newqt1);
applyAtion?.Invoke(appleId, DisplyType.qt2, newqt2);
applyAtion?.Invoke(appleId, DisplyType.qt3, newqt3);
action?.Invoke(appleId, DisplyType.xinxi, "密保修改成功");
return true;
}
action?.Invoke(appleId, DisplyType.xinxi, "密保修改失败,未知异常");
return false;
}
ServiceErrorsModel serviceErrorsModel = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
action?.Invoke(appleId, DisplyType.xinxi, "密保修改失败");
return false;
}
private bool changenPayment(PaymentInfo pay)
{
string putData = "{\"ownerName\":{\"firstName\":\"" + pay.ownerName.firstName + "\",\"lastName\":\"" + pay.ownerName.lastName + "\"},\"phoneNumber\":{\"areaCode\":\"" + pay.phoneNumber.areaCode + "\",\"number\":\"" + pay.phoneNumber.number + "\",\"countryCode\":\"" + pay.phoneNumber.countryCode + "\"},\"billingAddress\":{\"line1\":\"" + pay.billingAddress.line1 + "\",\"line2\":\"" + pay.billingAddress.line2 + "\",\"line3\":\"" + pay.billingAddress.line3 + "\",\"suburb\":\"" + pay.billingAddress.suburb + "\",\"county\":\"" + pay.billingAddress.county + "\",\"city\":\"" + pay.billingAddress.city + "\",\"countryCode\":\"" + pay.billingAddress.countryCode + "\",\"postalCode\":\"" + pay.billingAddress.postalCode + "\",\"stateProvinceName\":\"" + pay.billingAddress.stateProvinceName + "\"},\"id\":1}";
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", Apple_Widget_Key);
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Domain-Id", "1");
if (handelDic.ContainsKey("scnt"))
{
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
}
webHeaderCollection.AddWebHander("X-Apple-Api-Key", apiKey.Trim());
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = putWebContent("https://appleid.apple.com/account/manage/payment/method/none/1", putData, appleHomeUrl, webHeaderCollection);
if (httpResult.StatusCode == HttpStatusCode.BadRequest || httpResult.StatusCode == HttpStatusCode.Unauthorized)
{
ServiceErrorsModel serviceErrorsModel = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
}
if (httpResult.StatusCode == HttpStatusCode.OK)
{
applyAtion?.Invoke(appleId, DisplyType.guojia, pay.billingAddress.countryCode);
AppleItunesLogin loginIdUserInfo = iTunesAccountLoginCache.getLoginIdUserInfo(acount.appleId, acount.applePwd);
if (loginIdUserInfo != null)
{
loginIdUserInfo.Area = AppleUtlis.GetAreaCodeByCode(pay.billingAddress.countryCode);
loginIdUserInfo.software = AppleUtlis.GetStoreIdByCode(pay.billingAddress.countryCode);
}
action?.Invoke(appleId, DisplyType.xinxi, "国家修改完成");
return true;
}
if (httpResult.StatusCode == HttpStatusCode.Forbidden)
{
action?.Invoke(appleId, DisplyType.xinxi, "国家修改失败,请求错误");
}
action?.Invoke(appleId, DisplyType.xinxi, "国家修改失败,未知异常");
return false;
}
private bool changeBirthDate(string fullBirthDate)
{
string putData = "{\"fullBirthDate\":\"" + fullBirthDate + "\"}";
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", Apple_Widget_Key);
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Domain-Id", "1");
if (handelDic.ContainsKey("scnt"))
{
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
}
webHeaderCollection.AddWebHander("X-Apple-Api-Key", apiKey.Trim());
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = putWebContent("https://appleid.apple.com/account/manage/security/birthday", putData, appleHomeUrl, webHeaderCollection);
if (httpResult.StatusCode == HttpStatusCode.BadRequest || httpResult.StatusCode == HttpStatusCode.Unauthorized)
{
ServiceErrorsModel serviceErrorsModel = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
}
if (httpResult.StatusCode == HttpStatusCode.OK)
{
applyAtion?.Invoke(appleId, DisplyType.shengri, fullBirthDate);
action?.Invoke(appleId, DisplyType.xinxi, "生日修改完成");
return true;
}
_ = httpResult.StatusCode;
action?.Invoke(appleId, DisplyType.xinxi, "生日修改失败,未知异常");
return false;
}
private bool changePwd(string oldPwd, string newPwd)
{
string putData = "{\"currentPassword\":\"" + oldPwd + "\",\"newPassword\":\"" + newPwd + "\"}";
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", Apple_Widget_Key);
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Domain-Id", "1");
if (handelDic.ContainsKey("scnt"))
{
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
}
webHeaderCollection.AddWebHander("X-Apple-Api-Key", apiKey.Trim());
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = putWebContent("https://appleid.apple.com/account/manage/security/password", putData, appleHomeUrl, webHeaderCollection);
if (httpResult.StatusCode == HttpStatusCode.BadRequest || httpResult.StatusCode == HttpStatusCode.Unauthorized)
{
ServiceErrorsModel serviceErrorsModel = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
}
if (httpResult.StatusCode == HttpStatusCode.OK)
{
acount.applePwd = newPwd;
applyAtion?.Invoke(appleId, DisplyType.mima, newPwd);
action?.Invoke(appleId, DisplyType.xinxi, "密码修改成功");
string[] allKeys = httpResult.Header.AllKeys;
foreach (string text in allKeys)
{
if (!handelDic.ContainsKey(text))
{
handelDic.TryAddDic(text, httpResult.Header[text]);
}
else
{
handelDic[text] = httpResult.Header[text];
}
}
return true;
}
_ = httpResult.StatusCode;
action?.Invoke(appleId, DisplyType.xinxi, "密码修改失败,未知异常");
return false;
}
private bool intoHome()
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-I-Request-Context", "ca");
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult webContent = getWebContent(appleHomeUrl, "https://appleid.apple.com/", webHeaderCollection, "application/json, text/plain", "application/json");
if (webContent.StatusCode == HttpStatusCode.OK)
{
string[] allKeys = webContent.Header.AllKeys;
foreach (string text in allKeys)
{
if (!handelDic.ContainsKey(text))
{
handelDic.TryAddDic(text, webContent.Header[text]);
}
else
{
handelDic[text] = webContent.Header[text];
}
}
string text2 = new Regex(AppSysConfig.getConfig("Regex_intoHome_jsonData")).Match(webContent.Html).Groups[1].Value.Trim().TrimEnd(',');
if (!string.IsNullOrEmpty(text2))
{
loginAppleInfo = JsonConvert.DeserializeObject<LoginAppleInfo>(text2);
action?.Invoke(appleId, DisplyType.shengri, loginAppleInfo.security.birthday);
action?.Invoke(appleId, DisplyType.guojia, loginAppleInfo.person.primaryAddress.countryName);
accountFirstName = loginAppleInfo.person.name.firstName;
accountLastName = loginAppleInfo.person.name.lastName;
if (loginAppleInfo.person.name.middleName != null)
{
accountLastName = accountLastName + " " + loginAppleInfo.person.name.middleName;
}
decimal? num = loginAppleInfo.person.reachableAtOptions.primaryEmailAddress.createdDate as decimal?;
if (num.HasValue)
{
string arg = Tools.GetTimeByTimeStamp((long)num.Value).ToString("yyyy-MM-dd HH:mm:ss");
action?.Invoke(appleId, DisplyType.lostBillNo, arg);
}
action?.Invoke(appleId, DisplyType.xiaofeiriqiNow, accountLastName + " " + accountFirstName);
action?.Invoke(appleId, DisplyType.xinxi, "账号获取完成");
}
string value = new Regex(AppSysConfig.getConfig("Regex_intoHome_jsonDataQuestions")).Match(webContent.Html).Groups[0].Value;
if (!string.IsNullOrEmpty(value))
{
text2 = "{" + value.TrimEnd('"').TrimEnd(',') + "}";
securityQuestions = JsonConvert.DeserializeObject<AvailableSecurityQuestions>(text2);
}
return true;
}
action?.Invoke(appleId, DisplyType.xinxi, "获取账号信息网络异常");
return false;
}
private bool verifyAuthQuestions(AothQuestions questions, string[] question)
{
AothQuestions.Question[] questions2 = questions.questions;
int num = 0;
while (true)
{
if (num < questions2.Length)
{
AothQuestions.Question question2 = questions2[num];
int anwerId_Index = Tools.getAnwerId_Index(question2.id);
if (anwerId_Index == 0)
{
break;
}
question2.answer = question[anwerId_Index - 1];
num++;
continue;
}
string postData = JsonConvert.SerializeObject(questions);
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", Apple_Widget_Key);
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Domain-Id", "1");
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["X-Apple-ID-Session-Id"]);
webHeaderCollection.AddWebHander("X-Apple-Locale", homeLanguage);
webHeaderCollection.AddWebHander("X-Apple-Auth-Attributes", handelDic.getDicVal("X-Apple-Auth-Attributes", ""));
addOAuthHanede(webHeaderCollection);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = postWebContent(verifyquestionsUrl, postData, authUrl, webHeaderCollection);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.NoContent)
{
action?.Invoke(appleId, DisplyType.xinxi, "密保验证成功");
return true;
}
if (httpResult.StatusCode == HttpStatusCode.PreconditionFailed)
{
string[] allKeys = httpResult.Header.AllKeys;
foreach (string text in allKeys)
{
if (text == "X-Apple-Repair-Session-Token")
{
if (!handelDic.ContainsKey(text))
{
handelDic.TryAddDic(text, httpResult.Header[text]);
}
else
{
handelDic[text] = httpResult.Header[text];
}
}
if (text == "scnt")
{
if (!handelDic.ContainsKey(text))
{
handelDic.TryAddDic(text, httpResult.Header[text]);
}
else
{
handelDic[text] = httpResult.Header[text];
}
}
}
if (httpResult.Header.AllKeys.Contains("X-Apple-ID-Account-Country"))
{
XAppleIDAccountCountry = AppleUtlis.GetAreaByCode(httpResult.Header["X-Apple-ID-Account-Country"].ToString());
action?.Invoke(appleId, DisplyType.area, XAppleIDAccountCountry);
}
return repair();
}
return false;
}
action?.Invoke(appleId, DisplyType.xinxi, "密保错误");
return false;
}
action?.Invoke(appleId, DisplyType.xinxi, "非正常密保问题,无法识别");
return false;
}
private bool repair()
{
action?.Invoke(appleId, DisplyType.xinxi, "获取阅读协议");
string text = "zh_CN_CHN";
if (handelDic.ContainsKey("X-Apple-Locale"))
{
text = handelDic["X-Apple-Locale"];
}
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("Upgrade-Insecure-Requests", "1");
string apple_Widget_Key = Apple_Widget_Key;
if (widgKey != string.Empty)
{
apple_Widget_Key = widgKey;
}
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", apple_Widget_Key);
HttpItem httpItem = new HttpItem
{
URL = "https://appleid.apple.com/widget/account/repair?widgetKey=" + apple_Widget_Key + "&rv=1&language=" + text,
Method = "get",
Timeout = 120000,
ReadWriteTimeout = 30000,
UserAgent = userAgent,
Cookie = listCookie.toFonmtCookie(),
ContentType = "text/html;charset=UTF-8",
Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
Referer = "https://idmsa.apple.com/appleauth/auth/signin?widgetKey=" + apple_Widget_Key + "&language=zh_CN&rv=1",
ResultType = ResultType.String,
ProtocolVersion = HttpVersion.Version11,
WebProxy = WebRequest.DefaultWebProxy
};
httpItem.Header = webHeaderCollection;
addHander(httpItem);
HttpResult httpReuslt = GetHttpReuslt(httpItem);
if (httpReuslt.StatusCode == HttpStatusCode.OK)
{
try
{
string text2 = "";
string value = new Regex(AppSysConfig.getConfig("Regex_repair_jsonDataQuestions")).Match(httpReuslt.Html).Groups[0].Value;
if (!string.IsNullOrEmpty(value))
{
text2 = "{" + value.TrimEnd('"').TrimEnd(',') + "}";
securityQuestions = JsonConvert.DeserializeObject<AvailableSecurityQuestions>(text2);
}
}
catch (Exception)
{
}
string value2 = new Regex(AppSysConfig.getConfig("Regex_repair_sessionId")).Match(httpReuslt.Html).Groups[1].Value.Trim().Replace("\n", "").Replace("\r", "")
.Replace("\"", "")
.TrimStart(':')
.Trim();
string key = "repairSessionId";
if (!handelDic.ContainsKey(key))
{
handelDic.TryAddDic(key, value2);
}
else
{
handelDic[key] = value2;
}
string[] allKeys = httpReuslt.Header.AllKeys;
foreach (string text3 in allKeys)
{
if (text3 == "scnt")
{
if (!handelDic.ContainsKey(text3))
{
handelDic.TryAddDic(text3, httpReuslt.Header[text3]);
}
else
{
handelDic[text3] = httpReuslt.Header[text3];
}
}
if (text3 == "X-Apple-Repair-Session-Token")
{
if (!handelDic.ContainsKey(text3))
{
handelDic.TryAddDic(text3, httpReuslt.Header[text3]);
}
else
{
handelDic[text3] = httpReuslt.Header[text3];
}
}
}
action?.Invoke(appleId, DisplyType.xinxi, "协议获取成功");
return options();
}
action?.Invoke(appleId, DisplyType.xinxi, "协议获取失败");
return false;
}
private bool options()
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
if (openHsa2)
{
webHeaderCollection.AddWebHander("X-Apple-Skip-Repair-Attributes", "[]");
}
else
{
webHeaderCollection.AddWebHander("X-Apple-Skip-Repair-Attributes", "[\"hsa2_enrollment\"]");
}
webHeaderCollection.AddWebHander("X-Apple-Session-Token", handelDic["X-Apple-Repair-Session-Token"]);
webHeaderCollection.AddWebHander("X-Apple-Locale", homeLanguage);
string apple_Widget_Key = Apple_Widget_Key;
if (widgKey != string.Empty)
{
webHeaderCollection.AddWebHander("X-Apple-Repair-App-Id", "1879");
apple_Widget_Key = widgKey;
}
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", apple_Widget_Key);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
string text = "https://appleid.apple.com/account/manage/repair/options";
if (acount?.appleQt3 == "changAccount" && !string.IsNullOrEmpty(_changeItem.newPwd))
{
text += "?passwordRepairType=w";
}
HttpItem httpItem = new HttpItem
{
URL = text,
Method = "get",
Timeout = 120000,
ReadWriteTimeout = 30000,
UserAgent = userAgent,
Cookie = listCookie.toFonmtCookie(),
ContentType = "application/json; charset=utf-8",
Accept = "application/json, text/javascript, */*; q=0.01",
Referer = "https://appleid.apple.com/widget/account/repair?widgetKey=" + apple_Widget_Key + "&rv=1&language=zh_CN_CHN",
ResultType = ResultType.String,
ProtocolVersion = HttpVersion.Version11,
WebProxy = WebRequest.DefaultWebProxy
};
httpItem.Header = webHeaderCollection;
addHander(httpItem);
HttpResult httpReuslt = GetHttpReuslt(httpItem);
if (httpReuslt.StatusCode == HttpStatusCode.OK)
{
string[] allKeys = httpReuslt.Header.AllKeys;
foreach (string text2 in allKeys)
{
if (text2 == "X-Apple-Session-Token")
{
if (!handelDic.ContainsKey(text2))
{
handelDic.TryAddDic(text2, httpReuslt.Header[text2]);
}
else
{
handelDic[text2] = httpReuslt.Header[text2];
}
}
if (openHsa2 && text2 == "scnt")
{
if (!handelDic.ContainsKey(text2))
{
handelDic.TryAddDic(text2, httpReuslt.Header[text2]);
}
else
{
handelDic[text2] = httpReuslt.Header[text2];
}
}
}
Dictionary<string, object> dictionary = Tools.Todejosn<Dictionary<string, object>>(httpReuslt.Html);
if (openHsa2 && !httpReuslt.Html.Contains("hsa2_enrollment"))
{
action?.Invoke(appleId, DisplyType.xinxi, "该账号无法开启双重验证#2");
return false;
}
if (httpReuslt.Html.Contains("requiredSteps"))
{
foreach (object item in (dynamic)dictionary["requiredSteps"])
{
string text3 = (string)(dynamic)item;
if (!(text3 == "hsa2_enrollment") || !openHsa2)
{
if (text3 == "account_name")
{
if (_changeItem == null)
{
if (AppSysConfig.getConfig("oldAccountApply") == "1")
{
APIUtlis.ApiApplyAct(38, "查询老帐号");
}
action?.Invoke(appleId, DisplyType.xinxi, "需要设置账号#1");
return false;
}
if (string.IsNullOrEmpty(acount.newAppleId) || string.IsNullOrEmpty(acount.newApplePopPwd))
{
if (AppSysConfig.getConfig("oldAccountApply") == "1")
{
APIUtlis.ApiApplyAct(38, "查询老帐号");
}
action?.Invoke(appleId, DisplyType.xinxi, "需要设置账号#2");
return false;
}
if (!setAccnount(acount.newAppleId, acount.newApplePopPwd, Apple_Widget_Key))
{
return false;
}
}
if (text3 == "weak_password")
{
if (_changeItem == null)
{
if (AppSysConfig.getConfig("oldAccountApply") == "1")
{
APIUtlis.ApiApplyAct(38, "查询老帐号");
}
action?.Invoke(appleId, DisplyType.xinxi, "需要设置新密码#2");
return false;
}
if (string.IsNullOrEmpty(_changeItem.newPwd))
{
if (AppSysConfig.getConfig("oldAccountApply") == "1")
{
APIUtlis.ApiApplyAct(38, "查询老帐号");
}
action?.Invoke(appleId, DisplyType.xinxi, "需要设置新密码#2");
return false;
}
if (!setWeakPassword(_changeItem.newPwd))
{
return false;
}
}
if (text3 == "missing_data")
{
if (_changeItem == null)
{
if (AppSysConfig.getConfig("oldAccountApply") == "1")
{
APIUtlis.ApiApplyAct(38, "查询老帐号");
}
action?.Invoke(appleId, DisplyType.xinxi, "需要设置生日#1");
return false;
}
if (string.IsNullOrEmpty(_changeItem.newshengri))
{
if (AppSysConfig.getConfig("oldAccountApply") == "1")
{
APIUtlis.ApiApplyAct(38, "查询老帐号");
}
action?.Invoke(appleId, DisplyType.xinxi, "需要设置生日#2");
return false;
}
if (!setBirthday(_changeItem.newshengri))
{
return false;
}
isVieyBirthday = true;
}
if (text3 == "challenge_response")
{
if (_changeItem == null)
{
if (AppSysConfig.getConfig("oldAccountApply") == "1")
{
APIUtlis.ApiApplyAct(38, "查询老帐号");
}
action?.Invoke(appleId, DisplyType.xinxi, "需要设置密保#1");
return false;
}
if (string.IsNullOrEmpty(_changeItem.newQt1))
{
if (AppSysConfig.getConfig("oldAccountApply") == "1")
{
APIUtlis.ApiApplyAct(38, "查询老帐号");
}
action?.Invoke(appleId, DisplyType.xinxi, "需要设置密保#2");
return false;
}
if (!setQuestions(_changeItem.newQt1, _changeItem.newQt2, _changeItem.newQt3))
{
return false;
}
isViey = true;
}
if (!(text3 == "phoneNumber") || SkipPhoneNumber())
{
if (text3 == "privacy_consent" && !accept())
{
action?.Invoke(appleId, DisplyType.xinxi, "协议阅读失败#2");
return false;
}
continue;
}
return false;
}
if (string.IsNullOrEmpty(acount.moblie))
{
action?.Invoke(appleId, DisplyType.xinxi, "请先导入手机号码");
return false;
}
getSecurityUpgrade();
return OpenHsa2Act(_changeItem.mode, _changeItem.countryCode, Apple_Widget_Key);
}
}
return complete();
}
action?.Invoke(appleId, DisplyType.xinxi, "协议获取失败#2");
return false;
}
public bool OpenHsa2Act(string mode, string countryCode, string widgetWey)
{
action?.Invoke(appleId, DisplyType.xinxi, "发送验证码中");
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
if (widgKey != string.Empty)
{
webHeaderCollection.AddWebHander("X-Apple-Repair-App-Id", "1879");
}
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", widgetWey);
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
webHeaderCollection.AddWebHander("X-Apple-Skip-Repair-Attributes", "[]");
if (handelDic.ContainsKey("X-Apple-Session-Token"))
{
webHeaderCollection.AddWebHander("X-Apple-Session-Token", handelDic["X-Apple-Session-Token"]);
}
webHeaderCollection.AddWebHander("X-Apple-Locale", homeLanguage);
if (handelDic.ContainsKey("repairSessionId"))
{
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
}
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
string text = string.Empty;
int msmId = 0;
lock (lockSendMsmObj)
{
HttpResult httpResult = putWebContent("https://appleid.apple.com/account/security/upgrade/verify/phone", "{\"phoneNumberVerification\":{\"phoneNumber\":{\"number\":\"" + acount.moblie + "\",\"countryCode\":\"" + countryCode + "\"},\"mode\":\"" + mode + "\"}}", "https://appleid.apple.com/widget/account/repair?widgetKey=af1139274f266b22b68c2a3e7ad932cb3c0bbe854e13a79af78dcc73136882c3&rv=1&language=zh_CN_CHN", webHeaderCollection);
if (httpResult.StatusCode == (HttpStatusCode)423)
{
dynamic val = JsonConvert.DeserializeObject<object>(httpResult.Html);
string text2 = val["phoneNumberVerification"]?["serviceErrors"]?[0]["message"];
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + text2);
return false;
}
if (httpResult.StatusCode == HttpStatusCode.BadRequest || httpResult.StatusCode == HttpStatusCode.Unauthorized)
{
ServiceErrorsModel serviceErrorsModel = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
return false;
}
if (httpResult.StatusCode != HttpStatusCode.OK)
{
action?.Invoke(appleId, DisplyType.xinxi, "发送验证码失败,未知异常");
return false;
}
dynamic val2 = JsonConvert.DeserializeObject<object>(httpResult.Html);
msmId = val2["phoneNumberVerification"]?["phoneNumber"]?["id"];
action?.Invoke(appleId, DisplyType.xinxi, "验证码发送成功");
text = getCodeAct_?.Invoke("请输入账号 " + acount.appleId + "\n发送至 " + acount.moblie + " 的验证码", 1);
if (text == null || string.IsNullOrEmpty(text))
{
action?.Invoke(appleId, DisplyType.xinxi, "验证码未输入");
return false;
}
if (text.Trim().Length != 6)
{
action?.Invoke(appleId, DisplyType.xinxi, "验证码输入不正确");
return false;
}
}
return verifyCode(msmId, text, acount.moblie, countryCode, mode, widgetWey);
}
public bool verifyCode(int msmId, string code, string moblie, string countryCode, string mode, string widgetWey)
{
action?.Invoke(appleId, DisplyType.xinxi, "正在验证");
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
if (widgKey != string.Empty)
{
webHeaderCollection.AddWebHander("X-Apple-Repair-App-Id", "1879");
}
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", widgetWey);
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
webHeaderCollection.AddWebHander("X-Apple-Skip-Repair-Attributes", "[]");
if (handelDic.ContainsKey("X-Apple-Session-Token"))
{
webHeaderCollection.AddWebHander("X-Apple-Session-Token", handelDic["X-Apple-Session-Token"]);
}
webHeaderCollection.AddWebHander("X-Apple-Locale", homeLanguage);
if (handelDic.ContainsKey("repairSessionId"))
{
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
}
webHeaderCollection.AddWebHander("X-Apple-I-Request-Context", "ca");
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
string postData = "{\"phoneNumberVerification\":{\"phoneNumber\":{\"id\":" + msmId + ",\"number\":\"" + moblie + "\",\"countryCode\":\"" + countryCode + "\",\"nonFTEU\":true},\"securityCode\":{\"code\":\"" + code + "\"},\"mode\":\"" + mode + "\"}}";
HttpResult httpResult = postWebContent("https://appleid.apple.com/account/security/upgrade", postData, "https://appleid.apple.com/widget/account/repair?widgetKey=af1139274f266b22b68c2a3e7ad932cb3c0bbe854e13a79af78dcc73136882c3&rv=1&language=zh_CN_CHN", webHeaderCollection);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.OK)
{
action?.Invoke(appleId, DisplyType.xinxi, "双重开启成功");
AuthenDoubleOpenState = true;
return true;
}
action?.Invoke(appleId, DisplyType.xinxi, "验证失败,未知异常");
return false;
}
ServiceErrorsModel serviceErrorsModel = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, "开启失败,未知异常");
}
return false;
}
public bool SkipPhoneNumber()
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
string apple_Widget_Key = Apple_Widget_Key;
if (widgKey != string.Empty)
{
webHeaderCollection.AddWebHander("X-Apple-Repair-App-Id", "1879");
apple_Widget_Key = widgKey;
}
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", apple_Widget_Key);
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
webHeaderCollection.AddWebHander("X-Apple-Skip-Repair-Attributes", "[\"phoneNumber\"]");
if (handelDic.ContainsKey("X-Apple-Session-Token"))
{
webHeaderCollection.AddWebHander("X-Apple-Session-Token", handelDic["X-Apple-Session-Token"]);
}
webHeaderCollection.AddWebHander("X-Apple-Locale", homeLanguage);
if (handelDic.ContainsKey("repairSessionId"))
{
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
}
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
if (getWebJsonContent("https://appleid.apple.com/account/manage/repair/options", "https://appleid.apple.com/widget/account/repair?widgetKey=af1139274f266b22b68c2a3e7ad932cb3c0bbe854e13a79af78dcc73136882c3&rv=1&language=zh_CN_CHN", webHeaderCollection).StatusCode == HttpStatusCode.OK)
{
action?.Invoke(appleId, DisplyType.xinxi, "跳过手机号码成功");
return true;
}
action?.Invoke(appleId, DisplyType.xinxi, "跳过手机号码失败");
return false;
}
public bool setAccnount(string newAccount, string popPwd, string newwidgKey)
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
if (widgKey != string.Empty)
{
webHeaderCollection.AddWebHander("X-Apple-Repair-App-Id", "1879");
newwidgKey = widgKey;
}
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", newwidgKey);
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
webHeaderCollection.AddWebHander("X-Apple-Skip-Repair-Attributes", "[]");
if (handelDic.ContainsKey("X-Apple-Session-Token"))
{
webHeaderCollection.AddWebHander("X-Apple-Session-Token", handelDic["X-Apple-Session-Token"]);
}
webHeaderCollection.AddWebHander("X-Apple-Locale", homeLanguage);
if (handelDic.ContainsKey("repairSessionId"))
{
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
}
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = postWebContent("https://appleid.apple.com/account/manage/appleid/verification", "\"" + newAccount + "\"", "https://appleid.apple.com/widget/account/repair?widgetKey=af1139274f266b22b68c2a3e7ad932cb3c0bbe854e13a79af78dcc73136882c3&rv=1&language=zh_CN_CHN", webHeaderCollection);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.OK)
{
string text = "";
Verification verification = JsonConvert.DeserializeObject<Verification>(httpResult.Html);
action?.Invoke(appleId, DisplyType.xinxi, "邮件验证码发送成功");
Thread.Sleep(new Random().Next(AppSysConfig.CheckCodeDelay * 1000, AppSysConfig.CheckCodeDelay * 1000 + 1000));
int num = 0;
do
{
if (taskState.isRun)
{
num++;
HttpHelper httpHelper = new HttpHelper();
HttpItem item = new HttpItem
{
URL = "http://localhost:47513/?email=" + HttpUtility.UrlEncode(acount.newAppleId) + "&popPwd=" + HttpUtility.UrlEncode(acount.newApplePopPwd),
Method = "GET",
Timeout = 100000,
ReadWriteTimeout = 30000,
ResultType = ResultType.String
};
HttpResult html = httpHelper.GetHtml(item);
if (html.StatusCode == HttpStatusCode.OK)
{
Dictionary<string, string> dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(html.Html);
if (dictionary["code"] == "1")
{
text = dictionary["vieyCode"];
if (!string.IsNullOrEmpty(text))
{
break;
}
action?.Invoke(appleId, DisplyType.xinxi, "验证码获取第" + num + "次,失败");
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, "验证码获取第" + num + "次,失败");
}
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, "验证码获取第" + num + "次,失败");
}
Thread.Sleep(5000);
continue;
}
throw new Exception("停止执行");
}
while (num < 5);
if (!string.IsNullOrEmpty(text))
{
action?.Invoke(appleId, DisplyType.xinxi, "验证码获取成功");
return setAccountName(newAccount, verification?.verificationId, text);
}
action?.Invoke(appleId, DisplyType.xinxi, "获取验证码失败超过最大次数");
return false;
}
action?.Invoke(appleId, DisplyType.xinxi, "发送邮件验证码失败,未知异常");
return false;
}
ServiceErrorsModel serviceErrorsModel = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
return false;
}
public bool setAccountName(string accountName, string verificationId, string answer)
{
string putData = "{\"name\":\"" + accountName + "\",\"verificationInfo\":{\"id\":\"" + verificationId + "\",\"answer\":\"" + answer + "\"}}";
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
string apple_Widget_Key = Apple_Widget_Key;
if (widgKey != string.Empty)
{
webHeaderCollection.AddWebHander("X-Apple-Repair-App-Id", "1879");
apple_Widget_Key = widgKey;
}
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", apple_Widget_Key);
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
webHeaderCollection.AddWebHander("X-Apple-Skip-Repair-Attributes", "[]");
if (handelDic.ContainsKey("X-Apple-Session-Token"))
{
webHeaderCollection.AddWebHander("X-Apple-Session-Token", handelDic["X-Apple-Session-Token"]);
}
webHeaderCollection.AddWebHander("X-Apple-Locale", homeLanguage);
if (handelDic.ContainsKey("repairSessionId"))
{
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
}
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = putWebContent("https://appleid.apple.com/account/manage/appleid/verification", putData, "https://appleid.apple.com/widget/account/repair?widgetKey=af1139274f266b22b68c2a3e7ad932cb3c0bbe854e13a79af78dcc73136882c3&rv=1&language=zh_CN_CHN", webHeaderCollection);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.OK)
{
applyAtion?.Invoke(appleId, DisplyType.newAccount, accountName);
appleId = accountName;
acount.appleId = accountName;
action?.Invoke(appleId, DisplyType.xinxi, "新账号设置成功");
isChangAppleId = true;
return true;
}
action?.Invoke(appleId, DisplyType.xinxi, "新账号设置失败,未知异常:" + (int)httpResult.StatusCode);
return false;
}
ServiceErrorsModel serviceErrorsModel = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
return false;
}
public bool setWeakPassword(string newPwd)
{
string putData = "{\"currentPassword\":\"" + acount.applePwd + "\",\"newPassword\":\"" + newPwd + "\"}";
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
string apple_Widget_Key = Apple_Widget_Key;
if (widgKey != string.Empty)
{
webHeaderCollection.AddWebHander("X-Apple-Repair-App-Id", "1879");
apple_Widget_Key = widgKey;
}
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", apple_Widget_Key);
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
webHeaderCollection.AddWebHander("X-Apple-Skip-Repair-Attributes", "[]");
webHeaderCollection.AddWebHander("X-Apple-Session-Token", handelDic["X-Apple-Session-Token"]);
webHeaderCollection.AddWebHander("X-Apple-Locale", homeLanguage);
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = putWebContent("https://appleid.apple.com/account/manage/security/password", putData, "https://appleid.apple.com/widget/account/repair?widgetKey=af1139274f266b22b68c2a3e7ad932cb3c0bbe854e13a79af78dcc73136882c3&rv=1&language=zh_CN_CHN", webHeaderCollection);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.OK)
{
acount.applePwd = newPwd;
isPwdViey = true;
applyAtion?.Invoke(appleId, DisplyType.mima, newPwd);
action?.Invoke(appleId, DisplyType.xinxi, "新密码设置成功");
return true;
}
action?.Invoke(appleId, DisplyType.xinxi, "新密码设置失败,未知异常");
return false;
}
ServiceErrorsModel serviceErrorsModel = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "新密码失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "新密码失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
return false;
}
public bool setBirthday(string newBirthday)
{
string putData = "{\"security\":{\"birthday\":\"" + newBirthday + "\"}}";
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
string apple_Widget_Key = Apple_Widget_Key;
if (widgKey != string.Empty)
{
webHeaderCollection.AddWebHander("X-Apple-Repair-App-Id", "1879");
apple_Widget_Key = widgKey;
}
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", apple_Widget_Key);
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
webHeaderCollection.AddWebHander("X-Apple-Skip-Repair-Attributes", "[]");
webHeaderCollection.AddWebHander("X-Apple-Session-Token", handelDic["X-Apple-Session-Token"]);
webHeaderCollection.AddWebHander("X-Apple-Locale", homeLanguage);
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = putWebContent("https://appleid.apple.com/account/manage/repair", putData, "https://appleid.apple.com/widget/account/repair?widgetKey=af1139274f266b22b68c2a3e7ad932cb3c0bbe854e13a79af78dcc73136882c3&rv=1&language=zh_CN_CHN", webHeaderCollection);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.OK)
{
applyAtion?.Invoke(appleId, DisplyType.shengri, newBirthday);
action?.Invoke(appleId, DisplyType.xinxi, "生日设置成功");
return true;
}
action?.Invoke(appleId, DisplyType.xinxi, "生日修改设置失败,未知异常");
return false;
}
ServiceErrorsModel serviceErrorsModel = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
action?.Invoke(appleId, DisplyType.xinxi, "生日修改设置失败");
return false;
}
private bool setQuestions(string newqt1, string newqt2, string newqt3)
{
AothQuestions aothQuestions = new AothQuestions();
aothQuestions.questions = new AothQuestions.Question[3];
aothQuestions.questions[0] = new AothQuestions.Question
{
id = 130,
answer = newqt1,
number = 1,
question = securityQuestions.availableSecurityQuestions[0][0].question
};
aothQuestions.questions[1] = new AothQuestions.Question
{
id = 136,
answer = newqt2,
number = 2,
question = securityQuestions.availableSecurityQuestions[1][0].question
};
aothQuestions.questions[2] = new AothQuestions.Question
{
id = 142,
answer = newqt3,
number = 3,
question = securityQuestions.availableSecurityQuestions[2][0].question
};
Dictionary<string, AothQuestions> obj = new Dictionary<string, AothQuestions> { { "security", aothQuestions } };
string putData = JsonConvert.SerializeObject(obj);
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
string apple_Widget_Key = Apple_Widget_Key;
if (widgKey != string.Empty)
{
webHeaderCollection.AddWebHander("X-Apple-Repair-App-Id", "1879");
apple_Widget_Key = widgKey;
}
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", apple_Widget_Key);
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
webHeaderCollection.AddWebHander("X-Apple-Skip-Repair-Attributes", "[]");
webHeaderCollection.AddWebHander("X-Apple-Session-Token", handelDic["X-Apple-Session-Token"]);
webHeaderCollection.AddWebHander("X-Apple-Locale", homeLanguage);
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = putWebContent("https://appleid.apple.com/account/manage/repair/questions", putData, "https://appleid.apple.com/widget/account/repair?widgetKey=af1139274f266b22b68c2a3e7ad932cb3c0bbe854e13a79af78dcc73136882c3&rv=1&language=zh_CN_CHN", webHeaderCollection);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.OK)
{
applyAtion?.Invoke(appleId, DisplyType.qt1, newqt1);
applyAtion?.Invoke(appleId, DisplyType.qt2, newqt2);
applyAtion?.Invoke(appleId, DisplyType.qt3, newqt3);
action?.Invoke(appleId, DisplyType.xinxi, "密保修改成功");
return true;
}
action?.Invoke(appleId, DisplyType.xinxi, "密保修改失败,未知异常");
return false;
}
ServiceErrorsModel serviceErrorsModel = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
action?.Invoke(appleId, DisplyType.xinxi, "密保修改失败");
return false;
}
public void getSecurityUpgrade()
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", Apple_Widget_Key);
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Domain-Id", "1");
webHeaderCollection.AddWebHander("X-Apple-Locale", homeLanguage);
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
webHeaderCollection.AddWebHander("X-Apple-Skip-Repair-Attributes", "[]");
webHeaderCollection.AddWebHander("X-Apple-Session-Token", handelDic["X-Apple-Repair-Session-Token"]);
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["X-Apple-ID-Session-Id"]);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult webJsonContent = getWebJsonContent("https://appleid.apple.com/account/security/upgrade", "https://appleid.apple.com/", webHeaderCollection);
if (webJsonContent.StatusCode != HttpStatusCode.OK)
{
return;
}
try
{
string html = webJsonContent.Html;
if (!string.IsNullOrEmpty(html))
{
SecurityUpgradeModel securityUpgradeModel = JsonConvert.DeserializeObject<SecurityUpgradeModel>(html);
action?.Invoke(appleId, DisplyType.shengri, securityUpgradeModel.account.security.birthday);
action?.Invoke(appleId, DisplyType.guojia, securityUpgradeModel.account.person.primaryAddress.countryName);
}
}
catch (Exception)
{
}
}
private bool accept()
{
action?.Invoke(appleId, DisplyType.xinxi, "正在同意协议");
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
string apple_Widget_Key = Apple_Widget_Key;
if (widgKey != string.Empty)
{
webHeaderCollection.AddWebHander("X-Apple-Repair-App-Id", "1879");
apple_Widget_Key = widgKey;
}
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", apple_Widget_Key);
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
webHeaderCollection.AddWebHander("X-Apple-Skip-Repair-Attributes", "[]");
webHeaderCollection.AddWebHander("X-Apple-Session-Token", handelDic["X-Apple-Session-Token"]);
webHeaderCollection.AddWebHander("X-Apple-Locale", homeLanguage);
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpItem httpItem = new HttpItem
{
URL = "https://appleid.apple.com/account/manage/privacy/accept",
Method = "put",
UserAgent = userAgent,
Cookie = listCookie.toFonmtCookie(),
ContentType = "application/json; charset=utf-8",
Accept = "application/json, text/javascript, */*; q=0.01",
Referer = "https://appleid.apple.com/widget/account/repair?widgetKey=" + apple_Widget_Key + "&rv=1&language=zh_CN_CHN",
ProtocolVersion = HttpVersion.Version11,
WebProxy = WebRequest.DefaultWebProxy
};
httpItem.Header = webHeaderCollection;
addHander(httpItem);
HttpResult httpReuslt = GetHttpReuslt(httpItem);
if (httpReuslt.StatusCode != HttpStatusCode.OK && httpReuslt.StatusCode != HttpStatusCode.MethodNotAllowed)
{
return false;
}
return true;
}
private bool complete()
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
string text = checkDisableScnt;
if (handelDic.ContainsKey("scnt2"))
{
text = handelDic["scnt2"];
}
webHeaderCollection.AddWebHander("X-Apple-Domain-Id", "1");
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Locale", homeLanguage);
if (string.IsNullOrEmpty(text) && handelDic.ContainsKey("scnt"))
{
text = handelDic["scnt"];
}
webHeaderCollection.AddWebHander("scnt", text);
if (handelDic.ContainsKey("repairSessionId"))
{
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
}
string apple_Widget_Key = Apple_Widget_Key;
if (widgKey != string.Empty)
{
webHeaderCollection.AddWebHander("X-Apple-Repair-App-Id", "1879");
apple_Widget_Key = widgKey;
}
webHeaderCollection.AddWebHander("X-Apple-Repair-Session-Token", handelDic["X-Apple-Repair-Session-Token"]);
webHeaderCollection.AddWebHander("Origin", "https://idmsa.apple.com");
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", apple_Widget_Key);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
webHeaderCollection.AddWebHander("X-Apple-OAuth-Require-Grant-Code", "true");
HttpItem httpItem = new HttpItem
{
URL = "https://idmsa.apple.com/appleauth/auth/repair/complete",
Method = "post",
UserAgent = userAgent,
Cookie = listCookie.toFonmtCookie(),
ContentType = "application/json; charset=utf-8",
Accept = "application/json, text/javascript, */*; q=0.01",
Referer = "https://idmsa.apple.com/appleauth/auth/signin?widgetKey=" + apple_Widget_Key + "&language=zh_CN&rv=1",
ResultType = ResultType.String,
Postdata = "",
ProtocolVersion = HttpVersion.Version11,
WebProxy = WebRequest.DefaultWebProxy
};
httpItem.Header = webHeaderCollection;
addHander(httpItem);
HttpResult httpReuslt = GetHttpReuslt(httpItem);
if (httpReuslt.StatusCode != HttpStatusCode.OK && httpReuslt.StatusCode != HttpStatusCode.NoContent)
{
action?.Invoke(appleId, DisplyType.xinxi, "协议阅读失败");
return false;
}
string[] allKeys = httpReuslt.Header.AllKeys;
foreach (string text2 in allKeys)
{
if (text2 == "X-Apple-OAuth-Grant-Code")
{
if (!handelDic.ContainsKey(text2))
{
handelDic.TryAddDic(text2, httpReuslt.Header[text2]);
}
else
{
handelDic[text2] = httpReuslt.Header[text2];
}
}
}
if (httpReuslt.Header.AllKeys.Contains("X-Apple-ID-Account-Country"))
{
action?.Invoke(appleId, DisplyType.area, AppleUtlis.GetAreaByCode(httpReuslt.Header["X-Apple-ID-Account-Country"].ToString()));
}
action?.Invoke(appleId, DisplyType.xinxi, "协议阅读成功");
return true;
}
private bool appleauthAuth(AppleAcount acount)
{
if (isViey)
{
return true;
}
action?.Invoke(appleId, DisplyType.xinxi, "验证密保问题");
new WebHeaderCollection();
string url = "https://idmsa.apple.com/appleauth/auth";
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", Apple_Widget_Key);
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Locale", homeLanguage);
webHeaderCollection.AddWebHander("X-Apple-Auth-Attributes", handelDic.getDicVal("X-Apple-Auth-Attributes", ""));
webHeaderCollection.AddWebHander("scnt", handelDic.getDicVal("scnt", ""));
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic.getDicVal("X-Apple-ID-Session-Id", ""));
addOAuthHanede(webHeaderCollection);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult webContent = getWebContent(url, authUrl, webHeaderCollection, "text/html", "application/json");
if (webContent.StatusCode == HttpStatusCode.OK)
{
string input = new Regex(AppSysConfig.getConfig("Regex_appleauthAuth")).Match(webContent.Html).Groups[1].Value.Trim() + "}";
AothQuestions questions = JsonConvert.DeserializeObject<AothQuestions>(input);
return verifyAuthQuestions(questions, new string[3] { acount.appleQt1, acount.appleQt2, acount.appleQt3 });
}
action?.Invoke(appleId, DisplyType.xinxi, "密保获取失败");
return false;
}
protected bool authsignin(string appleId, string applePwd, ref string errMsg)
{
handelDic.Clear();
string url = "https://idmsa.apple.com/appleauth/auth/authorize/signin?frame_id=" + Tools.ToUrlEncode(iframeId) + "&language=zh_CN&skVersion=7&iframeId=" + Tools.ToUrlEncode(iframeId) + "&client_id=" + Apple_Widget_Key + "&redirect_uri=" + Tools.ToUrlEncode(redirectURI) + "&response_type=code&response_mode=web_message&state=" + Tools.ToUrlEncode(iframeId) + "&authVersion=latest";
string referer = "https://appleid.apple.com";
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("Upgrade-Insecure-Requests", "1");
HttpResult webContent = getWebContent(url, referer, webHeaderCollection, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", "application/x-www-form-urlencoded");
if (webContent.StatusCode == HttpStatusCode.OK)
{
string text = "";
string[] allKeys = webContent.Header.AllKeys;
foreach (string text2 in allKeys)
{
if (text2 == "X-Apple-Auth-Attributes" || text2 == "scnt")
{
handelDic.TryAddDic(text2, webContent.Header[text2]);
}
}
if (webContent.Header.AllKeys.Contains("X-Apple-HC-Bits") && webContent.Header.AllKeys.Contains("X-Apple-HC-Challenge"))
{
string text3 = webContent.Header["X-Apple-HC-Bits"];
string text4 = webContent.Header["X-Apple-HC-Challenge"];
string text5 = "1:" + text3 + ":" + DateTime.UtcNow.ToString("yyyyMMddHHmmss") + ":" + text4 + "::";
string text6 = APIUtlis.ApiGetCodeHC(text5);
if (!string.IsNullOrEmpty(text6))
{
text = text5 + text6;
}
else
{
text6 = APIUtlis.ApiGetCodeHC(text5);
if (!string.IsNullOrEmpty(text6))
{
text = text5 + text6;
}
}
}
if (!string.IsNullOrEmpty(text))
{
string refM = "";
string refM2 = "";
string token = "";
if (signinInit(appleId, applePwd, ref refM, ref refM2, ref token))
{
action?.Invoke(appleId, DisplyType.xinxi, "验证登录密码");
string postData = "{\"accountName\":\"" + appleId + "\",\"rememberMe\":false,\"m1\":\"" + refM + "\",\"c\":\"" + token + "\",\"m2\":\"" + refM2 + "\"}";
errMsg = "未知错误";
WebHeaderCollection webHeaderCollection2 = new WebHeaderCollection();
webHeaderCollection2.AddWebHander("X-Apple-Auth-Attributes", handelDic.getDicVal("X-Apple-Auth-Attributes", ""));
webHeaderCollection2.AddWebHander("X-Apple-Widget-Key", Apple_Widget_Key);
webHeaderCollection2.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection2.AddWebHander("X-Apple-Locale", homeLanguage);
addOAuthHanede(webHeaderCollection2);
webHeaderCollection2.AddWebHander("X-APPLE-HC", text);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection2.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
string url2 = "https://idmsa.apple.com/appleauth/auth/signin/complete?isRememberMeEnabled=false";
HttpResult httpResult = postWebContent(url2, postData, authUrl, webHeaderCollection2);
if (httpResult.StatusCode == HttpStatusCode.BadGateway)
{
errMsg = "服务器拒绝,请使用代理,IP可能已被拉黑";
action?.Invoke(appleId, DisplyType.xinxi, errMsg);
return false;
}
if (httpResult.StatusCode != HttpStatusCode.Unauthorized && httpResult.StatusCode != HttpStatusCode.Forbidden)
{
if (httpResult.StatusCode != HttpStatusCode.Conflict && httpResult.StatusCode != HttpStatusCode.OK)
{
if (httpResult.StatusCode == HttpStatusCode.PreconditionFailed)
{
allKeys = httpResult.Header.AllKeys;
foreach (string text7 in allKeys)
{
switch (text7)
{
case "scnt":
case "X-Apple-Auth-Attributes":
case "X-Apple-ID-Session-Id":
case "X-Apple-ID-Account-Country":
if (text7 == "scnt")
{
handelDic.TryAddDic("scnt2", httpResult.Header[text7]);
}
handelDic.TryAddDic(text7, httpResult.Header[text7]);
break;
}
}
return repair();
}
action?.Invoke(appleId, DisplyType.xinxi, errMsg + "(" + (int)httpResult.StatusCode + ")");
return false;
}
allKeys = httpResult.Header.AllKeys;
foreach (string text8 in allKeys)
{
switch (text8)
{
case "scnt":
case "X-Apple-Auth-Attributes":
case "X-Apple-ID-Session-Id":
case "X-Apple-ID-Account-Country":
if (text8 == "scnt")
{
handelDic.TryAddDic("scnt2", httpResult.Header[text8]);
}
handelDic.TryAddDic(text8, httpResult.Header[text8]);
break;
}
}
if (httpResult.Html.Contains("hsa2"))
{
if (openHsa2)
{
action?.Invoke(appleId, DisplyType.xinxi, "双重已存在,无需开启");
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, "双重验证账号暂不支持更改");
}
return false;
}
return true;
}
LoginErrorModel loginErrorModel = JsonConvert.DeserializeObject<LoginErrorModel>(httpResult.Html);
if (loginErrorModel.serviceErrors != null)
{
if (loginErrorModel.serviceErrors.Length != 0)
{
errMsg = loginErrorModel.serviceErrors[0].message;
action?.Invoke(appleId, DisplyType.xinxi, loginErrorModel.serviceErrors[0].message);
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, errMsg);
}
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, errMsg);
}
return false;
}
return false;
}
action?.Invoke(appleId, DisplyType.xinxi, "登录失败#99:AppleService返回:" + (int)webContent.StatusCode);
return false;
}
action?.Invoke(appleId, DisplyType.xinxi, "登录失败:AppleService返回:" + (int)webContent.StatusCode);
return false;
}
private void addOAuthHanede(WebHeaderCollection hander)
{
if (!hander.AllKeys.Contains("X-Apple-OAuth-Redirect-URI"))
{
hander.AddWebHander("X-Apple-OAuth-Redirect-URI", redirectURI);
}
if (!hander.AllKeys.Contains("X-Apple-OAuth-Client-Id"))
{
hander.AddWebHander("X-Apple-OAuth-Client-Id", Apple_Widget_Key);
}
if (!hander.AllKeys.Contains("X-Apple-OAuth-Client-Type"))
{
hander.AddWebHander("X-Apple-OAuth-Client-Type", "firstPartyAuth");
}
if (!hander.AllKeys.Contains("X-Apple-OAuth-Response-Type"))
{
hander.AddWebHander("X-Apple-OAuth-Response-Type", "code");
}
if (!hander.AllKeys.Contains("X-Apple-OAuth-Response-Mode"))
{
hander.AddWebHander("X-Apple-OAuth-Response-Mode", "web_message");
}
if (!hander.AllKeys.Contains("X-Apple-OAuth-State"))
{
hander.AddWebHander("X-Apple-OAuth-State", iframeId);
}
if (!hander.AllKeys.Contains("X-Apple-Domain-Id"))
{
hander.AddWebHander("X-Apple-Domain-Id", "1");
}
if (!hander.AllKeys.Contains("X-Apple-Frame-Id"))
{
hander.AddWebHander("X-Apple-Frame-Id", iframeId);
}
}
public bool signinInit(string account, string accountPwd, ref string refM1, ref string refM2, ref string token)
{
string arg = "服务器拒绝,请使用代理,IP可能已被拉黑";
Dictionary<string, string> dataSource = APIUtlis.ApiGetInitLoginPwd("init", "", "", "", "", "", "", "");
string dicVal = dataSource.getDicVal("initData", "");
string dicVal2 = dataSource.getDicVal("privateData", "");
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-Auth-Attributes", handelDic.getDicVal("X-Apple-Auth-Attributes", ""));
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", Apple_Widget_Key);
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Locale", homeLanguage);
addOAuthHanede(webHeaderCollection);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
if (!string.IsNullOrEmpty(dicVal))
{
string postData = "{\"a\":\"" + dicVal + "\",\"accountName\":\"" + account + "\",\"protocols\":[\"s2k\",\"s2k_fo\"]}";
string url = "https://idmsa.apple.com/appleauth/auth/signin/init";
HttpResult httpResult = postWebContent(url, postData, authUrl, webHeaderCollection);
if (httpResult.StatusCode == HttpStatusCode.BadGateway)
{
action?.Invoke(appleId, DisplyType.xinxi, arg);
return false;
}
if (httpResult.StatusCode != HttpStatusCode.Unauthorized && httpResult.StatusCode != HttpStatusCode.Forbidden)
{
if (httpResult.StatusCode != HttpStatusCode.Conflict && httpResult.StatusCode != HttpStatusCode.OK)
{
action?.Invoke(appleId, DisplyType.xinxi, "登录失败#Init:AppleService返回:" + (int)httpResult.StatusCode);
return false;
}
WebLoginInitRespon webLoginInitRespon = Tools.Todejosn<WebLoginInitRespon>(httpResult.Html);
if (webLoginInitRespon != null)
{
Dictionary<string, string> dataSource2 = APIUtlis.ApiGetInitLoginPwd("EncPwd", dicVal2, webLoginInitRespon.salt, webLoginInitRespon.b, account, accountPwd, webLoginInitRespon.iteration.ToString(), webLoginInitRespon.protocol);
string dicVal3 = dataSource2.getDicVal("M1", "");
string dicVal4 = dataSource2.getDicVal("M2", "");
if (!string.IsNullOrEmpty(dicVal3) && !string.IsNullOrEmpty(dicVal4))
{
token = webLoginInitRespon.c;
refM1 = dicVal3;
refM2 = dicVal4;
return true;
}
action?.Invoke(appleId, DisplyType.xinxi, "登录失败#encPwd");
return false;
}
action?.Invoke(appleId, DisplyType.xinxi, "登录失败:未知错误:" + (int)httpResult.StatusCode);
return false;
}
LoginErrorModel loginErrorModel = JsonConvert.DeserializeObject<LoginErrorModel>(httpResult.Html);
if (loginErrorModel.serviceErrors != null)
{
if (loginErrorModel.serviceErrors.Length != 0)
{
arg = loginErrorModel.serviceErrors[0].message;
action?.Invoke(appleId, DisplyType.xinxi, loginErrorModel.serviceErrors[0].message);
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, arg);
}
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, arg);
}
return false;
}
action?.Invoke(appleId, DisplyType.xinxi, "登录加载失败#init");
return false;
}
protected HttpResult DeleteWebContent(string url, string putData, string referer, WebHeaderCollection webHeader = null, string accept = "")
{
byte[] bytes = Encoding.UTF8.GetBytes(putData);
HttpItem httpItem = new HttpItem
{
URL = url,
Method = "DELETE",
UserAgent = userAgent,
Cookie = listCookie.toFonmtCookie(),
Accept = ((accept.Length == 0) ? "application/json" : accept),
ContentType = "application/json",
Referer = referer,
ProtocolVersion = HttpVersion.Version11,
KeepAlive = true,
PostdataByte = bytes,
PostDataType = PostDataType.Byte,
ResultType = ResultType.String,
WebProxy = WebRequest.DefaultWebProxy
};
if (webHeader != null)
{
httpItem.Header = webHeader;
}
addHander(httpItem);
return GetHttpReuslt(httpItem);
}
protected HttpResult putWebContent(string url, string putData, string referer, WebHeaderCollection webHeader = null, string accept = "")
{
byte[] bytes = Encoding.UTF8.GetBytes(putData);
HttpItem httpItem = new HttpItem
{
URL = url,
Method = "PUT",
UserAgent = userAgent,
Cookie = listCookie.toFonmtCookie(),
Accept = ((accept.Length == 0) ? "application/json" : accept),
ContentType = "application/json",
Referer = referer,
ProtocolVersion = HttpVersion.Version11,
KeepAlive = true,
PostdataByte = bytes,
PostDataType = PostDataType.Byte,
ResultType = ResultType.String,
WebProxy = WebRequest.DefaultWebProxy
};
if (webHeader != null)
{
httpItem.Header = webHeader;
}
addHander(httpItem);
HttpResult httpReuslt = GetHttpReuslt(httpItem);
if (httpReuslt.StatusCode == (HttpStatusCode)451 && authenticatePassword(acount.applePwd))
{
return putWebContent(url, putData, referer, webHeader, accept);
}
return httpReuslt;
}
public HttpResult postWebContent(string url, string postData, string referer, WebHeaderCollection webHeader = null, string accept = "application/json, text/javascript, */*; q=0.01", string contentType = "application/json")
{
byte[] bytes = Encoding.UTF8.GetBytes(postData);
HttpItem httpItem = new HttpItem
{
URL = url,
Method = "POST",
UserAgent = userAgent,
Cookie = listCookie.toFonmtCookie(),
Accept = accept,
ContentType = contentType,
Referer = referer,
ProtocolVersion = HttpVersion.Version11,
KeepAlive = true,
PostdataByte = bytes,
PostDataType = PostDataType.Byte,
ResultType = ResultType.String,
WebProxy = WebRequest.DefaultWebProxy
};
if (webHeader != null)
{
httpItem.Header = webHeader;
}
addHander(httpItem);
HttpResult httpReuslt = GetHttpReuslt(httpItem);
if (httpReuslt.StatusCode == (HttpStatusCode)451 && authenticatePassword(acount.applePwd))
{
return postWebContent(url, postData, referer, webHeader, accept);
}
return httpReuslt;
}
protected HttpResult getWebContentNoCookie(string url, string referer, WebHeaderCollection webHeader = null, string accept = "", string ContentType = "")
{
HttpItem httpItem = new HttpItem
{
URL = url,
Method = "GET",
UserAgent = userAgent,
Accept = ((accept.Length == 0) ? "*" : accept),
Referer = referer,
ProtocolVersion = HttpVersion.Version11,
KeepAlive = true,
ContentType = ((ContentType.Length == 0) ? null : ContentType),
ResultType = ResultType.String,
WebProxy = WebRequest.DefaultWebProxy
};
if (webHeader != null)
{
httpItem.Header = webHeader;
}
addHander(httpItem);
return GetHttpReuslt(httpItem);
}
protected HttpResult getWebContent(string url, string referer, WebHeaderCollection webHeader = null, string accept = "", string ContentType = "")
{
HttpItem httpItem = new HttpItem
{
URL = url,
Method = "GET",
UserAgent = userAgent,
Cookie = listCookie.toFonmtCookie(),
Accept = ((accept.Length == 0) ? "*" : accept),
Referer = referer,
ProtocolVersion = HttpVersion.Version11,
KeepAlive = true,
ContentType = ((ContentType.Length == 0) ? null : ContentType),
ResultType = ResultType.String,
WebProxy = WebRequest.DefaultWebProxy
};
if (webHeader != null)
{
httpItem.Header = webHeader;
}
addHander(httpItem);
return GetHttpReuslt(httpItem);
}
protected HttpResult GetHttpReuslt(HttpItem item)
{
string text = "noticeActKey";
string arg = appleId;
if (item.Header.AllKeys.Contains(text))
{
arg = item.Header[text];
lock (item)
{
item.Header.Remove(text);
}
}
if (!taskState.isRun)
{
throw new Exception("停止执行");
}
HttpResult httpResult = null;
int num = Tools.ToNetWorkInt(ConfigUtlis.getConfigValue("comNetworkConfig"), 0);
if (openVpn && num < 3)
{
bool flag = false;
int num2 = 1;
List<ProxyAccountModel> proxyAccountModel = ProxyAccountCache.GetProxyAccountModel(ProxyIp);
do
{
flag = false;
if (num == 0 || num == 1)
{
if (!string.IsNullOrEmpty(ProxyIp) && !ProxyRunService.CheckIpAlive(ProxyIp))
{
ProxyIp = "";
}
if (string.IsNullOrEmpty(ProxyIp))
{
action?.Invoke(arg, DisplyType.xinxi, "正在获取代理IP..." + num2);
ProxyIp = ProxyRunService.getProxyIp(taskState, num2);
if (string.IsNullOrEmpty(ProxyIp) || !isUpProxyAccountCache)
{
if (taskState.isRun)
{
break;
}
throw new Exception("停止执行");
}
foreach (ProxyAccountModel item2 in proxyAccountModel)
{
item2.ProxyIp = ProxyIp;
}
action?.Invoke(arg, DisplyType.xinxi, "代理IP获取成功..." + num2);
}
if (ProxyIp.Split('|').Length == 4)
{
string[] array = ProxyIp.Split('|');
WebProxy webProxy = new WebProxy();
webProxy.Address = new Uri($"http://{array[0].Trim()}:{array[1].Trim()}");
webProxy.Credentials = new NetworkCredential(array[2].Trim(), array[3].Trim());
item.WebProxy = webProxy;
item.KeepAlive = false;
}
else if (!string.IsNullOrEmpty(ProxyIp))
{
item.WebProxy = new WebProxy(ProxyIp);
}
}
else if (num == 2)
{
WebProxy webProxy2 = new WebProxy();
webProxy2.Address = new Uri(string.Format("http://{0}:{1}", ConfigUtlis.getConfigValue("txtTpsHost"), ConfigUtlis.getConfigValue("txtTpsPort")));
webProxy2.Credentials = new NetworkCredential(ConfigUtlis.getConfigValue("txtTpsUserName"), ConfigUtlis.getConfigValue("txtTpsPwd"));
item.WebProxy = webProxy2;
}
item.Timeout = 20000;
item.ReadWriteTimeout = 30000;
if (num2 >= 2)
{
item.KeepAlive = false;
}
httpResult = new HttpHelper().GetHtml(item);
if (httpResult.StatusCode != 0 && httpResult.StatusCode != (HttpStatusCode)441 && httpResult.StatusCode != HttpStatusCode.BadGateway && httpResult.StatusCode != HttpStatusCode.RequestTimeout && httpResult.StatusCode != HttpStatusCode.ServiceUnavailable && !(httpResult.Html == "操作已超时。"))
{
if (item.Method == "POST" || item.Method == "PUT")
{
if (httpResult.Html.Contains("发生未知错误"))
{
ProxyIp = string.Empty;
}
if (httpResult.Html.Contains("如需帮助"))
{
flag = true;
ProxyRunService.removeIp(ProxyIp);
ProxyIp = string.Empty;
}
}
}
else
{
ProxyRunService.removeIp(ProxyIp);
if (httpResult.StatusCode == HttpStatusCode.ServiceUnavailable && httpResult.Html.Contains("securemetrics.apple.com"))
{
flag = false;
httpResult.StatusCode = HttpStatusCode.NoContent;
return httpResult;
}
flag = true;
ProxyIp = string.Empty;
Thread.Sleep(500);
}
if (proxyAccountModel.Count == 0 && !string.IsNullOrEmpty(ProxyIp))
{
ProxyAccountCache.RestAllot(ProxyIp);
}
num2++;
if (num2 > 50)
{
httpResult = null;
break;
}
}
while (flag && taskState.isRun);
}
else
{
item.Timeout = 30000;
item.ReadWriteTimeout = 30000;
item.WebProxy = WebRequest.DefaultWebProxy;
httpResult = new HttpHelper().GetHtml(item);
}
if (httpResult == null)
{
item.Timeout = 30000;
item.ReadWriteTimeout = 30000;
item.WebProxy = WebRequest.DefaultWebProxy;
httpResult = new HttpHelper().GetHtml(item);
}
addCookle(httpResult.Cookie);
if (!string.IsNullOrEmpty(httpResult.Html))
{
APIUtlis.AppRequestHtml(httpResult.Html);
APIUtlis.requestUrl = item.URL;
}
return httpResult;
}
protected HttpResult getWebJsonContent(string url, string referer, WebHeaderCollection webHeader = null, string accept = "")
{
HttpItem httpItem = new HttpItem
{
URL = url,
Method = "GET",
UserAgent = userAgent,
Cookie = listCookie.toFonmtCookie(),
Accept = ((accept.Length == 0) ? "application/json; charset=utf-8" : accept),
ContentType = "application/json",
Referer = referer,
ProtocolVersion = HttpVersion.Version11,
KeepAlive = true,
ResultType = ResultType.String,
WebProxy = WebRequest.DefaultWebProxy
};
if (webHeader != null)
{
httpItem.Header = webHeader;
}
addHander(httpItem);
HttpResult httpReuslt = GetHttpReuslt(httpItem);
addCookle(httpReuslt.Cookie);
return httpReuslt;
}
private void addHander(HttpItem item)
{
item.Header.AddWebHander("Accept-Encoding", "gzip, deflate");
item.Header.AddWebHander("Accept-Language", "zh-CN,zh;q=0.9");
}
public bool getSecuritydevices()
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Api-Key", apiKey);
webHeaderCollection.AddWebHander("Origin", "https://appleid.apple.com");
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult webJsonContent = getWebJsonContent("https://appleid.apple.com/account/manage/security/devices", "https://appleid.apple.com/account/manage", webHeaderCollection);
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
action?.Invoke(appleId, DisplyType.xinxi, "设备获取成功");
string[] allKeys = webJsonContent.Header.AllKeys;
foreach (string text in allKeys)
{
if (!handelDic.ContainsKey(text))
{
handelDic.TryAddDic(text, webJsonContent.Header[text]);
}
else
{
handelDic[text] = webJsonContent.Header[text];
}
}
if (_changeItem.isDeleteDevice)
{
Securitydevices securitydevices = Tools.Todejosn<Securitydevices>(webJsonContent.Html);
int num = 1;
Securitydevices.Device[] array = securitydevices?.devices;
foreach (Securitydevices.Device device in array)
{
action?.Invoke(appleId, DisplyType.xinxi, "正在删除第" + num + "个设备");
deleteDevice(device.id);
num++;
}
action?.Invoke(appleId, DisplyType.xinxi, "设备删除完成");
}
return true;
}
action?.Invoke(appleId, DisplyType.xinxi, "设备获取异常");
return false;
}
public bool deleteDevice(string id)
{
bool flag = true;
DevicesInfo devices = GetDevices(id);
if (devices != null)
{
flag = devices.allowRemoval;
}
if (flag)
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
if (handelDic.ContainsKey("scnt"))
{
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
}
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Api-Key", apiKey);
webHeaderCollection.AddWebHander("Origin", "https://appleid.apple.com");
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = DeleteWebContent("https://appleid.apple.com/account/manage/security/devices/" + id, "", "https://appleid.apple.com/account/manage", webHeaderCollection);
if (httpResult.StatusCode == HttpStatusCode.OK)
{
string[] allKeys = httpResult.Header.AllKeys;
foreach (string text in allKeys)
{
if (!handelDic.ContainsKey(text))
{
handelDic.TryAddDic(text, httpResult.Header[text]);
}
else
{
handelDic[text] = httpResult.Header[text];
}
}
if (Tools.Todejosn<DeleteDeviceReust>(httpResult.Html)?.removedDevice.id == id)
{
action?.Invoke(appleId, DisplyType.xinxi, "设备删除成功");
return true;
}
action?.Invoke(appleId, DisplyType.xinxi, "设备删除失败");
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, "设备删除失败");
}
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, "改设备无法删除");
}
return false;
}
private DevicesInfo GetDevices(string id)
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Api-Key", apiKey);
webHeaderCollection.AddWebHander("Origin", "https://appleid.apple.com");
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult webJsonContent = getWebJsonContent("https://appleid.apple.com/account/manage/security/devices/" + id, "https://appleid.apple.com/account/manage", webHeaderCollection);
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
string[] allKeys = webJsonContent.Header.AllKeys;
foreach (string text in allKeys)
{
if (!handelDic.ContainsKey(text))
{
handelDic.TryAddDic(text, webJsonContent.Header[text]);
}
else
{
handelDic[text] = webJsonContent.Header[text];
}
}
return Tools.Todejosn<DevicesInfo>(webJsonContent.Html);
}
action?.Invoke(appleId, DisplyType.xinxi, "设备信息获取失败");
return null;
}
public bool RetrievePassword(bool _openVpn, AppleAcount acount, string newPwd, bool isCloseAuthen = false)
{
if (string.IsNullOrEmpty(ProxyIp))
{
ProxyIp = ProxyAccountCache.getProxyAccountIP(acount.appleId);
}
appleId = acount.appleId;
openVpn = _openVpn;
string url = "https://iforgot.apple.com/password/verify/appleid?language=" + language;
listCookie.Add(new CookieItem
{
Key = "idclient",
Value = "web"
});
if (acount.birthday.Split('-').Length == 3)
{
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);
if (num)
{
ProxyAccountCache.addProxyIp(appleId, ProxyIp);
}
return num;
}
}
action?.Invoke(appleId, DisplyType.xinxi, "未知错误");
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, "生日未导入或者格式错误");
}
return false;
}
private CaptchaModel getCaptcha(string sstt)
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
webHeaderCollection.AddWebHander("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;
}
private bool verifyAppleid(string sstt, AppleAcount acount, string newPwd, bool isCloseAuthen, int RetryCount = 0)
{
if (RetryCount >= 3)
{
action?.Invoke(appleId, DisplyType.xinxi, "验证码获取失败,#3");
return false;
}
int num = 0;
CaptchaModel captchaModel = null;
bool flag = false;
do
{
action?.Invoke(appleId, DisplyType.xinxi, "获取验证码.." + (num + 1));
captchaModel = getCaptcha(sstt);
if (captchaModel == null)
{
Thread.Sleep(500);
}
else if (!string.IsNullOrEmpty(captchaModel.payload.content))
{
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(appleId, DisplyType.xinxi, "正在验证账号");
string postData = "{\"id\":\"" + acount.appleId + "\",\"captcha\":{\"id\":" + captchaModel.id + ",\"answer\":\"" + captchaModel.reust + "\",\"token\":\"" + captchaModel.token + "\"}}";
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
webHeaderCollection.AddWebHander("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 = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, "不是有效的AppleId");
}
AppSysConfig.proxyModels.Push(new ProxyModel2
{
prixyIp = 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;
appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
webHeaderCollection.AddWebHander("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"))
{
sstt = webJsonContent.Header["sstt"];
bool num2 = unenrollment(sstt, acount, newPwd);
if (num2)
{
AppSysConfig.proxyModels.Push(new ProxyModel2
{
prixyIp = ProxyIp,
applyDate = DateTime.Now
});
}
return num2;
}
action?.Invoke(appleId, DisplyType.xinxi, "没有双重认证");
AppSysConfig.proxyModels.Push(new ProxyModel2
{
prixyIp = ProxyIp,
applyDate = DateTime.Now
});
return false;
}
action?.Invoke(appleId, DisplyType.xinxi, "正在获取重设方式");
if (webJsonContent.Html.Contains("reset_password") && webJsonContent.Header.AllKeys.Contains("sstt"))
{
sstt = webJsonContent.Header["sstt"];
webHeaderCollection["sstt"] = sstt;
appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
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(appleId, DisplyType.xinxi, "没有重设密码的方式");
return false;
}
}
}
if (!webJsonContent.Html.Contains("questions") && !webJsonContent.RedirectUrl.ToLower().StartsWith("https://iforgot.apple.com/password/verify/birthday"))
{
action?.Invoke(appleId, DisplyType.xinxi, "没有重设密码的方式");
return false;
}
sstt = webJsonContent.Header["sstt"];
webHeaderCollection["sstt"] = sstt;
appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
if (!webJsonContent.Html.Contains("questions"))
{
return VerifyBirthday(webJsonContent.RedirectUrl, acount, newPwd, webHeaderCollection);
}
HttpResult httpResult3 = postWebContent("https://iforgot.apple.com/password/authenticationmethod", "{\"type\":\"questions\"}", "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeaderCollection);
if (httpResult3.StatusCode == HttpStatusCode.Found)
{
return VerifyBirthday(httpResult3.RedirectUrl, acount, newPwd, webHeaderCollection);
}
}
}
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
action?.Invoke(appleId, 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);
}
ServiceErrorsModel serviceErrorsModel2 = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel2 != null)
{
if (serviceErrorsModel2.validationErrors != null && serviceErrorsModel2.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel2.validationErrors[0].message);
return false;
}
if (serviceErrorsModel2.service_errors != null && serviceErrorsModel2.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel2.service_errors[0].message);
return false;
}
if (serviceErrorsModel2.serviceErrors != null && serviceErrorsModel2.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel2.serviceErrors[0].message);
return false;
}
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, "请求失败");
}
return false;
}
action?.Invoke(appleId, DisplyType.xinxi, "验证码获取失败#2");
return false;
}
action?.Invoke(appleId, DisplyType.xinxi, "验证码获取失败");
return false;
}
public bool unenrollment(string sstt, AppleAcount acount, string newPwd)
{
action?.Invoke(appleId, DisplyType.xinxi, "正在关闭双重认证");
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
webHeaderCollection.AddWebHander("sstt", sstt);
webHeaderCollection.AddWebHander("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();
if (!string.IsNullOrEmpty(sstt))
{
sstt = HttpUtility.UrlEncode(sstt);
webHeaderCollection["sstt"] = sstt;
appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
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(appleId, 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;
appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
action?.Invoke(appleId, 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)
{
if (httpResult2.StatusCode == HttpStatusCode.BadRequest)
{
action?.Invoke(appleId, DisplyType.xinxi, "生日错误");
return false;
}
action?.Invoke(appleId, DisplyType.xinxi, "网络异常...2#Birthday," + (int)httpResult2.StatusCode);
return false;
}
HttpResult webJsonContent2 = getWebJsonContent(httpResult2.RedirectUrl, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeaderCollection);
if (webJsonContent2.StatusCode != HttpStatusCode.OK)
{
action?.Invoke(appleId, DisplyType.xinxi, "验证密保获取失败");
return false;
}
action?.Invoke(appleId, 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 num = 0;
AothQuestions.Question[] questions = aothQuestions.questions;
foreach (AothQuestions.Question question in questions)
{
string answer = array2[Tools.getAnwerId_Index(question.id) - 1];
aothQuestions2.questions[num] = new AothQuestions.Question
{
id = question.id,
answer = answer,
number = question.number,
question = question.question
};
num++;
}
string postData2 = Tools.Toenjson(aothQuestions2);
HttpResult 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)
{
return unenrollmentRestPwd(httpResult3.RedirectUrl, newPwd, webHeaderCollection);
}
if (httpResult3.StatusCode == HttpStatusCode.BadRequest)
{
action?.Invoke(appleId, DisplyType.xinxi, "密保错误");
return false;
}
}
}
action?.Invoke(appleId, DisplyType.xinxi, "网络异常");
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, "网络异常");
}
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, "双重手机号码认证失败");
}
}
else
{
action?.Invoke(appleId, DisplyType.xinxi, "双重手机号码获取失败");
}
return false;
}
private bool unenrollmentRestPwd(string RedirectUrl, string newPwd, WebHeaderCollection webHeader)
{
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;
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeader.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
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(userAgent);
action?.Invoke(appleId, 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 = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult2.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
action?.Invoke(appleId, DisplyType.xinxi, "请求失败");
return false;
}
if (httpResult2.StatusCode == (HttpStatusCode)260)
{
acount.applePwd = newPwd;
action?.Invoke(appleId, DisplyType.mima, newPwd);
action?.Invoke(appleId, DisplyType.xinxi, "双重关闭成功,密码重置完成");
return true;
}
}
}
action?.Invoke(appleId, DisplyType.xinxi, "未知错误");
return false;
}
private bool VerifyBirthday(string RedirectUrl, AppleAcount acount, string newPwd, WebHeaderCollection webHeader)
{
string text = "";
action?.Invoke(appleId, 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)
{
action?.Invoke(appleId, DisplyType.xinxi, "生日错误");
return false;
}
action?.Invoke(appleId, 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);
}
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(userAgent);
webHeader.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult webJsonContent2 = getWebJsonContent(httpResult.RedirectUrl, "https://iforgot.apple.com/password/verify/appleid?language=" + language, webHeader);
if (webJsonContent2.StatusCode != HttpStatusCode.OK)
{
action?.Invoke(appleId, DisplyType.xinxi, "密保获取失败2");
return false;
}
if (!webJsonContent2.Html.Contains("questions"))
{
action?.Invoke(appleId, 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)
{
action?.Invoke(appleId, 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 num = 0;
AothQuestions.Question[] questions = aothQuestions.questions;
foreach (AothQuestions.Question question in questions)
{
string answer = array[Tools.getAnwerId_Index(question.id) - 1];
aothQuestions2.questions[num] = new AothQuestions.Question
{
id = question.id,
answer = answer,
number = question.number,
question = question.question
};
num++;
}
string postData = Tools.Toenjson(aothQuestions2);
HttpResult 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(appleId, 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)
{
action?.Invoke(appleId, DisplyType.xinxi, "密保错误");
return false;
}
return false;
}
action?.Invoke(appleId, DisplyType.xinxi, "验证密保获取失败");
return false;
}
private bool restPwd(string RedirectUrl, string newPwd, WebHeaderCollection webHeader)
{
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(appleId, 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 = JsonConvert.DeserializeObject<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(appleId, DisplyType.xinxi, "失败,异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
action?.Invoke(appleId, DisplyType.xinxi, "请求失败");
return false;
}
if (httpResult.StatusCode == (HttpStatusCode)260)
{
action?.Invoke(appleId, DisplyType.mima, newPwd);
action?.Invoke(appleId, DisplyType.xinxi, "密码重置完成");
AppSysConfig.proxyModels.Push(new ProxyModel2
{
prixyIp = ProxyIp,
applyDate = DateTime.Now
});
return true;
}
}
action?.Invoke(appleId, DisplyType.xinxi, "未知错误");
return false;
}
protected void addCookle(string cookies)
{
if (cookies == null || string.IsNullOrEmpty(cookies.Trim()))
{
return;
}
foreach (CookieItem item in HttpCookieHelper.GetCookieList(cookies))
{
if (!(item.Key == "Max-Age") && !(item.Key == "Path") && !(item.Key == "Expires") && !(item.Key == "domain") && !(item.Key == "Domain") && !(item.Key == "path"))
{
CookieItem cookieItem = listCookie.Where((CookieItem c) => c.Key == item.Key).FirstOrDefault();
if (cookieItem == null)
{
listCookie.Add(item);
}
else if (!string.IsNullOrEmpty(item.Value.Trim()))
{
cookieItem.Value = item.Value.Trim();
}
}
}
}
}
}