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

3023 lines
121 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 AppleBatch_June.Domain;
using AppleBatch_June.ExecuteTasks;
using AppleBatch_June.Model;
using AppleBatch_June.Utils;
using DotNet.Utilities;
namespace AppleBatch_June.AppleWebServace
{
public class AppleManageWeb : AppleWebBase
{
private string redirectURI = "https://appleid.apple.com";
private static string homeLanguage = "zh_CN";
protected string Apple_Widget_Key = "af1139274f266b22b68c2a3e7ad932cb3c0bbe854e13a79af78dcc73136882c3";
public string widgKey = string.Empty;
public AppleChangeItem _changeItem;
private Func<string, int, string> getCodeAct_;
private string appleHomeUrl = "https://appleid.apple.com/account/manage";
private static readonly object lockSendMsmObj = new object();
private readonly Dictionary<string, object> objSendMsmS = new Dictionary<string, object>();
public HttpResult LoginloginReust;
private string authUrl => "https://idmsa.apple.com/appleauth/auth/signin?widgetKey=" + Apple_Widget_Key + "&language=" + homeLanguage;
protected string iframeId { get; set; }
public string appleId { get; set; }
public bool openHsa2 { get; set; }
private AvailableSecurityQuestions securityQuestions { get; set; }
public AppleAcount acount { get; set; }
public bool isVieyBirthday { get; set; }
public bool isViey { get; set; }
public bool AuthenDoubleOpenState { get; set; }
public bool isChangAppleId { get; set; }
public bool isPwdViey { get; set; }
private AuthsigninConfig authsigninConfig { get; set; }
private string accountFirstName { get; set; }
private string accountLastName { get; set; }
private LoginAppleInfo loginAppleInfo { get; set; }
private string XAppleIDAccountCountry { get; set; } = "";
private string XAppleIDAccountCountry_SOUSUO { get; set; } = "";
public string authSupportpin { get; set; } = "";
private bool incompatibleDevice { get; set; }
public AppleManageWeb(bool _openVpn, Action<string, DisplyType, string> _action, Action<string, DisplyType, string> _applyAtion, ITaskRunState _taskState)
: base(_action, _applyAtion, _taskState)
{
taskState = _taskState ?? throw new Exception("任务运行状态不能是空的");
base.openVpn = _openVpn;
iframeId = APPLEHCHelp.getIframeId();
}
public bool applyChangeAcount(AppleAcount _acount, AppleChangeItem changeItem, bool errorGoint, string _notifiKey, ref string accountName)
{
acount = _acount;
appleId = _acount.appleId;
base.noticeKey = _notifiKey;
_changeItem = changeItem;
listCookie.Add(new CookieItem
{
Key = "geo",
Value = "CN"
});
initUserAgent();
authsigninConfig = new AuthsigninConfig
{
Apple_Widget_Key = Apple_Widget_Key,
authUrl = authUrl,
homeLanguage = homeLanguage,
iframeId = iframeId,
redirectURI = redirectURI,
refererUrl = "https://idmsa.apple.com/"
};
try
{
if (changeItem.CreatePin)
{
base.fristGetProxy = true;
}
if (LoginWeb() && appleauthAuth(acount))
{
if (isPwdViey && isPwdViey && isChangAppleId && isVieyBirthday)
{
ProxyAccountCache.addwebProxyIp(acount.appleId, base.ProxyIp, base.userAgent, iframeId);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "账号修改完成");
return true;
}
GetGsWsToken();
action?.Invoke(base.noticeKey, DisplyType.xinxi, "登录成功");
if (intoHome())
{
ProxyAccountCache.addwebProxyIp(acount.appleId, base.ProxyIp, base.userAgent, iframeId);
string apple_Widget_Key = (base.apiKey = "cbf64fd6843ee630b463f358ea0b707b");
Apple_Widget_Key = apple_Widget_Key;
bool flag = true;
if (_changeItem.isDeleteDevice)
{
getSecuritydevices();
}
if (changeItem.CreatePin)
{
if (string.IsNullOrEmpty(authSupportpin))
{
flag = CreateSupportpin(appleHomeUrl);
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, authSupportpin);
flag = true;
}
}
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 (loginAppleInfo != null && !string.IsNullOrEmpty(loginAppleInfo?.security?.rescueEmail) && changeItem.isRemoveRescueEmail)
{
flag = RemoveRescueEmail();
}
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, changeItem.ckShippingAddress);
}
if (!string.IsNullOrEmpty(acount.newAppleId) && !isChangAppleId)
{
bool num = setAccnount(acount.newAppleId, acount.newApplePopPwd, "cbf64fd6843ee630b463f358ea0b707b");
if (!num && flag)
{
int num2 = Tools.ToNetWorkInt(ConfigUtlis.getConfigValue("comNetworkConfig"), 0);
if (base.openVpn && num2 == 0)
{
APIUtlis.ApiApplyAct(45, "新邮箱验证异常");
}
}
flag = num;
}
if (changeItem.pay != null)
{
flag = changenPayment(changeItem.pay);
}
if (changeItem.isUnlinkFamily)
{
bool family = getFamily();
if (!flag)
{
flag = family;
}
}
return flag;
}
}
}
catch (Exception ex)
{
APIUtlis.ApiSeriveError(ex);
action?.Invoke(base.noticeKey, DisplyType.xinxi, ex.Message);
}
finally
{
accountName = appleId;
}
return false;
}
public bool CreateSupportpin(string appleHomeUrl)
{
string postData = "{}";
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.Add("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.Add("X-Apple-I-TimeZone", "Asia/Shanghai");
webHeaderCollection.Add("X-Apple-I-Request-Context", "ca");
if (handelDic.ContainsKey("scnt"))
{
webHeaderCollection.Add("scnt", handelDic["scnt"]);
}
webHeaderCollection.Add("X-Apple-Api-Key", base.apiKey.Trim());
webHeaderCollection.Add("X-Apple-I-FD-Client-Info", FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent));
HttpResult httpResult = postWebContent("https://appleid.apple.com/account/manage/supportpin", postData, "https://appleid.apple.com/account/manage", webHeaderCollection);
if (httpResult.StatusCode == HttpStatusCode.BadRequest || httpResult.StatusCode == HttpStatusCode.Unauthorized)
{
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "PIN失败异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "PIN失败异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "PIN失败异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
}
if (httpResult.StatusCode == HttpStatusCode.OK)
{
Dictionary<string, string> dataSource = Tools.Todejosn<Dictionary<string, string>>(httpResult.Html);
string dicVal = dataSource.getDicVal("pin", "");
string dicVal2 = dataSource.getDicVal("localizedDate", "");
action?.Invoke(base.noticeKey, DisplyType.xinxi, "支持 PIN" + dicVal + ",有效期:" + dicVal2);
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;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "获取PIN码失败,未知异常");
return false;
}
private bool RemoveRescueEmail()
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "正在移除救援邮箱");
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
if (handelDic.ContainsKey("scnt"))
{
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
}
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-I-Request-Context", "ca");
webHeaderCollection.AddWebHander("X-Apple-I-TimeZone", "Asia/Shanghai");
webHeaderCollection.AddWebHander("X-Apple-Api-Key", base.apiKey);
webHeaderCollection.AddWebHander("Origin", "https://appleid.apple.com");
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = DeleteWebContent("https://appleid.apple.com/account/manage/security/email/rescue", "", "https://appleid.apple.com/", webHeaderCollection);
if (httpResult.StatusCode != HttpStatusCode.OK && httpResult.StatusCode != HttpStatusCode.NoContent)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "除救援邮箱移除失败");
return false;
}
action?.Invoke(base.noticeKey, DisplyType.balance, "已移除");
action?.Invoke(base.noticeKey, DisplyType.xinxi, "除救援邮箱移除成功");
return true;
}
private bool changePwd(string oldPwd, string newPwd, int retry = 0)
{
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", base.apiKey.Trim());
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = putWebContent("https://appleid.apple.com/account/manage/security/password", putData, appleHomeUrl, webHeaderCollection);
UpdateScnt(httpResult.Header);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.OK)
{
acount.applePwd = newPwd;
applyAtion?.Invoke(base.noticeKey, DisplyType.mima, newPwd);
action?.Invoke(base.noticeKey, 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(base.noticeKey, DisplyType.xinxi, "密码修改失败,未知异常");
return false;
}
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密码修改失败:" + serviceError);
if ((serviceError.Contains("发生未知错误") || serviceError.Contains("无法处理你的请求")) && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return changePwd(oldPwd, newPwd, retry + 1);
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密码修改失败,未知异常");
}
return false;
}
private bool changQuestions(string newqt1, string newqt2, string newqt3, int retry = 0)
{
string text = "";
try
{
if (securityQuestions != null)
{
AothQuestions obj = new AothQuestions
{
questions = new AothQuestions.Question[3]
};
obj.questions[0] = new AothQuestions.Question
{
id = 130,
answer = newqt1,
number = 1,
question = securityQuestions.availableSecurityQuestions[0][0].question
};
obj.questions[1] = new AothQuestions.Question
{
id = 136,
answer = newqt2,
number = 2,
question = securityQuestions.availableSecurityQuestions[1][0].question
};
obj.questions[2] = new AothQuestions.Question
{
id = 142,
answer = newqt3,
number = 3,
question = securityQuestions.availableSecurityQuestions[2][0].question
};
text = Tools.Toenjson(obj);
}
else
{
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 + "\"}]}"));
}
}
catch (Exception ex)
{
APIUtlis.ApiSeriveError(ex);
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", base.apiKey.Trim());
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.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");
UpdateScnt(httpResult.Header);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.OK)
{
applyAtion?.Invoke(base.noticeKey, DisplyType.qt1, newqt1);
applyAtion?.Invoke(base.noticeKey, DisplyType.qt2, newqt2);
applyAtion?.Invoke(base.noticeKey, DisplyType.qt3, newqt3);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密保修改成功");
return true;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密保修改失败,未知异常");
return false;
}
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密保修改失败:" + serviceError);
if ((serviceError.Contains("发生未知错误") || serviceError.Contains("无法处理你的请求")) && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return changQuestions(newqt1, newqt2, newqt3, retry + 1);
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密保修改失败");
}
return false;
}
private bool changeBirthDate(string fullBirthDate, int retry = 0)
{
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", base.apiKey.Trim());
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = putWebContent("https://appleid.apple.com/account/manage/security/birthday", putData, appleHomeUrl, webHeaderCollection);
UpdateScnt(httpResult.Header);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.OK)
{
applyAtion?.Invoke(base.noticeKey, DisplyType.shengri, fullBirthDate);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "生日修改完成");
return true;
}
if (httpResult.StatusCode == HttpStatusCode.Forbidden && retry == 0 && GetGsWsToken())
{
return changeBirthDate(fullBirthDate, retry + 1);
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "生日修改失败,未知异常");
return false;
}
if (httpResult.StatusCode == HttpStatusCode.Unauthorized)
{
GetGsWsToken();
}
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "生日修改失败:" + serviceError);
if ((serviceError.Contains("发生未知错误") || serviceError.Contains("无法处理你的请求")) && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return changeBirthDate(fullBirthDate, retry + 1);
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "生日修改失败");
}
return false;
}
public StackablePaymentInfos getAddressInfo(bool isAgent = false)
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Api-Key", base.apiKey);
webHeaderCollection.AddWebHander("x-apple-store-front", "143465-19,8");
webHeaderCollection.AddWebHander("Origin", "https://apps.apple.com");
HttpResult webJsonContent = getWebJsonContent("https://buy.apps.apple.com/account/stackable/paymentInfos?context=CWA&isVideoEverywhere=true", "https://apps.apple.com/", webHeaderCollection, "application/json");
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
return Tools.Todejosn<StackablePaymentInfos>(webJsonContent.Html);
}
if (webJsonContent.StatusCode == HttpStatusCode.Unauthorized)
{
if (!authV1Gs())
{
GetGsWsToken();
authV1Gs();
}
if (!isAgent)
{
return getAddressInfo(isAgent: true);
}
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "地址信息获取异常");
return null;
}
public bool getAccountPaymentOptions(int retryCount = 0)
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Api-Key", base.apiKey);
webHeaderCollection.AddWebHander("x-apple-store-front", "143465-19,8");
webHeaderCollection.AddWebHander("Origin", "https://apps.apple.com");
HttpResult webJsonContent = getWebJsonContent("https://buy.apps.apple.com/account/paymentOptions", "https://apps.apple.com/", webHeaderCollection, "application/json");
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
return true;
}
if (webJsonContent.StatusCode == HttpStatusCode.Unauthorized)
{
string text = ".";
for (int i = 0; i < retryCount; i++)
{
text += ".";
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "获取账号支付方式" + text);
if (!authV1Gs())
{
GetGsWsToken();
authV1Gs();
}
if (retryCount <= 3)
{
return getAccountPaymentOptions(retryCount + 1);
}
return true;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "设备获取异常");
return false;
}
public bool getAccountPaymentOptionsContext()
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("x-apple-store-front", "143465-19,8");
webHeaderCollection.AddWebHander("Origin", "https://apps.apple.com");
if (getWebJsonContent("https://buy.apps.apple.com/account/stackable/paymentInfos?context=CWA&isVideoEverywhere=true", "https://apps.apple.com/", webHeaderCollection, "application/json").StatusCode == HttpStatusCode.OK)
{
return true;
}
return false;
}
public bool authV1Gs()
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("x-apple-store-front", "143465-19,8");
webHeaderCollection.AddWebHander("Origin", "https://apps.apple.com");
HttpResult httpResult = postWebContent("https://auth.apps.apple.com/auth/v1/gs", "", "https://apps.apple.com/", webHeaderCollection, "*/*");
if (httpResult.StatusCode == HttpStatusCode.OK)
{
return true;
}
if (httpResult.StatusCode == HttpStatusCode.Unauthorized)
{
return false;
}
return true;
}
private bool changenPayment(PaymentInfo pay, int retry = 0)
{
string text = "{\"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 + "\"},{0}\"id\":1}";
string webAppend = pay.webAppend;
if (!string.IsNullOrEmpty(webAppend))
{
string text2 = "";
string[] array = webAppend.Split('&');
for (int i = 0; i < array.Length; i++)
{
string[] array2 = array[i].Split('=');
if (array2.Length == 2)
{
string text3 = array2[0];
string text4 = array2[1];
text2 = text2 + "\"" + text3 + "\":\"" + text4 + "\",";
}
}
text = text.Replace("{0}", text2);
}
else
{
text = text.Replace("{0}", "");
}
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", base.apiKey.Trim());
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = putWebContent("https://appleid.apple.com/account/manage/payment/method/none/1", text, appleHomeUrl, webHeaderCollection);
UpdateScnt(httpResult.Header);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.OK)
{
applyAtion?.Invoke(base.noticeKey, 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);
iTunesAccountLoginCache.removeReddemUserInfo(loginIdUserInfo.account, loginIdUserInfo.StdndbyKeyGuid);
}
iCloudAccountLoginCache.removeUserInfoByAppleId(acount.appleId, acount.applePwd);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "国家修改完成");
return true;
}
if (httpResult.StatusCode == HttpStatusCode.Forbidden)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "国家修改失败,请求错误");
}
if (retry == 0)
{
getAccountPaymentOptions();
GetGsWsToken();
return changenPayment(pay, retry + 1);
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "国家修改失败,未知异常:" + (int)httpResult.StatusCode);
return false;
}
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "国家修改失败:" + serviceError);
if (serviceError.Contains("发生未知错误") && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return changenPayment(pay, retry + 1);
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "国家修改失败,未知异常");
}
return false;
}
public bool editAddrs(string addres, bool ckShippingAddress)
{
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(Tools.Toenjson(dictionary));
}
if (!ckShippingAddress)
{
return EditAddres(dictionary2);
}
return ShippingAddres(dictionary2);
}
public bool ShippingAddres(Dictionary<string, string> pairs, int retry = 0)
{
StackablePaymentInfos addressInfo = getAddressInfo();
if (addressInfo != null && addressInfo.data != null && addressInfo.data.attributes != null)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "正在修改配送地址");
string text = getDicValue(pairs, "公司", "");
string text2 = "";
string text3 = "";
string text4 = "";
string text5 = "";
string text6 = "";
string text7 = "";
string text8 = "";
string text9 = "";
if (addressInfo.data.attributes.shippingAddressInfo != null)
{
StackablePaymentInfos.ShippingaddressinfoModel shippingAddressInfo = addressInfo.data.attributes.shippingAddressInfo.shippingAddressInfo;
text2 = shippingAddressInfo.addressShippingCountryCode;
text3 = getDicValue(pairs, "城市", shippingAddressInfo.addressShippingCity);
text4 = getDicValue(pairs, "邮编", shippingAddressInfo.addressShippingPostalCode);
text5 = getDicValue(pairs, "街道地址", shippingAddressInfo.addressShippingLineFirst);
text6 = getDicValue(pairs, "账单名字", shippingAddressInfo.shippingFirstName);
text7 = getDicValue(pairs, "省/市", shippingAddressInfo.addressShippingStateProvince);
text8 = getDicValue(pairs, "楼号单元", shippingAddressInfo.addressShippingLineSecond);
text9 = getDicValue(pairs, "账单姓氏", shippingAddressInfo.shippingLastName);
}
else if (addressInfo.data.attributes.paymentInfos != null && addressInfo.data.attributes.paymentInfos.Length != 0)
{
StackablePaymentInfos.Billingaddress billingAddress = addressInfo.data.attributes.paymentInfos[0].billingAddress;
text2 = billingAddress.addressOfficialCountryCode;
text3 = getDicValue(pairs, "城市", billingAddress.addressOfficialCity);
text4 = getDicValue(pairs, "邮编", billingAddress.addressOfficialPostalCode);
text5 = getDicValue(pairs, "街道地址", billingAddress.addressOfficialLineFirst);
text6 = getDicValue(pairs, "账单名字", billingAddress.billingFirstName);
text7 = getDicValue(pairs, "省/市", billingAddress.addressOfficialStateProvince);
text8 = getDicValue(pairs, "楼号单元", billingAddress.addressOfficialLineSecond);
text9 = getDicValue(pairs, "账单姓氏", billingAddress.billingLastName);
}
if (string.IsNullOrEmpty(text2))
{
text2 = XAppleIDAccountCountry_SOUSUO;
}
if (!string.IsNullOrEmpty(text))
{
text = ",\"addressShippingCompanyName\":\"" + text + "\"";
}
string postData = "{\"addressShippingCountryCode\":\"" + text2 + "\",\"addressShippingCity\":\"" + text3 + "\",\"shippingLastName\":\"" + text9 + "\",\"addressShippingPostalCode\":\"" + text4 + "\",\"addressShippingLineFirst\":\"" + text5 + "\",\"shippingFirstName\":\"" + text6 + "\",\"addressShippingStateProvince\":\"" + text7 + "\",\"addressShippingLineSecond\":\"" + text8 + "\"" + text + "}";
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Api-Key", base.apiKey);
webHeaderCollection.AddWebHander("x-apple-store-front", "143465-19,8");
webHeaderCollection.AddWebHander("Origin", "https://apps.apple.com");
HttpResult httpResult = postWebContent("https://buy.apps.apple.com/account/shippingAddress/edit", postData, "https://apps.apple.com/", webHeaderCollection);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.OK)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "配送地址修改完成");
action?.Invoke(base.noticeKey, DisplyType.reddemLose, "");
return true;
}
if (httpResult.StatusCode == HttpStatusCode.Forbidden)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "配送地址修改失败,请求错误");
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "信息修改失败,未知异常:" + httpResult.StatusCode);
return false;
}
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "配送地址修改失败:" + serviceError);
if (serviceError.Contains("发生未知错误") && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return EditAddres(pairs, retry + 1);
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "配送地址修改失败");
}
return false;
}
return false;
}
public bool EditMangName(string putJson, int retry = 0)
{
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", base.apiKey.Trim());
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = putWebContent("https://appleid.apple.com/account/manage/name", putJson, appleHomeUrl, webHeaderCollection);
UpdateScnt(httpResult.Header);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.OK)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "名称修改完成");
return true;
}
if (httpResult.StatusCode == HttpStatusCode.Forbidden)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "名称修改失败,请求错误");
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "名称修改失败,未知异常");
return false;
}
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "名称修改失败失败:" + serviceError);
if (serviceError.Contains("发生未知错误") && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return EditMangName(putJson, retry + 1);
}
}
return false;
}
public bool EditAddres(Dictionary<string, string> pairs, int retry = 0)
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Domain-Id", "1");
webHeaderCollection.AddWebHander("X-Apple-Api-Key", base.apiKey.Trim());
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.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);
UpdateScnt(webJsonContent.Header);
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "正在修改内容");
string text = "ownerName";
ManagePayment payment = Tools.Todejosn<ManagePayment>(webJsonContent.Html);
string text2 = "";
if (pairs.ContainsKey("税号"))
{
text2 = "\"taxId\":\"" + getDicValue(pairs, "税号", "") + "\",";
}
else if (payment.primaryPaymentMethod.taxId != null)
{
text2 = "\"taxId\":\"" + payment.primaryPaymentMethod.taxId + "\",";
}
string text3 = "";
if (pairs.ContainsKey("卡号"))
{
text3 = text3 + "\"number\":\"" + getDicValue(pairs, "卡号", "") + "\",";
text = "nameOnCard";
}
else if (payment.primaryPaymentMethod.number != null)
{
text3 = text3 + "\"number\":\"" + payment.primaryPaymentMethod.number + "\",";
}
if (pairs.ContainsKey("有效期限年"))
{
text3 = text3 + "\"expirationYear\":\"" + getDicValue(pairs, "有效期限年", "") + "\",";
}
else if (payment.primaryPaymentMethod.expirationYear.HasValue)
{
text3 = text3 + "\"expirationYear\":\"" + payment.primaryPaymentMethod.expirationYear + "\",";
}
if (pairs.ContainsKey("有效期限月"))
{
text3 = text3 + "\"expirationMonth\":\"" + getDicValue(pairs, "有效期限月", "") + "\",";
}
else if (payment.primaryPaymentMethod.expirationMonth.HasValue)
{
text3 = text3 + "\"expirationMonth\":\"" + payment.primaryPaymentMethod.expirationMonth + "\",";
}
if (pairs.ContainsKey("安全码"))
{
text3 = text3 + "\"cvv\":\"" + getDicValue(pairs, "安全码", "") + "\",";
}
if (payment.primaryPaymentMethod.nameOnCard != null)
{
text = "nameOnCard";
}
string text4 = "";
if (payment.primaryPaymentMethod.phoneNumber != null && payment.primaryPaymentMethod.phoneNumber.number != null && payment.primaryPaymentMethod.phoneNumber.areaCode != null && payment.primaryPaymentMethod.phoneNumber.countryCode != null)
{
text4 = "\"phoneNumber\":{\"areaCode\":\"" + (getDicValue(pairs, "电话", payment.primaryPaymentMethod.phoneNumber.number).Contains(getDicValue(pairs, "区号", payment.primaryPaymentMethod.phoneNumber.areaCode)) ? "" : getDicValue(pairs, "区号", payment.primaryPaymentMethod.phoneNumber.areaCode)) + "\",\"number\":\"" + getDicValue(pairs, "电话", payment.primaryPaymentMethod.phoneNumber.number).Replace("(", "").Replace(")", "").Replace("-", "")
.Replace(" ", "") + "\",\"countryCode\":\"" + payment.primaryPaymentMethod.phoneNumber.countryCode + "\"},";
}
else
{
string text5 = "";
string text6 = "";
NationalList nationalList = (from c in new NationalData().getMation()
where c.payment.billingAddress.countryCode.ToUpper() == payment.primaryPaymentMethod.paymentAccountCountryCode.ToUpper()
select c).FirstOrDefault();
if (nationalList != null)
{
if (nationalList.payment.phoneNumber.number.StartsWith("410"))
{
text5 = nationalList.payment.phoneNumber.number.Replace("410", "");
text6 = "410";
}
else
{
text5 = nationalList.payment.phoneNumber.number;
text6 = nationalList.payment.phoneNumber.areaCode;
}
text4 = "\"phoneNumber\":{\"areaCode\":\"" + text6 + "\",\"number\":\"" + text5 + "\",\"countryCode\":\"" + payment.primaryPaymentMethod.phoneNumber.countryCode + "\"},";
}
}
string putData = string.Concat("{\"" + text + "\":{\"firstName\":\"" + getDicValue(pairs, "账单名字", payment.primaryPaymentMethod.ownerName.firstName) + "\",\"lastName\":\"" + getDicValue(pairs, "账单姓氏", payment.primaryPaymentMethod.ownerName.lastName) + "\"}," + text4 + "\"billingAddress\":{\"line1\":\"" + getDicValue(pairs, "街道地址", payment.primaryPaymentMethod.billingAddress.line1) + "\",\"line2\":\"" + getDicValue(pairs, "楼号单元", payment.primaryPaymentMethod.billingAddress.line2) + "\",\"line3\":\"", "\",\"suburb\":\"", getDicValue(pairs, "区", payment.primaryPaymentMethod.billingAddress.suburb), "\",\"county\":\"", getDicValue(pairs, "县", payment.primaryPaymentMethod.billingAddress.county), "\",\"city\":\"", getDicValue(pairs, "城市", payment.primaryPaymentMethod.billingAddress.city), "\",\"countryCode\":\"", payment.primaryPaymentMethod.billingAddress.countryCode, "\",\"postalCode\":\"", getDicValue(pairs, "邮编", payment.primaryPaymentMethod.billingAddress.postalCode), "\",\"stateProvinceName\":\"", getDicValue(pairs, "省/市", payment.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", base.apiKey.Trim());
appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.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);
UpdateScnt(httpResult.Header);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.OK)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "信息修改完成");
action?.Invoke(base.noticeKey, DisplyType.reddemLose, "");
return true;
}
if (httpResult.StatusCode == HttpStatusCode.Forbidden)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "账单信息修改失败,请求错误");
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "信息修改失败,未知异常:" + httpResult.StatusCode);
return false;
}
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "账单信息修改失败:" + serviceError);
if (serviceError.Contains("发生未知错误") && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return EditAddres(pairs, retry + 1);
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "账单信息修改失败");
}
return false;
}
action?.Invoke(base.noticeKey, 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 getSecuritydevices()
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Api-Key", base.apiKey);
webHeaderCollection.AddWebHander("Origin", "https://appleid.apple.com");
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.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)
{
UpdateScnt(webJsonContent.Header);
action?.Invoke(base.noticeKey, 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(base.noticeKey, DisplyType.xinxi, "正在删除第" + num + "个设备");
deleteDevice(device.id);
num++;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "设备删除完成");
}
return true;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "设备获取异常");
return false;
}
public bool getFamily()
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
string text = APPLEHCHelp.getIframeId().Replace("auth-", "");
HttpResult webJsonContent = getWebJsonContent("https://familyws.icloud.apple.com/api/family-members", "https://familyws.icloud.apple.com/members?wid=" + text + "&env=idms_prod&locale=zh_CN", webHeaderCollection);
if (webJsonContent.StatusCode == HttpStatusCode.OK)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "家庭信息获取成功");
FamilyMembers familyMembers = Tools.Todejosn<FamilyMembers>(webJsonContent.Html);
if (familyMembers != null && familyMembers.isLinkedToFamily && !familyMembers.isMemberOfFamily && familyMembers.family != null)
{
return unlinkFamily(familyMembers.currentDsid, familyMembers.family.familyId, familyMembers.currentUserAppleId);
}
return true;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "家庭信息获取异常");
return false;
}
public bool GetGsWsToken()
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-I-Request-Context", "ca");
webHeaderCollection.AddWebHander("scnt", handelDic.getDicVal("scnt", ""));
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult webContent = getWebContent("https://appleid.apple.com/account/manage/gs/ws/token", "https://appleid.apple.com/", webHeaderCollection, "application/json, text/plain", "application/json");
if (webContent.StatusCode == HttpStatusCode.OK)
{
UpdateScnt(webContent.Header);
return true;
}
return false;
}
private bool intoHome()
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-I-Request-Context", "ca");
webHeaderCollection.AddWebHander("scnt", handelDic.getDicVal("scnt", ""));
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.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 = Tools.Todejosn<LoginAppleInfo>(text2);
if (loginAppleInfo != null)
{
action?.Invoke(base.noticeKey, DisplyType.shengri, loginAppleInfo.security.birthday);
if (!string.IsNullOrEmpty(loginAppleInfo.security.birthday) && loginAppleInfo.security.birthday.Split('-').Length == 3 && (string.IsNullOrEmpty(acount.birthday) || acount.birthday != loginAppleInfo.security.birthday))
{
acount.birthday = loginAppleInfo.security.birthday;
}
if (loginAppleInfo.person.primaryAddress != null && loginAppleInfo.person.primaryAddress.countryName != null)
{
action?.Invoke(base.noticeKey, 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(base.noticeKey, DisplyType.lostBillNo, arg);
}
action?.Invoke(base.noticeKey, DisplyType.xiaofeiriqiNow, accountLastName + " " + accountFirstName);
if (!string.IsNullOrEmpty(loginAppleInfo.security.rescueEmail))
{
action?.Invoke(base.noticeKey, DisplyType.balance, loginAppleInfo.security.rescueEmail);
}
else
{
action?.Invoke(base.noticeKey, DisplyType.balance, "无");
}
}
action?.Invoke(base.noticeKey, 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 = Tools.Todejosn<AvailableSecurityQuestions>(text2);
}
return true;
}
action?.Invoke(base.noticeKey, 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", base.apiKey);
webHeaderCollection.AddWebHander("Origin", "https://appleid.apple.com");
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.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(base.noticeKey, DisplyType.xinxi, "设备信息获取失败");
return null;
}
public bool unlinkFamily(string currentDsid, string familyId, string currentUserAppleId)
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
string text = APPLEHCHelp.getIframeId().Replace("auth-", "");
string postData = "{\"currentDsid\":\"" + currentDsid + "\",\"familyId\":\"" + familyId + "\",\"currentUserAppleId\":\"" + currentUserAppleId + "\"}";
string referer = "https://familyws.icloud.apple.com/confirm-unlink?wid=" + text + "&env=idms_prod&locale=zh_CN";
HttpResult httpResult = postWebContent("https://familyws.icloud.apple.com/api/unlink-family", postData, referer, webHeaderCollection);
if (httpResult.StatusCode == HttpStatusCode.OK)
{
FamilyMembers familyMembers = Tools.Todejosn<FamilyMembers>(httpResult.Html);
if (familyMembers != null && !familyMembers.isLinkedToFamily && !familyMembers.isMemberOfFamily)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "断开家庭账户连接成功");
return true;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "家庭连接断开失败");
}
else
{
action?.Invoke(base.noticeKey, 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", base.apiKey);
webHeaderCollection.AddWebHander("Origin", "https://appleid.apple.com");
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.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(base.noticeKey, DisplyType.xinxi, "设备删除成功");
return true;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "设备删除失败");
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "设备删除失败");
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "改设备无法删除");
}
return false;
}
public void UpdateScnt(WebHeaderCollection webHeader)
{
if (webHeader == null)
{
return;
}
string[] allKeys = webHeader.AllKeys;
foreach (string text in allKeys)
{
if (text == "scnt")
{
handelDic.TryAddDic(text, webHeader[text]);
}
}
}
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", base.apiKey.Trim());
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult webJsonContent = getWebJsonContent("https://appleid.apple.com/account/manage/family", "https://appleid.apple.com/account/manage", webHeaderCollection);
UpdateScnt(webJsonContent.Header);
}
public bool LoginWeb()
{
HttpResult result = null;
string errMsg = "未知错误";
acount.isAccountException = false;
if (authsignin(acount.appleId, acount.applePwd, authsigninConfig, ref errMsg, out result))
{
if (result != null)
{
if (result.StatusCode == HttpStatusCode.Conflict || result.StatusCode == HttpStatusCode.OK)
{
LoginloginReust = result;
if (result.Html.Contains("hsa2"))
{
acount.isHsa2 = true;
if (openHsa2)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "双重已存在,无需开启");
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "双重验证账号暂不支持更改");
}
return false;
}
return true;
}
if (result.StatusCode == HttpStatusCode.PreconditionFailed)
{
string[] allKeys = result.Header.AllKeys;
foreach (string text in allKeys)
{
switch (text)
{
case "X-Apple-Auth-Attributes":
case "X-Apple-Repair-Session-Token":
case "X-Apple-ID-Session-Id":
case "scnt":
case "X-Apple-OAuth-Context":
handelDic.TryAddDic(text, result.Header[text]);
break;
}
if (text == "scnt")
{
handelDic.TryAddDic("scnt2", result.Header[text]);
}
}
return repair();
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "登录异常了");
}
}
return false;
}
private bool appleauthAuth(AppleAcount acount)
{
if (isViey)
{
return true;
}
action?.Invoke(base.noticeKey, 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-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, authsigninConfig);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.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[] allKeys = webContent.Header.AllKeys;
foreach (string text in allKeys)
{
if (text == "scnt" || text == "X-Apple-Auth-Attributes")
{
handelDic.TryAddDic(text, webContent.Header[text]);
}
}
string text2 = new Regex(AppSysConfig.getConfig("Regex_appleauthAuth")).Match(webContent.Html).Groups[1].Value.Trim() + "}";
if (string.IsNullOrEmpty(text2))
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密保获取失败..请重试");
return false;
}
AothQuestions questions = Tools.Todejosn<AothQuestions>(text2);
string config = AppSysConfig.getConfig("supportPinInSACRChallenge");
if (webContent.Html.Contains(config) && _changeItem.CreatePin)
{
CreateAuthSupportpin();
}
return verifyAuthQuestions(questions, new string[3] { acount.appleQt1, acount.appleQt2, acount.appleQt3 });
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密保获取失败");
return false;
}
public bool CreateAuthSupportpin()
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "正在获取PIN码");
new WebHeaderCollection();
string url = "https://idmsa.apple.com/appleauth/auth/supportpin";
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", Apple_Widget_Key);
webHeaderCollection.AddWebHander("X-Apple-App-Id", Apple_Widget_Key);
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
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, authsigninConfig);
HttpResult webContent = getWebContent(url, "https://idmsa.apple.com/", webHeaderCollection, "application/json", "application/json");
if (webContent.StatusCode == HttpStatusCode.BadRequest || webContent.StatusCode == HttpStatusCode.Unauthorized)
{
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(webContent.Html);
if (serviceErrorsModel != null)
{
if (serviceErrorsModel.validationErrors != null && serviceErrorsModel.validationErrors.Length != 0)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "PIN失败异常:" + serviceErrorsModel.validationErrors[0].message);
return false;
}
if (serviceErrorsModel.service_errors != null && serviceErrorsModel.service_errors.Length != 0)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "PIN失败异常:" + serviceErrorsModel.service_errors[0].message);
return false;
}
if (serviceErrorsModel.serviceErrors != null && serviceErrorsModel.serviceErrors.Length != 0)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "PIN失败异常:" + serviceErrorsModel.serviceErrors[0].message);
return false;
}
}
}
if (webContent.StatusCode == HttpStatusCode.OK)
{
Dictionary<string, string> dataSource = Tools.Todejosn<Dictionary<string, string>>(webContent.Html);
string dicVal = dataSource.getDicVal("pin", "");
string dicVal2 = dataSource.getDicVal("localizedDate", "");
action?.Invoke(base.noticeKey, DisplyType.xinxi, "PIN码获取成功");
authSupportpin = "支持 PIN" + dicVal + ",有效期:" + dicVal2;
action?.Invoke(base.noticeKey, DisplyType.xiaofeiriqiNow, authSupportpin);
string[] allKeys = webContent.Header.AllKeys;
foreach (string text in allKeys)
{
if (text == "scnt")
{
handelDic.TryAddDic(text, webContent.Header[text]);
}
}
return true;
}
return false;
}
private bool verifyAuthQuestions(AothQuestions questions, string[] question, int retry = 0)
{
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 = Tools.Toenjson(questions);
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", Apple_Widget_Key);
webHeaderCollection.AddWebHander("X-Apple-App-Id", 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-Auth-Attributes", handelDic.getDicVal("X-Apple-Auth-Attributes", ""));
addOAuthHanede(webHeaderCollection, authsigninConfig);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
string url = "https://idmsa.apple.com/appleauth/auth/verify/questions";
HttpResult httpResult = postWebContent(url, postData, authUrl, webHeaderCollection);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.NoContent)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密保验证成功");
return true;
}
if (httpResult.StatusCode == HttpStatusCode.PreconditionFailed)
{
string[] allKeys = httpResult.Header.AllKeys;
foreach (string text in allKeys)
{
switch (text)
{
case "X-Apple-Repair-Session-Token":
case "X-Apple-ID-Session-Id":
case "scnt":
case "X-Apple-OAuth-Context":
handelDic.TryAddDic(text, httpResult.Header[text]);
break;
}
}
if (httpResult.Header.AllKeys.Contains("X-Apple-ID-Account-Country"))
{
XAppleIDAccountCountry_SOUSUO = httpResult.Header["X-Apple-ID-Account-Country"].ToString();
XAppleIDAccountCountry = AppleUtlis.GetAreaByCode(httpResult.Header["X-Apple-ID-Account-Country"].ToString());
action?.Invoke(base.noticeKey, DisplyType.area, XAppleIDAccountCountry);
}
return repair();
}
return false;
}
acount.isAccountException = true;
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密保验证失败:" + serviceError);
if (serviceError.Contains("发生未知错误") && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return verifyAuthQuestions(questions, question, retry + 1);
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "未知异常或者密保错误");
}
return false;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "非正常密保问题,无法识别");
return false;
}
private bool repair()
{
action?.Invoke(base.noticeKey, 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);
string uRL = "https://appleid.apple.com/widget/account/repair?widgetKey=" + apple_Widget_Key + "&rv=1&language=" + text;
HttpItem httpItem = new HttpItem
{
URL = uRL,
Method = "get",
Timeout = 120000,
ReadWriteTimeout = 30000,
UserAgent = base.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/",
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 = Tools.Todejosn<AvailableSecurityQuestions>(text2);
}
}
catch (Exception ex)
{
APIUtlis.ApiSeriveError(ex);
}
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(base.noticeKey, DisplyType.xinxi, "协议获取成功");
return options();
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "协议获取失败");
return false;
}
private bool options(bool skieprderPrivacy = false)
{
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-OAuth-Context", handelDic.getDicVal("X-Apple-OAuth-Context", ""));
string dicVal = handelDic.getDicVal("X-Apple-Session-Token", "");
if (string.IsNullOrEmpty(dicVal))
{
dicVal = handelDic.getDicVal("X-Apple-Repair-Session-Token", "");
}
webHeaderCollection.AddWebHander("X-Apple-Session-Token", dicVal);
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.getDicVal("repairSessionId", ""));
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", apple_Widget_Key);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.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 = base.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" || text2 == "scnt")
{
handelDic.TryAddDic(text2, httpReuslt.Header[text2]);
}
}
Dictionary<string, object> dictionary = Tools.Todejosn<Dictionary<string, object>>(httpReuslt.Html);
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)
{
int num = Tools.ToNetWorkInt(ConfigUtlis.getConfigValue("comNetworkConfig"), 0);
if (AppSysConfig.getConfig("oldAccountApply") == "1" && base.openVpn && num == 0)
{
APIUtlis.ApiApplyAct(38, "查询老帐号");
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "需要设置账号#1");
return false;
}
if (string.IsNullOrEmpty(acount.newAppleId) || string.IsNullOrEmpty(acount.newApplePopPwd))
{
int num2 = Tools.ToNetWorkInt(ConfigUtlis.getConfigValue("comNetworkConfig"), 0);
if (AppSysConfig.getConfig("oldAccountApply") == "1" && base.openVpn && num2 == 0)
{
APIUtlis.ApiApplyAct(38, "查询老帐号");
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "需要设置账号#2");
return false;
}
if (!setAccnount(acount.newAppleId, acount.newApplePopPwd, Apple_Widget_Key))
{
return false;
}
}
if (text3 == "weak_password")
{
if (_changeItem == null)
{
int num3 = Tools.ToNetWorkInt(ConfigUtlis.getConfigValue("comNetworkConfig"), 0);
if (AppSysConfig.getConfig("oldAccountApply") == "1" && base.openVpn && num3 == 0)
{
APIUtlis.ApiApplyAct(38, "查询老帐号");
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "需要设置新密码#2");
return false;
}
if (string.IsNullOrEmpty(_changeItem.newPwd))
{
int num4 = Tools.ToNetWorkInt(ConfigUtlis.getConfigValue("comNetworkConfig"), 0);
if (AppSysConfig.getConfig("oldAccountApply") == "1" && base.openVpn && num4 == 0)
{
APIUtlis.ApiApplyAct(38, "查询老帐号");
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "需要设置新密码#2");
return false;
}
if (!setWeakPassword(_changeItem.newPwd))
{
return false;
}
}
if (text3 == "missing_data")
{
if (_changeItem == null)
{
int num5 = Tools.ToNetWorkInt(ConfigUtlis.getConfigValue("comNetworkConfig"), 0);
if (AppSysConfig.getConfig("oldAccountApply") == "1" && base.openVpn && num5 == 0)
{
APIUtlis.ApiApplyAct(38, "查询老帐号");
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "需要设置生日#1");
return false;
}
if (string.IsNullOrEmpty(_changeItem.newshengri))
{
int num6 = Tools.ToNetWorkInt(ConfigUtlis.getConfigValue("comNetworkConfig"), 0);
if (AppSysConfig.getConfig("oldAccountApply") == "1" && base.openVpn && num6 == 0)
{
APIUtlis.ApiApplyAct(38, "查询老帐号");
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "需要设置生日#2");
return false;
}
if (!setBirthday(_changeItem.newshengri))
{
return false;
}
isVieyBirthday = true;
}
if (text3 == "challenge_response")
{
if (_changeItem == null)
{
int num7 = Tools.ToNetWorkInt(ConfigUtlis.getConfigValue("comNetworkConfig"), 0);
if (AppSysConfig.getConfig("oldAccountApply") == "1" && base.openVpn && num7 == 0)
{
APIUtlis.ApiApplyAct(38, "查询老帐号");
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "需要设置密保#1");
return false;
}
if (string.IsNullOrEmpty(_changeItem.newQt1))
{
int num8 = Tools.ToNetWorkInt(ConfigUtlis.getConfigValue("comNetworkConfig"), 0);
if (AppSysConfig.getConfig("oldAccountApply") == "1" && base.openVpn && num8 == 0)
{
APIUtlis.ApiApplyAct(38, "查询老帐号");
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "需要设置密保#2");
return false;
}
if (!setQuestions(_changeItem.newQt1, _changeItem.newQt2, _changeItem.newQt3))
{
return false;
}
isViey = true;
}
if (!(text3 == "phoneNumber") || SkipPhoneNumber())
{
if (!(text3 == "crossBorderPrivacyConsent") || skieprderPrivacy)
{
if (text3 == "privacy_consent" && !accept())
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "协议阅读失败#2");
return false;
}
continue;
}
bool gcbdCrossBorderPrivacyConsentRequired = false;
bool appleCrossBorderPrivacyConsentRequired = false;
try
{
dynamic val = dictionary["repairContext"];
gcbdCrossBorderPrivacyConsentRequired = val["privacyConsentRequirement"]["gcbdCrossBorderPrivacyConsentRequired"];
appleCrossBorderPrivacyConsentRequired = val["privacyConsentRequirement"]["appleCrossBorderPrivacyConsentRequired"];
}
catch (Exception)
{
}
CrossBorderPrivacyConsent(gcbdCrossBorderPrivacyConsentRequired, appleCrossBorderPrivacyConsentRequired);
return options(skieprderPrivacy: true);
}
return false;
}
if (string.IsNullOrEmpty(acount.moblie))
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "请先导入手机号码");
return false;
}
getSecurityUpgrade();
return OpenHsa2Act(_changeItem.mode, _changeItem.countryCode, Apple_Widget_Key);
}
}
return complete();
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "协议获取失败#2(" + (int)httpReuslt.StatusCode + ")");
return false;
}
public bool OpenHsa2Act(string mode, string countryCode, string widgetWey, int attemptCout = 0, int retry = 0)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "发送验证码中.." + attemptCout);
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", widgetWey);
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
webHeaderCollection.AddWebHander("X-Apple-Skip-Repair-Attributes", "[]");
webHeaderCollection.AddWebHander("X-Apple-OAuth-Context", handelDic.getDicVal("X-Apple-OAuth-Context", ""));
if (handelDic.ContainsKey("X-Apple-Session-Token"))
{
webHeaderCollection.AddWebHander("X-Apple-Session-Token", handelDic["X-Apple-Session-Token"]);
}
if (handelDic.ContainsKey("repairSessionId"))
{
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
}
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
string moblie = acount.moblie;
if (acount.moblie == "18888888888")
{
lock (lockSendMsmObj)
{
string text = getCodeAct_?.Invoke(acount.appleId, 9);
if (string.IsNullOrEmpty(text))
{
return false;
}
acount.moblie = text;
action?.Invoke(base.noticeKey, DisplyType.bindMoblie, text);
}
}
string text2 = string.Empty;
int msmId = 0;
lock (lockSendMsmObj)
{
if (!objSendMsmS.ContainsKey(acount.moblie))
{
objSendMsmS.Add(acount.moblie, new object());
}
}
if (moblie != "18888888888")
{
objSendMsmS[acount.moblie] = lockSendMsmObj;
}
lock (objSendMsmS[acount.moblie])
{
string text3 = "https://appleid.apple.com/account/security/upgrade/verify/phone";
string text4 = "{\"phoneNumberVerification\":{\"phoneNumber\":{\"number\":\"" + acount.moblie + "\",\"countryCode\":\"" + countryCode + "\"},\"mode\":\"" + mode + "\"}}";
if (incompatibleDevice)
{
text3 += "?warnings=incompatible_device";
text4 = text4.Substring(0, text4.Length - 1) + ",\"acceptedWarnings\":[\"incompatible_device\"]}";
}
HttpResult httpResult = putWebContent(text3, text4, "https://appleid.apple.com/widget/account/repair?widgetKey=af1139274f266b22b68c2a3e7ad932cb3c0bbe854e13a79af78dcc73136882c3&rv=1&language=zh_CN_CHN", webHeaderCollection);
if (httpResult.StatusCode == (HttpStatusCode)423)
{
dynamic val = Tools.Todejosn<object>(httpResult.Html);
string text5 = val["phoneNumberVerification"]?["serviceErrors"]?[0]["message"];
action?.Invoke(base.noticeKey, DisplyType.xinxi, "失败,异常:" + text5);
if (moblie == "18888888888" && attemptCout < 3)
{
if (text5.Contains("发送验证码的次数过多"))
{
return false;
}
getCodeAct_?.Invoke(acount.moblie, 10);
acount.moblie = "18888888888";
Thread.Sleep(2000);
return OpenHsa2Act(mode, countryCode, widgetWey, attemptCout + 1);
}
return false;
}
if (httpResult.StatusCode == HttpStatusCode.BadRequest || httpResult.StatusCode == HttpStatusCode.Unauthorized)
{
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (httpResult.Html.Contains("电话号码的使用次数过多") && moblie == "18888888888" && attemptCout < 5)
{
acount.moblie = "18888888888";
getCodeAct_?.Invoke(acount.moblie, 10);
Thread.Sleep(2000);
return OpenHsa2Act(mode, countryCode, widgetWey, attemptCout + 1);
}
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "发送验证码失败:" + serviceError);
if (serviceError.Contains("发生未知错误") && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return OpenHsa2Act(mode, countryCode, widgetWey, attemptCout + 1, retry + 1);
}
}
return false;
}
if (httpResult.StatusCode != HttpStatusCode.OK)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "发送验证码失败,未知异常");
return false;
}
string[] allKeys = httpResult.Header.AllKeys;
foreach (string text6 in allKeys)
{
if (text6 == "X-Apple-Session-Token" || text6 == "scnt")
{
handelDic.TryAddDic(text6, httpResult.Header[text6]);
}
}
dynamic val2 = Tools.Todejosn<object>(httpResult.Html);
msmId = val2["phoneNumberVerification"]?["phoneNumber"]?["id"];
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证码发送成功");
text2 = getCodeAct_?.Invoke("请输入账号:" + acount.appleId + ",\n发送至 <" + acount.moblie + "> 的验证码", 1);
if (text2 == null || string.IsNullOrEmpty(text2))
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证码未输入");
return false;
}
if (text2.Trim().Length != 6)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证码输入不正确");
return false;
}
}
return verifyCode(msmId, text2, acount.moblie, countryCode, mode, widgetWey);
}
public bool verifyCode(int msmId, string code, string moblie, string countryCode, string mode, string widgetWey, int retry = 0)
{
action?.Invoke(base.noticeKey, 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-OAuth-Context", handelDic.getDicVal("X-Apple-OAuth-Context", ""));
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(base.userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
string text = "{\"phoneNumberVerification\":{\"phoneNumber\":{\"id\":" + msmId + ",\"number\":\"" + moblie + "\",\"countryCode\":\"" + countryCode + "\",\"nonFTEU\":true},\"securityCode\":{\"code\":\"" + code + "\"},\"mode\":\"" + mode + "\"}}";
string text2 = "https://appleid.apple.com/account/security/upgrade";
if (incompatibleDevice)
{
text2 += "?warnings=incompatible_device";
text = text.Substring(0, text.Length - 1) + ",\"acceptedWarnings\":[\"incompatible_device\"]}";
}
HttpResult httpResult = postWebContent(text2, text, "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[] allKeys = httpResult.Header.AllKeys;
foreach (string text3 in allKeys)
{
if (text3 == "X-Apple-Session-Token" || text3 == "scnt")
{
handelDic.TryAddDic(text3, httpResult.Header[text3]);
}
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "双重开启成功");
AuthenDoubleOpenState = true;
acount.isHsa2 = true;
acount.moblie = moblie;
action?.Invoke(base.noticeKey, DisplyType.bindMoblie, moblie);
return true;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证失败,未知异常");
return false;
}
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "开启失败:" + serviceError);
if (serviceError.Contains("发生未知错误") && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return verifyCode(msmId, code, moblie, countryCode, mode, widgetWey, retry + 1);
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "开启失败,未知异常");
}
return false;
}
public bool setAccnount(string newAccount, string popPwd, string newwidgKey, int retry = 0)
{
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.getDicVal("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-OAuth-Context", handelDic.getDicVal("X-Apple-OAuth-Context", ""));
if (handelDic.ContainsKey("repairSessionId"))
{
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
}
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.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);
UpdateScnt(httpResult.Header);
if (httpResult.StatusCode != HttpStatusCode.BadRequest && httpResult.StatusCode != HttpStatusCode.Unauthorized)
{
if (httpResult.StatusCode == HttpStatusCode.OK)
{
string[] allKeys = httpResult.Header.AllKeys;
foreach (string text in allKeys)
{
if (text == "X-Apple-Session-Token" || text == "scnt")
{
handelDic.TryAddDic(text, httpResult.Header[text]);
}
}
string text2 = "";
Verification verification = Tools.Todejosn<Verification>(httpResult.Html);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "邮件验证码发送成功");
Thread.Sleep(new Random().Next(AppSysConfig.CheckCodeDelay * 1000, AppSysConfig.CheckCodeDelay * 1000 + 1000));
int num = 0;
do
{
if (taskState.isRun)
{
num++;
using 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 = Tools.Todejosn<Dictionary<string, string>>(html.Html);
if (dictionary["code"] == "1")
{
text2 = dictionary["vieyCode"];
if (!string.IsNullOrEmpty(text2))
{
break;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证码获取第" + num + "次,失败");
goto IL_03e1;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证码获取第" + num + "次,失败");
goto IL_03e1;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证码获取第" + num + "次,失败");
goto IL_03e1;
}
throw new Exception("停止执行");
IL_03e1:
Thread.Sleep(5000);
}
while (num < 5);
if (!string.IsNullOrEmpty(text2))
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "验证码获取成功");
return setAccountName(newAccount, verification?.verificationId, text2);
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "获取验证码失败超过最大次数");
return false;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "发送邮件验证码失败,未知异常");
return false;
}
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "发送验证码异常:" + serviceError);
if (serviceError.Contains("发生未知错误") && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return setAccnount(newAccount, popPwd, newwidgKey, retry + 1);
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "发送邮件验证码失败,未知异常");
}
return false;
}
public bool setAccountName(string accountName, string verificationId, string answer, int retry = 0)
{
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"]);
}
if (handelDic.ContainsKey("repairSessionId"))
{
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
}
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.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)
{
string[] allKeys = httpResult.Header.AllKeys;
foreach (string text in allKeys)
{
if (text == "X-Apple-Session-Token" || text == "scnt")
{
handelDic.TryAddDic(text, httpResult.Header[text]);
}
}
applyAtion?.Invoke(base.noticeKey, DisplyType.newAccount, accountName);
appleId = accountName;
acount.appleId = accountName;
action?.Invoke(base.noticeKey, DisplyType.xinxi, "新账号设置成功");
isChangAppleId = true;
return true;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "新账号设置失败,未知异常:" + (int)httpResult.StatusCode);
return false;
}
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "新账号设置异常:" + serviceError);
if (serviceError.Contains("发生未知错误") && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return setAccountName(accountName, verificationId, answer, retry + 1);
}
}
return false;
}
public bool setBirthday(string newBirthday, int retry = 0)
{
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-OAuth-Context", handelDic.getDicVal("X-Apple-OAuth-Context", ""));
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-ID-Session-Id", handelDic["repairSessionId"]);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.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)
{
string[] allKeys = httpResult.Header.AllKeys;
foreach (string text in allKeys)
{
if (text == "X-Apple-Session-Token" || text == "scnt")
{
handelDic.TryAddDic(text, httpResult.Header[text]);
}
}
applyAtion?.Invoke(base.noticeKey, DisplyType.shengri, newBirthday);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "生日设置成功");
return true;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "生日修改设置失败,未知异常");
return false;
}
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "生日修改设置异常:" + serviceError);
if (serviceError.Contains("发生未知错误") && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return setBirthday(newBirthday, retry + 1);
}
return false;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "生日修改设置失败");
return false;
}
public bool setWeakPassword(string newPwd, int retry = 0)
{
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-OAuth-Context", handelDic.getDicVal("X-Apple-OAuth-Context", ""));
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-ID-Session-Id", handelDic["repairSessionId"]);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.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)
{
string[] allKeys = httpResult.Header.AllKeys;
foreach (string text in allKeys)
{
if (text == "X-Apple-Session-Token" || text == "scnt")
{
handelDic.TryAddDic(text, httpResult.Header[text]);
}
}
acount.applePwd = newPwd;
isPwdViey = true;
_changeItem.newPwd = "";
applyAtion?.Invoke(base.noticeKey, DisplyType.mima, newPwd);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "新密码设置成功");
return true;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "新密码设置失败,未知异常");
return false;
}
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "新密码设置异常:" + serviceError);
if (serviceError.Contains("发生未知错误") && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return setWeakPassword(newPwd, retry + 1);
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "新密码设置失败,未知异常");
}
return false;
}
private bool accept()
{
action?.Invoke(base.noticeKey, 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-OAuth-Context", handelDic.getDicVal("X-Apple-OAuth-Context", ""));
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-ID-Session-Id", handelDic["repairSessionId"]);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
string uRL = "https://appleid.apple.com/account/manage/privacy/accept";
HttpItem httpItem = new HttpItem
{
URL = uRL,
Method = "put",
UserAgent = base.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;
}
string[] allKeys = httpReuslt.Header.AllKeys;
foreach (string text in allKeys)
{
if (text == "X-Apple-Session-Token" || text == "scnt")
{
handelDic.TryAddDic(text, httpReuslt.Header[text]);
}
}
return true;
}
private bool setQuestions(string newqt1, string newqt2, string newqt3, int retry = 0)
{
string text = "";
if (securityQuestions != null)
{
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 = Tools.Toenjson(new Dictionary<string, AothQuestions> { { "security", aothQuestions } });
}
else
{
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-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-OAuth-Context", handelDic.getDicVal("X-Apple-OAuth-Context", ""));
webHeaderCollection.AddWebHander("X-Apple-Session-Token", handelDic["X-Apple-Session-Token"]);
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
HttpResult httpResult = putWebContent("https://appleid.apple.com/account/manage/repair/questions", text, "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[] allKeys = httpResult.Header.AllKeys;
foreach (string text2 in allKeys)
{
if (text2 == "X-Apple-Session-Token" || text2 == "scnt")
{
handelDic.TryAddDic(text2, httpResult.Header[text2]);
}
}
applyAtion?.Invoke(base.noticeKey, DisplyType.qt1, newqt1);
applyAtion?.Invoke(base.noticeKey, DisplyType.qt2, newqt2);
applyAtion?.Invoke(base.noticeKey, DisplyType.qt3, newqt3);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密保修改成功");
return true;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密保修改失败,未知异常");
return false;
}
ServiceErrorsModel serviceErrorsModel = Tools.Todejosn<ServiceErrorsModel>(httpResult.Html);
if (serviceErrorsModel != null)
{
string serviceError = getServiceError(serviceErrorsModel);
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密保修改异常:" + serviceError);
if (serviceError.Contains("发生未知错误") && retry < base.MaxRetryCount)
{
Thread.Sleep(3000);
if (retry != 0)
{
base.ProxyIp = "";
}
return setQuestions(newqt1, newqt2, newqt3, retry + 1);
}
}
else
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密保修改失败");
}
return false;
}
public bool CrossBorderPrivacyConsent(bool gcbdCrossBorderPrivacyConsentRequired, bool appleCrossBorderPrivacyConsentRequired, int retry = 0)
{
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"]);
}
if (handelDic.ContainsKey("repairSessionId"))
{
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
}
webHeaderCollection.AddWebHander("X-Apple-OAuth-Context", handelDic.getDicVal("X-Apple-OAuth-Context", ""));
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
string postData = "{\"account\":{\"preferences\":{\"privacyPreferences\":{\"appleCrossBorderPrivacyNoticeAccepted\":true}}},\"completedSteps\":[],\"requiredSteps\":[\"crossBorderPrivacyConsent\"],\"repairContext\":{\"repairType\":\"crossBorderPrivacyConsent\",\"repairItems\":[\"crossBorderPrivacyConsent\"]}}";
if (gcbdCrossBorderPrivacyConsentRequired)
{
postData = "{\"account\":{\"preferences\":{\"privacyPreferences\":{\"gcbdCrossBorderPrivacyNoticeAccepted\":true}}},\"completedSteps\":[],\"requiredSteps\":[\"crossBorderPrivacyConsent\"],\"repairContext\":{\"repairType\":\"crossBorderPrivacyConsent\",\"repairItems\":[\"crossBorderPrivacyConsent\"]}}";
}
if (gcbdCrossBorderPrivacyConsentRequired && appleCrossBorderPrivacyConsentRequired)
{
postData = "{\"account\":{\"preferences\":{\"privacyPreferences\":{\"appleCrossBorderPrivacyNoticeAccepted\":true,\"gcbdCrossBorderPrivacyNoticeAccepted\":true}}},\"completedSteps\":[],\"requiredSteps\":[\"crossBorderPrivacyConsent\"],\"repairContext\":{\"repairType\":\"crossBorderPrivacyConsent\",\"repairItems\":[\"crossBorderPrivacyConsent\"]}}";
}
if (postWebContent("https://appleid.apple.com/account/manage/repair/privacy/consent", postData, "https://appleid.apple.com/", webHeaderCollection).StatusCode == HttpStatusCode.OK)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "同意数据隐私协议");
return true;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "跳过隐私协议失败");
if (retry == 0)
{
return CrossBorderPrivacyConsent(gcbdCrossBorderPrivacyConsentRequired, appleCrossBorderPrivacyConsentRequired, retry + 1);
}
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"]);
}
if (handelDic.ContainsKey("repairSessionId"))
{
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["repairSessionId"]);
}
webHeaderCollection.AddWebHander("X-Apple-OAuth-Context", handelDic.getDicVal("X-Apple-OAuth-Context", ""));
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.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(base.noticeKey, DisplyType.xinxi, "跳过手机号码成功");
return true;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "跳过手机号码失败");
return false;
}
private bool complete()
{
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
string text = "";
if (handelDic.ContainsKey("scnt2"))
{
text = handelDic["scnt2"];
}
webHeaderCollection.AddWebHander("X-Apple-Domain-Id", "1");
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
if (string.IsNullOrEmpty(text) && handelDic.ContainsKey("scnt"))
{
text = handelDic["scnt"];
}
webHeaderCollection.AddWebHander("scnt", text);
if (handelDic.ContainsKey("X-Apple-ID-Session-Id"))
{
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic.getDicVal("X-Apple-ID-Session-Id", ""));
}
else if (handelDic.ContainsKey("repairSessionId"))
{
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic.getDicVal("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-Session-Token"]);
webHeaderCollection.AddWebHander("Origin", "https://idmsa.apple.com");
webHeaderCollection.AddWebHander("X-Apple-Widget-Key", apple_Widget_Key);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.userAgent);
webHeaderCollection.AddWebHander("X-Apple-I-FD-Client-Info", appleIFDClientInfo);
webHeaderCollection.AddWebHander("X-Apple-Auth-Attributes", handelDic.getDicVal("X-Apple-Auth-Attributes", ""));
addOAuthHanede(webHeaderCollection, authsigninConfig);
string uRL = "https://idmsa.apple.com/appleauth/auth/repair/complete";
HttpItem httpItem = new HttpItem
{
URL = uRL,
Method = "post",
UserAgent = base.userAgent,
Cookie = listCookie.toFonmtCookie(),
ContentType = "application/json; charset=utf-8",
Accept = "application/json, text/javascript, */*; q=0.01",
Referer = "https://idmsa.apple.com/",
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(base.noticeKey, 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(base.noticeKey, DisplyType.area, AppleUtlis.GetAreaByCode(httpReuslt.Header["X-Apple-ID-Account-Country"].ToString()));
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "协议阅读成功");
return true;
}
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("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-OAuth-Context", handelDic.getDicVal("X-Apple-OAuth-Context", ""));
webHeaderCollection.AddWebHander("X-Apple-ID-Session-Id", handelDic["X-Apple-ID-Session-Id"]);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.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 = Tools.Todejosn<SecurityUpgradeModel>(html);
action?.Invoke(base.noticeKey, DisplyType.shengri, securityUpgradeModel.account.security.birthday);
if (!string.IsNullOrEmpty(securityUpgradeModel.account.security.birthday) && securityUpgradeModel.account.security.birthday.Split('-').Length == 3 && (string.IsNullOrEmpty(acount.birthday) || acount.birthday != securityUpgradeModel.account.security.birthday))
{
acount.birthday = securityUpgradeModel.account.security.birthday;
}
action?.Invoke(base.noticeKey, DisplyType.guojia, securityUpgradeModel.account.person.primaryAddress.countryName);
}
if (webJsonContent.Html.Contains("incompatible_device"))
{
incompatibleDevice = true;
}
}
catch (Exception ex)
{
APIUtlis.ApiSeriveError(ex);
}
}
private bool authenticatePassword(string pwd)
{
string url = "https://appleid.apple.com/authenticate/password";
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.AddWebHander("X-Apple-Api-Key", base.apiKey);
webHeaderCollection.AddWebHander("X-Requested-With", "XMLHttpRequest");
webHeaderCollection.AddWebHander("X-Apple-Domain-Id", "1");
webHeaderCollection.AddWebHander("scnt", handelDic["scnt"]);
string appleIFDClientInfo = FDClientInfoHelp.getAppleIFDClientInfo(base.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(base.noticeKey, 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());
XAppleIDAccountCountry_SOUSUO = httpResult.Header["X-Apple-ID-Account-Country"].ToString();
action?.Invoke(base.noticeKey, DisplyType.area, XAppleIDAccountCountry);
}
}
return false;
}
action?.Invoke(base.noticeKey, DisplyType.xinxi, "密码错误");
return false;
}
public bool OpenAuthen(AppleAcount _acount, AppleChangeItem changeItem, Func<string, int, string> getCodeAct, string _noticeKey)
{
if (string.IsNullOrEmpty(base.ProxyIp))
{
base.ProxyIp = ProxyAccountCache.getProxyAccountIP(_acount.appleId);
}
acount = _acount;
base.noticeKey = _noticeKey;
appleId = _acount.appleId;
_changeItem = changeItem;
initUserAgent();
authsigninConfig = new AuthsigninConfig
{
Apple_Widget_Key = Apple_Widget_Key,
authUrl = authUrl,
homeLanguage = homeLanguage,
iframeId = iframeId,
redirectURI = redirectURI
};
listCookie.Add(new CookieItem
{
Key = "idclient",
Value = "web"
});
appleId = acount.appleId;
_changeItem = changeItem;
getCodeAct_ = getCodeAct;
openHsa2 = true;
try
{
bool flag;
if (LoginWeb() && (flag = appleauthAuth(acount)))
{
if (flag && !AuthenDoubleOpenState)
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "登录成功");
ProxyAccountCache.addProxyIp(acount.appleId, base.ProxyIp);
if (intoHome())
{
if (string.IsNullOrEmpty(acount.moblie))
{
action?.Invoke(base.noticeKey, DisplyType.xinxi, "请先导入手机号码");
return false;
}
getSecuritydevices();
AuthenDoubleOpenState = OpenHsa2Act(_changeItem.mode, _changeItem.countryCode, base.apiKey);
}
}
return AuthenDoubleOpenState;
}
}
catch (Exception ex)
{
APIUtlis.ApiSeriveError(ex);
action?.Invoke(base.noticeKey, DisplyType.xinxi, ex.Message);
}
return false;
}
protected new 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 = base.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);
}
Array.Clear(bytes, 0, bytes.Length);
return httpReuslt;
}
protected new 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 = base.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 DeleteWebContent(url, putData, referer, webHeader, accept);
}
Array.Clear(bytes, 0, bytes.Length);
return httpReuslt;
}
public new HttpResult postWebContent(string url, string postData, string referer, WebHeaderCollection webHeader = null, string accept = "application/json, text/javascript, */*; q=0.01", string contentType = "application/json", int RetryTimes = 0)
{
byte[] bytes = Encoding.UTF8.GetBytes(postData);
HttpItem httpItem = new HttpItem
{
URL = url,
Method = "POST",
UserAgent = base.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);
}
if (httpReuslt.StatusCode == HttpStatusCode.BadRequest && RetryTimes < 2 && string.IsNullOrEmpty(httpReuslt.Html))
{
if (RetryTimes == 1)
{
base.ProxyIp = "";
}
Thread.Sleep(3000 * (RetryTimes + 1));
return postWebContent(url, postData, referer, webHeader, accept, contentType, RetryTimes + 1);
}
Array.Clear(bytes, 0, bytes.Length);
return httpReuslt;
}
public void initUserAgent()
{
if (!string.IsNullOrEmpty(base.ProxyIp))
{
return;
}
ProxyAccountModel proxyAccountInfo = ProxyAccountCache.getProxyAccountInfo(acount.appleId);
if (proxyAccountInfo != null)
{
base.ProxyIp = proxyAccountInfo.ProxyIp;
if (string.IsNullOrEmpty(proxyAccountInfo.accountWebUserAgent))
{
proxyAccountInfo.accountWebUserAgent = base.userAgent;
}
else
{
base.userAgent = proxyAccountInfo.accountWebUserAgent;
}
}
}
}
}