mirror of
https://git.oceanpay.cc/danial/kami_itunes_june.git
synced 2025-12-18 22:31:24 +00:00
835 lines
34 KiB
C#
835 lines
34 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Net;
|
||
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
using System.Threading;
|
||
using AppleBatch_June.Model;
|
||
using AppleBatch_June.Utils;
|
||
using DotNet.Utilities;
|
||
|
||
namespace AppleBatch_June.ExecuteTasks
|
||
{
|
||
public class iCloundUtils : AppleNetworkBase
|
||
{
|
||
public List<CookieItem> listCookie = new List<CookieItem>();
|
||
|
||
public string parentAccount { get; set; } = "";
|
||
|
||
|
||
public iCloundUtils(ITaskRunState _taskState, string _notyKey, Action<string, DisplyType, string> _action = null, bool _OpenVpn = false)
|
||
: base(_taskState, _notyKey, _action, _OpenVpn)
|
||
{
|
||
_ = new string[2] { "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/600.1.3 (KHTML, like Gecko)", "com.apple.iCloudHelper/203 CFNetwork/708.1 Darwin/14.0.0 (x86_64)" };
|
||
}
|
||
|
||
public bool iCloudVerifyauthen(string appleid, string password, string autoMoblie, NasQualifyModel nasQualify, Func<string, int, string> getCodeAct_, ref string errmess, ref string icMsmCode)
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "正在获取验证码...");
|
||
string postData = createAppleIdTermsPlist(appleid, password);
|
||
string url = "https://setup.icloud.com/setup/iosbuddy/ui/existingAppleIdTermsUI";
|
||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||
dictionary.Add("X-MMe-Client-Info", nasQualify.clientInfo);
|
||
string value = new Regex("OS;([\\s\\S]*?)>").Match(nasQualify.clientInfo).Groups[1].Value;
|
||
string text = "12B411";
|
||
if (value.Split(';').Length == 2)
|
||
{
|
||
text = value.Split(';')[1];
|
||
}
|
||
HttpResult httpResult = postiCloudWebContext(url, postData, "", "iOS iPhone " + text + " iPhone Setup Assistant", dictionary);
|
||
if (httpResult.StatusCode == HttpStatusCode.OK)
|
||
{
|
||
string value2 = new Regex("session=\"([\\s\\S]*?)\"").Match(httpResult.Html).Groups[1].Value;
|
||
string value3 = new Regex("url=\"([\\s\\S]*?)\"").Match(httpResult.Html).Groups[1].Value;
|
||
if (!string.IsNullOrEmpty(value2))
|
||
{
|
||
string text2 = getCodeAct_?.Invoke(autoMoblie, 11);
|
||
if (string.IsNullOrEmpty(text2) || !(autoMoblie == text2))
|
||
{
|
||
errmess = "手机号码获取失败:" + text2;
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, errmess);
|
||
return false;
|
||
}
|
||
action?.Invoke(base.notyKey, DisplyType.bindMoblie, text2);
|
||
HttpResult httpResult2 = APIUtlis.QueryInfo(base.appleId, password, "balance");
|
||
if (!httpResult2.Html.Contains("密码错误"))
|
||
{
|
||
httpResult2 = APIUtlis.QueryInfo(base.appleId, password, "balance");
|
||
}
|
||
if (httpResult2.StatusCode == HttpStatusCode.OK)
|
||
{
|
||
if (httpResult2.Html.Contains("密码错误"))
|
||
{
|
||
string text3 = getCodeAct_?.Invoke("请输入账号:" + appleid + ",\n发送至 <" + autoMoblie + "> 的验证码", 15);
|
||
if (text3 == null || string.IsNullOrEmpty(text3))
|
||
{
|
||
ItunesUtlis itunesUtlis = new ItunesUtlis(taskState, base.appleId, action, openVpn);
|
||
string msgReust = "";
|
||
itunesUtlis.appleLogin(base.appleId, password, 1, ref msgReust, out var _);
|
||
if (msgReust.Contains("密码错误"))
|
||
{
|
||
text3 = getCodeAct_?.Invoke("请输入账号:" + appleid + ",\n发送至 <" + autoMoblie + "> 的验证码", 16);
|
||
}
|
||
if (text3 == null || string.IsNullOrEmpty(text3))
|
||
{
|
||
errmess = "icloud的验证码未输入";
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, errmess);
|
||
return false;
|
||
}
|
||
}
|
||
if (text3.Trim().Length != 6)
|
||
{
|
||
errmess = "验证码输入不正确";
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, errmess);
|
||
return false;
|
||
}
|
||
string postData2 = createSmsAccountRepair(text3, value2);
|
||
string url2 = "https://setup.icloud.com" + value3;
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "提交验证码...");
|
||
HttpResult httpResult3 = postiCloudWebContext(url2, postData2, "", "iOS iPhone " + text + " iPhone Setup Assistant", dictionary);
|
||
if (httpResult3.StatusCode == HttpStatusCode.OK)
|
||
{
|
||
if (httpResult3.Html.Contains("session="))
|
||
{
|
||
icMsmCode = text3;
|
||
errmess = "验证成功";
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "验证成功..");
|
||
return true;
|
||
}
|
||
string value4 = new Regex("message=\"([\\s\\S]*?)\"").Match(httpResult3.Html).Groups[1].Value;
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, value4);
|
||
errmess = value4;
|
||
return false;
|
||
}
|
||
errmess = "验证失败...";
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, errmess);
|
||
return false;
|
||
}
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "ic登录双重发送失败:" + httpResult2.Html);
|
||
return false;
|
||
}
|
||
errmess = "验证码发送失败...";
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, errmess);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
errmess = "双重验证码加载失败.";
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, errmess);
|
||
}
|
||
return false;
|
||
}
|
||
|
||
public bool ActioniCloud(string appleid, string password, string XMmeNasQualify, string clientInfo, string newClientid, ref string localizedError, bool isAgree = false, string icMsmCode = "")
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "正在处理..");
|
||
string url = "https://setup.icloud.com/setup/login_or_create_account";
|
||
string referer = "https://setup.icloud.com/setup/login_or_create_account";
|
||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||
dictionary.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(appleid + ":" + password + icMsmCode)));
|
||
dictionary.Add("X-MMe-Client-Info", clientInfo);
|
||
dictionary.Add("X-MMe-Country", "CN");
|
||
dictionary.Add("X-Mme-Nas-Qualify", XMmeNasQualify);
|
||
if (listCookie.Where((CookieItem c) => c.Key == "X-iCloud-HSA-Token").FirstOrDefault() != null)
|
||
{
|
||
dictionary.Add("X-Apple-MD-M", "");
|
||
dictionary.Add("X-Apple-MD", "");
|
||
}
|
||
string postData = createActionPlist(appleid, password, newClientid);
|
||
HttpResult httpResult = postiCloudWebContext(url, postData, referer, "%E8%AE%BE%E7%BD%AE/1.0 CFNetwork/711.3.18 Darwin/14.0.0", dictionary);
|
||
localizedError = GetKeyValue("<key>localizedError</key>", "<string>", "</string>", httpResult.Html).Trim();
|
||
if (localizedError == "MOBILEME_CREATE_UNAVAILABLE")
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "激活已到最大次数.");
|
||
return false;
|
||
}
|
||
if (localizedError == "UNAUTHORIZED")
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "账号或密码错误.");
|
||
return false;
|
||
}
|
||
if (httpResult.StatusCode == HttpStatusCode.Conflict && !isAgree && localizedError == "MOBILEME_TERMS_OF_SERVICE_UPDATE")
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "正在获取协议...");
|
||
string url2 = "https://setup.icloud.com/setup/iosbuddy/ui/genericTermsUI";
|
||
dictionary.Remove("X-Mme-Nas-Qualify");
|
||
StringBuilder stringBuilder = new StringBuilder();
|
||
stringBuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<plist version=\"1.0\">\n<dict>\n");
|
||
stringBuilder.Append("\t<key>format</key>\n\t<string>plist/buddyml</string>\n");
|
||
stringBuilder.Append("\t<key>terms</key>\n\t<array>\n\t\t<dict>\n\t\t<key>name</key>\n\t\t<string>iCloud</string>\n\t\t</dict>\n\t</array>\n");
|
||
string postData2 = stringBuilder.Append("</dict>\n</plist>").ToString();
|
||
HttpResult httpResult2 = postiCloudWebContext(url2, postData2, referer, "%E8%AE%BE%E7%BD%AE/1.0 CFNetwork/711.1.12 Darwin/14.0.0", dictionary);
|
||
if (httpResult2.StatusCode == HttpStatusCode.OK)
|
||
{
|
||
string token = AppleNetworkBase.GetToken(httpResult2.Html, "agreeUrl=\"", "\"");
|
||
if (!string.IsNullOrEmpty(token))
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "正在同意协议...");
|
||
if (postiCloudWebContext(token, "", referer, "%E8%AE%BE%E7%BD%AE/1.0 CFNetwork/711.1.12 Darwin/14.0.0", dictionary).StatusCode == HttpStatusCode.OK)
|
||
{
|
||
return ActioniCloud(appleid, password, XMmeNasQualify, clientInfo, newClientid, ref localizedError, isAgree: true);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (httpResult.StatusCode == HttpStatusCode.OK)
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "获取激活状态...");
|
||
string keyValue = GetKeyValue("<key>dsPrsID</key>", "<string>", "</string>", httpResult.Html);
|
||
string keyValue2 = GetKeyValue("<key>mmeAuthToken</key>", "<string>", "</string>", httpResult.Html);
|
||
string keyValue3 = GetKeyValue("<key>aDsID</key>", "<string>", "</string>", httpResult.Html);
|
||
_ = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(keyValue + ":" + keyValue2));
|
||
AppleiCloundLogin cloundLogin = new AppleiCloundLogin
|
||
{
|
||
account = appleid,
|
||
pwd = password,
|
||
dsid = keyValue,
|
||
mmeAuthToken = keyValue2,
|
||
clientInfo = clientInfo,
|
||
userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/600.1.3 (KHTML, like Gecko)"
|
||
};
|
||
Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
|
||
dictionary2.Add("X-Apple-ADSID", keyValue3);
|
||
HttpResult jsoniCloudWebContext = getJsoniCloudWebContext("https://setup.icloud.com/setup/icd/migrate/status", "", cloundLogin, dictionary2);
|
||
if (jsoniCloudWebContext.StatusCode == HttpStatusCode.OK && GetKeyValue("<key>status</key>", "<string>", "</string>", jsoniCloudWebContext.Html) == "SUCCEEDED")
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "激活成功");
|
||
action?.Invoke(base.notyKey, DisplyType.forbidden, "激活成功");
|
||
APIUtlis.ApiApplyAct(40, "激活iCloud");
|
||
return true;
|
||
}
|
||
}
|
||
string text = GetKeyValue("<key>message</key>", "<string>", "</string>", httpResult.Html);
|
||
action?.Invoke(base.notyKey, DisplyType.error, "失败");
|
||
if (string.IsNullOrEmpty(text))
|
||
{
|
||
text = localizedError;
|
||
}
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, text);
|
||
return false;
|
||
}
|
||
|
||
public NasQualifyModel GetNasQualifyInfo(int nasType)
|
||
{
|
||
int num = 0;
|
||
do
|
||
{
|
||
num++;
|
||
Dictionary<string, string> dictionary = APIUtlis.ApiNasQualify(nasType);
|
||
if (dictionary == null)
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "数据加载中..." + num);
|
||
if (num < 50)
|
||
{
|
||
Thread.Sleep(3000);
|
||
}
|
||
else
|
||
{
|
||
Thread.Sleep(1500);
|
||
}
|
||
continue;
|
||
}
|
||
if (dictionary.Count <= 0)
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "数据加载中..." + num);
|
||
if (num < 50)
|
||
{
|
||
Thread.Sleep(3000);
|
||
}
|
||
else
|
||
{
|
||
Thread.Sleep(1500);
|
||
}
|
||
continue;
|
||
}
|
||
string nasQualify = dictionary["nasQualify"];
|
||
string userAgent = dictionary["userAgent"];
|
||
string clientInfo = dictionary["clientInfo"];
|
||
string postData = dictionary["postData"];
|
||
return new NasQualifyModel
|
||
{
|
||
clientInfo = clientInfo,
|
||
nasQualify = nasQualify,
|
||
postData = postData,
|
||
userAgent = userAgent
|
||
};
|
||
}
|
||
while (num < 120 && taskState.isRun);
|
||
return null;
|
||
}
|
||
|
||
public AppleiCloundLogin loginDelegates(string appleid, string password, int type)
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "正在处理.");
|
||
HttpResult isLogin = APIUtlis.getIsLogin(type);
|
||
if (isLogin.StatusCode == HttpStatusCode.OK)
|
||
{
|
||
dynamic val = Tools.Todejosn<object>(isLogin.Html);
|
||
if (val["Code"] == "0000")
|
||
{
|
||
if (val["Data"]["integral"] >= AppSysConfig.getTypeById(type).consNum)
|
||
{
|
||
AppleiCloundLogin loginIdUserInfo = iCloudAccountLoginCache.getLoginIdUserInfo(appleid.Trim(), password.Trim());
|
||
if (loginIdUserInfo != null)
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.area, loginIdUserInfo.Area);
|
||
action?.Invoke(base.notyKey, DisplyType.lostBillNo, loginIdUserInfo.dsid);
|
||
return loginIdUserInfo;
|
||
}
|
||
if (string.IsNullOrEmpty(base.ProxyIp))
|
||
{
|
||
base.ProxyIp = ProxyAccountCache.getProxyAccountIP(appleid);
|
||
}
|
||
string url = "https://setup.icloud.com/setup/iosbuddy/loginDelegates";
|
||
string referer = "https://setup.icloud.com/setup/iosbuddy/loginDelegates";
|
||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||
dictionary.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(appleid + ":" + password)));
|
||
string config = AppSysConfig.getConfig("iCloudClientInfo");
|
||
dictionary.Add("X-MMe-Client-Info", config);
|
||
dictionary.Add("X-MMe-Country", "CN");
|
||
string postData = createLoginPlist(appleid, password);
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "正在登录.");
|
||
HttpResult httpResult = postiCloudWebContext(url, postData, referer, "Accounts/113 CFNetwork/711.2.23 Darwin/14.0.0", dictionary);
|
||
if (httpResult.StatusCode == HttpStatusCode.OK)
|
||
{
|
||
if (GetKeyValue("<key>status</key>", "<integer>", "</integer>", httpResult.Html) == "1")
|
||
{
|
||
string keyValue = GetKeyValue("<key>status-message</key>", "<string>", "</string>", httpResult.Html);
|
||
if (keyValue.Contains("incorrectly"))
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "账号密码错误,或需要输入双重验证码");
|
||
return null;
|
||
}
|
||
string[] array = AppSysConfig.getConfig("UnactivatedKey").Split('|');
|
||
bool flag = false;
|
||
string[] array2 = array;
|
||
foreach (string value in array2)
|
||
{
|
||
if (keyValue.Contains(value))
|
||
{
|
||
string keyValue2 = GetKeyValue("<key>dsid</key>", "<string>", "</string>", httpResult.Html);
|
||
string areaByArea = AppleUtlis.GetAreaByArea(GetKeyValue("<key>region-id</key>", "<string>R:", "</string>", httpResult.Html));
|
||
action?.Invoke(base.notyKey, DisplyType.area, areaByArea);
|
||
action?.Invoke(base.notyKey, DisplyType.lostBillNo, keyValue2);
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "未激活iCloud账户");
|
||
APIUtlis.ApiApplyAct(39, "激活iCloud查询");
|
||
flag = true;
|
||
}
|
||
}
|
||
if (!flag)
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, keyValue);
|
||
}
|
||
return null;
|
||
}
|
||
string keyValue3 = GetKeyValue("<key>region-id</key>", "<string>R:", "</string>", httpResult.Html);
|
||
string keyValue4 = GetKeyValue("<key>dsid</key>", "<string>", "</string>", httpResult.Html);
|
||
string areaByArea2 = AppleUtlis.GetAreaByArea(keyValue3);
|
||
string keyValue5 = GetKeyValue("<key>handles</key>", "<array>", "</array>", httpResult.Html);
|
||
if (!string.IsNullOrEmpty(keyValue5))
|
||
{
|
||
int count = Regex.Matches(keyValue5, "5051").Count;
|
||
int num = Tools.ToInt(AppSysConfig.getConfig("iCloudStatus5051Count"), 1);
|
||
if (count >= num)
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.area, areaByArea2);
|
||
action?.Invoke(base.notyKey, DisplyType.lostBillNo, keyValue4);
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "未激活iCloud账户");
|
||
APIUtlis.ApiApplyAct(39, "激活iCloud查询");
|
||
return null;
|
||
}
|
||
}
|
||
string keyValue6 = GetKeyValue("<key>mmeAuthToken</key>", "<string>", "</string>", httpResult.Html);
|
||
action?.Invoke(base.notyKey, DisplyType.area, areaByArea2);
|
||
action?.Invoke(base.notyKey, DisplyType.lostBillNo, keyValue4);
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "登录成功.");
|
||
loginIdUserInfo = new AppleiCloundLogin
|
||
{
|
||
account = appleid,
|
||
pwd = password,
|
||
dsid = keyValue4,
|
||
Area = areaByArea2,
|
||
mmeAuthToken = keyValue6,
|
||
clientInfo = "<MacBook Pro> <Mac OS X;10.10;14A314h> <com.apple.AOSKit/203 (com.apple.systempreferences/14.0)>",
|
||
userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/600.1.3 (KHTML, like Gecko)"
|
||
};
|
||
iCloudAccountLoginCache.addReddemUserInfo(appleid, loginIdUserInfo);
|
||
ProxyAccountCache.addProxyIp(appleid, base.ProxyIp);
|
||
return loginIdUserInfo;
|
||
}
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "登录失败...");
|
||
}
|
||
else
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, val["Message"]);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, val["Message"]);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "网络请求失败");
|
||
}
|
||
return null;
|
||
}
|
||
|
||
public bool getFamilyDetails(AppleiCloundLogin cloundLogin, iCloundUtils icloud, bool retry = false)
|
||
{
|
||
string text = "https://setup.icloud.com/setup/family/getFamilyDetails";
|
||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||
dictionary.Add("X-MMe-LoggedIn-AppleID", cloundLogin.account);
|
||
HttpResult jsoniCloudWebContext = getJsoniCloudWebContext(text, text, cloundLogin, dictionary);
|
||
if (jsoniCloudWebContext.StatusCode == HttpStatusCode.OK)
|
||
{
|
||
if (GetKeyValue("<key>is-member-of-family</key>", "<", "/>", jsoniCloudWebContext.Html).ToLower() == "false")
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xiaofeiriqiNow, "未加入家庭共享");
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "查询完成");
|
||
}
|
||
else
|
||
{
|
||
string text2 = "";
|
||
string keyValue = GetKeyValue("<key>family-members</key>", "<array>", "</array>", jsoniCloudWebContext.Html);
|
||
foreach (Match item in new Regex("<dict>([\\s\\S]*?)</dict>").Matches(keyValue))
|
||
{
|
||
string value = item.Groups[1].Value;
|
||
string keyValue2 = GetKeyValue("<key>member-display-label</key>", "<string>", "</string>", value);
|
||
string keyValue3 = GetKeyValue("<key>member-dsid</key>", "<integer>", "</integer>", value);
|
||
string keyValue4 = GetKeyValue("<key>member-apple-id</key>", "<string>", "</string>", value);
|
||
GetKeyValue("<key>member-last-name</key>", "<string>", "</string>", value);
|
||
string text3 = keyValue2;
|
||
if (GetKeyValue("<key>member-is-parent-account</key>", "<", "/>", value).ToLower() == "true")
|
||
{
|
||
parentAccount = keyValue4;
|
||
}
|
||
text3 = ((!(keyValue4.ToLower() != cloundLogin.account.ToLower().Trim())) ? (text3 + "(此账号)") : (text3 + "(" + keyValue4 + "[Dsid:" + keyValue3 + "])"));
|
||
text3 += ",";
|
||
text2 += text3;
|
||
}
|
||
action?.Invoke(base.notyKey, DisplyType.xiaofeiriqiNow, text2.TrimEnd(','));
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "查询完成");
|
||
}
|
||
return true;
|
||
}
|
||
if (!retry)
|
||
{
|
||
string account = cloundLogin.account;
|
||
string pwd = cloundLogin.pwd;
|
||
iCloudAccountLoginCache.removeReddemUserInfo(cloundLogin.account, cloundLogin.StdndbyKeyGuid);
|
||
cloundLogin = icloud.loginDelegates(account, pwd, 31);
|
||
if (cloundLogin != null)
|
||
{
|
||
return getFamilyDetails(cloundLogin, icloud, retry: true);
|
||
}
|
||
}
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "查询失败,网络请求失败");
|
||
return false;
|
||
}
|
||
|
||
public bool createFamily(AppleiCloundLogin cloundLogin, string organizerAppleId, string AppleIdForPurchases, string AppleIdForPurchasesPassword)
|
||
{
|
||
string url = "https://setup.icloud.com/setup/mac/family/createFamily";
|
||
string referer = "https://setup.icloud.com/setup/mac/family/setupFamilyUI";
|
||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||
dictionary.Add("X-MMe-LoggedIn-AppleID", cloundLogin.account);
|
||
string postData = Tools.Toenjson(new CreateFamilyPostModel
|
||
{
|
||
organizerAppleId = organizerAppleId,
|
||
organizerAppleIdForPurchases = AppleIdForPurchases,
|
||
organizerAppleIdForPurchasesPassword = AppleIdForPurchasesPassword,
|
||
organizerShareMyLocationEnabledDefault = true,
|
||
iTunesTosVersion = 284005
|
||
});
|
||
HttpResult httpResult = postJsoniCloudWebContext(url, postData, referer, cloundLogin, dictionary);
|
||
if (httpResult.StatusCode == HttpStatusCode.OK)
|
||
{
|
||
dynamic val = Tools.Todejosn<object>(httpResult.Html);
|
||
if ((int)val["status"] == 0)
|
||
{
|
||
string text = val["family"]["familyId"];
|
||
action?.Invoke(base.notyKey, DisplyType.forbidden, "成功");
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, " 开通成功,家庭ID=" + text);
|
||
return true;
|
||
}
|
||
string token = AppleNetworkBase.GetToken(httpResult.Html, "status-message\":\"", "\"");
|
||
action?.Invoke(base.notyKey, DisplyType.error, "失败");
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, token);
|
||
if (token.Contains("有效的付款方式"))
|
||
{
|
||
iCloudAccountLoginCache.removeReddemUserInfo(cloundLogin.account, cloundLogin.StdndbyKeyGuid);
|
||
}
|
||
return false;
|
||
}
|
||
if (httpResult.StatusCode == (HttpStatusCode)422)
|
||
{
|
||
string text2 = Tools.Unicode2String(AppleNetworkBase.GetToken(httpResult.Html, "status-message\":\"", "\""));
|
||
action?.Invoke(base.notyKey, DisplyType.error, "失败");
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, text2);
|
||
if (text2.Contains("有效的付款方式"))
|
||
{
|
||
iCloudAccountLoginCache.removeReddemUserInfo(cloundLogin.account, cloundLogin.StdndbyKeyGuid);
|
||
}
|
||
return false;
|
||
}
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, " 开通失败,未知错误");
|
||
return false;
|
||
}
|
||
|
||
public bool leaveFamily(AppleiCloundLogin cloundLogin)
|
||
{
|
||
string url = "https://setup.icloud.com/setup/mac/family/leaveFamily";
|
||
string referer = "https://setup.icloud.com/setup/mac/family/setupFamilyUI";
|
||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||
dictionary.Add("X-MMe-LoggedIn-AppleID", cloundLogin.account);
|
||
string postData = "";
|
||
HttpResult httpResult = postJsoniCloudWebContext(url, postData, referer, cloundLogin, dictionary);
|
||
if (httpResult.StatusCode == HttpStatusCode.OK)
|
||
{
|
||
dynamic val = Tools.Todejosn<object>(httpResult.Html);
|
||
if ((int)val["status"] == 0)
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.forbidden, "成功");
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "家庭共享,关闭成功");
|
||
return true;
|
||
}
|
||
string token = AppleNetworkBase.GetToken(httpResult.Html, "status-message\":\"", "\"");
|
||
action?.Invoke(base.notyKey, DisplyType.error, "失败");
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, token);
|
||
return false;
|
||
}
|
||
if (httpResult.StatusCode == (HttpStatusCode)422)
|
||
{
|
||
string token2 = AppleNetworkBase.GetToken(httpResult.Html, "status-message\":\"", "\"");
|
||
action?.Invoke(base.notyKey, DisplyType.error, "失败");
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, token2);
|
||
return false;
|
||
}
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, " 关闭失败,未知错误");
|
||
return false;
|
||
}
|
||
|
||
public bool removeFamilyMember(AppleiCloundLogin cloundLogin, string Dsid)
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, " 正在移除..");
|
||
HttpResult httpResult = APIUtlis.serviceSend(Tools.Toenjson(new Dictionary<string, object>
|
||
{
|
||
{
|
||
"Authorization",
|
||
Convert.ToBase64String(Encoding.UTF8.GetBytes(cloundLogin.dsid + ":" + cloundLogin.mmeAuthToken))
|
||
},
|
||
{ "Dsid", Dsid },
|
||
{ "type", "IRemoveFamilyMember" },
|
||
{ "userAgent", cloundLogin.userAgent }
|
||
}));
|
||
if (httpResult.StatusCode == HttpStatusCode.OK)
|
||
{
|
||
dynamic val = Tools.Todejosn<object>(httpResult.Html);
|
||
if (val["Code"] == "0000")
|
||
{
|
||
dynamic val2 = val["Data"];
|
||
dynamic val3 = Tools.Todejosn<object>(val2);
|
||
string text = val3["msg"];
|
||
if (text == "0000")
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, " 移除成功");
|
||
action?.Invoke(base.notyKey, DisplyType.forbidden, "成功");
|
||
return true;
|
||
}
|
||
action?.Invoke(base.notyKey, DisplyType.error, "失败");
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, text);
|
||
return false;
|
||
}
|
||
}
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "请求错误");
|
||
return false;
|
||
}
|
||
|
||
public bool addFamilyMember(AppleiCloundLogin cloundLogin, string appleId, string password, string verificationToken)
|
||
{
|
||
string url = "https://setup.icloud.com/setup/mac/family/addFamilyMember";
|
||
string referer = "https://setup.icloud.com/setup/mac/family/setupFamilyUI";
|
||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||
dictionary.Add("X-MMe-LoggedIn-AppleID", cloundLogin.account);
|
||
string postData = Tools.Toenjson(new AddFamilyMemberPostModel
|
||
{
|
||
appleId = appleId,
|
||
password = password,
|
||
appleIdForPurchases = appleId,
|
||
shareMyLocationEnabledDefault = true,
|
||
shareMyPurchasesEnabledDefault = true,
|
||
verificationToken = verificationToken,
|
||
preferredAppleId = appleId
|
||
});
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, " 正在添加成员.");
|
||
HttpResult httpResult = postJsoniCloudWebContext(url, postData, referer, cloundLogin, dictionary);
|
||
if (httpResult.StatusCode == HttpStatusCode.OK)
|
||
{
|
||
dynamic val = Tools.Todejosn<object>(httpResult.Html);
|
||
if ((int)val["status"] == 0)
|
||
{
|
||
object[] obj = val["familyMembers"];
|
||
string text = "";
|
||
object[] array = obj;
|
||
foreach (dynamic val2 in array)
|
||
{
|
||
if (((string)val2["appleId"]).ToLower() == appleId.ToLower())
|
||
{
|
||
text = val2["dsid"];
|
||
break;
|
||
}
|
||
}
|
||
action?.Invoke(base.notyKey, DisplyType.forbidden, "成功");
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "添加成功,成员dsid:" + text);
|
||
return true;
|
||
}
|
||
string text2 = Tools.Unicode2String(AppleNetworkBase.GetToken(httpResult.Html, "status-message\":\"", "\""));
|
||
action?.Invoke(base.notyKey, DisplyType.error, "失败");
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "失败:" + text2);
|
||
if (text2.Contains("有效的付款方式"))
|
||
{
|
||
iCloudAccountLoginCache.removeReddemUserInfo(cloundLogin.account, cloundLogin.StdndbyKeyGuid);
|
||
}
|
||
return false;
|
||
}
|
||
if (httpResult.StatusCode == (HttpStatusCode)422)
|
||
{
|
||
string text3 = Tools.Unicode2String(AppleNetworkBase.GetToken(httpResult.Html, "status-message\":\"", "\""));
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, text3);
|
||
action?.Invoke(base.notyKey, DisplyType.error, "失败");
|
||
if (text3.Contains("有效的付款方式"))
|
||
{
|
||
iCloudAccountLoginCache.removeReddemUserInfo(cloundLogin.account, cloundLogin.StdndbyKeyGuid);
|
||
}
|
||
return false;
|
||
}
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, " 添加失败,未知错误");
|
||
return false;
|
||
}
|
||
|
||
public iCloudVerifyCVVModel getiTunesAccountPaymentInfo(AppleiCloundLogin cloundLogin)
|
||
{
|
||
string url = "https://setup.icloud.com/setup/mac/family/getiTunesAccountPaymentInfo";
|
||
string referer = "https://setup.icloud.com/setup/mac/family/addFamilyMemberUI";
|
||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||
dictionary.Add("X-MMe-LoggedIn-AppleID", cloundLogin.account);
|
||
string postData = Tools.Toenjson(new getiTunesAccountPaymentInfoPostModel
|
||
{
|
||
organizerDSID = cloundLogin.dsid,
|
||
userAction = "ADDING_FAMILY_MEMBER",
|
||
sendSMS = true
|
||
});
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, " 查询付款信息..");
|
||
HttpResult httpResult = postJsoniCloudWebContext(url, postData, referer, cloundLogin, dictionary);
|
||
if (httpResult.StatusCode == HttpStatusCode.OK)
|
||
{
|
||
dynamic val = Tools.Todejosn<object>(httpResult.Html);
|
||
if ((int)val["status"] == 0)
|
||
{
|
||
string text = val["creditCardType"];
|
||
if (text == "无")
|
||
{
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, "账号没有支付方式");
|
||
return null;
|
||
}
|
||
string creditCardLastFourDigits = val["creditCardLastFourDigits"];
|
||
string verificationType = val["verificationType"];
|
||
string billingType = val["billingType"];
|
||
return new iCloudVerifyCVVModel
|
||
{
|
||
billingType = billingType,
|
||
creditCardId = text,
|
||
creditCardLastFourDigits = creditCardLastFourDigits,
|
||
verificationType = verificationType
|
||
};
|
||
}
|
||
string token = AppleNetworkBase.GetToken(httpResult.Html, "title\":\"", "\"");
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, token);
|
||
return null;
|
||
}
|
||
if (httpResult.StatusCode == (HttpStatusCode)422)
|
||
{
|
||
string arg = Tools.Unicode2String(AppleNetworkBase.GetToken(httpResult.Html, "title\":\"", "\""));
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, arg);
|
||
return null;
|
||
}
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, " 付款信息查询失败,未知错误");
|
||
return null;
|
||
}
|
||
|
||
public string verifyCVV(AppleiCloundLogin cloundLogin, iCloudVerifyCVVModel cVVModel)
|
||
{
|
||
string url = "https://setup.icloud.com/setup/mac/family/verifyCVV";
|
||
string referer = "https://setup.icloud.com/setup/mac/family/setupFamilyUI";
|
||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||
dictionary.Add("X-MMe-LoggedIn-AppleID", cloundLogin.account);
|
||
string postData = Tools.Toenjson(cVVModel);
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, " 验证安全码..");
|
||
HttpResult httpResult = postJsoniCloudWebContext(url, postData, referer, cloundLogin, dictionary);
|
||
if (httpResult.StatusCode == HttpStatusCode.OK)
|
||
{
|
||
string token = AppleNetworkBase.GetToken(httpResult.Html, "verificationToken\":\"", "\"");
|
||
if (string.IsNullOrEmpty(token))
|
||
{
|
||
Action<string, DisplyType, string> obj = action;
|
||
if (obj == null)
|
||
{
|
||
return token;
|
||
}
|
||
obj(base.notyKey, DisplyType.xinxi, "验证付款方式失败");
|
||
}
|
||
return token;
|
||
}
|
||
if (httpResult.StatusCode == (HttpStatusCode)422)
|
||
{
|
||
string arg = Tools.Unicode2String(AppleNetworkBase.GetToken(httpResult.Html, "title\":\"", "\""));
|
||
action?.Invoke(base.notyKey, DisplyType.xinxi, arg);
|
||
}
|
||
return "";
|
||
}
|
||
|
||
private string createAppleIdTermsPlist(string appleId, string applePwd)
|
||
{
|
||
StringBuilder stringBuilder = new StringBuilder();
|
||
stringBuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<plist version=\"1.0\">\n<dict>\n");
|
||
stringBuilder.Append("\t\t<key>apple-id</key>\n\t\t<string>" + appleId + "</string>\n");
|
||
stringBuilder.Append("\t\t<key>password</key>\n\t\t<string>" + applePwd + "</string>\n");
|
||
stringBuilder.Append("</dict>\n</plist>");
|
||
return stringBuilder.ToString();
|
||
}
|
||
|
||
private string createSmsAccountRepair(string securityCode, string session)
|
||
{
|
||
StringBuilder stringBuilder = new StringBuilder();
|
||
stringBuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<plist version=\"1.0\">\n<dict>\n");
|
||
stringBuilder.Append("\t\t<key>security-code</key>\n\t\t<string>" + securityCode + "</string>\n");
|
||
stringBuilder.Append("\t<key>serverInfo</key>\n\t<dict>\n\t\t<key>session</key>\n\t\t<string>" + session + "</string>\n\t</dict>\n");
|
||
stringBuilder.Append("</dict>\n</plist>");
|
||
return stringBuilder.ToString();
|
||
}
|
||
|
||
private string createActionPlist(string appleId, string applePwd, string newClientid)
|
||
{
|
||
StringBuilder stringBuilder = new StringBuilder();
|
||
stringBuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<plist version=\"1.0\">\n<dict>\n");
|
||
stringBuilder.Append("\t<key>protocolVersion</key>\n\t<string>1.0</string>\n");
|
||
stringBuilder.Append("\t<key>userInfo</key>\n\t<dict>\n\t\t<key>client-id</key>\n\t\t<string>" + newClientid + "</string>\n\t\t<key>language</key>\n\t\t<string>zh-Hans</string>\n\t\t<key>timezone</key>\n\t\t<string>Asia/Chongqing</string>\n\t</dict>\n");
|
||
stringBuilder.Append("</dict>\n</plist>");
|
||
return stringBuilder.ToString();
|
||
}
|
||
|
||
private string createLoginPlist(string appleId, string applePwd)
|
||
{
|
||
string text = "348F2E20-CED5-41EA-BE2E-F589028EA985";
|
||
StringBuilder stringBuilder = new StringBuilder();
|
||
stringBuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<plist version=\"1.0\">\n\t<dict>\n");
|
||
stringBuilder.Append("\t\t<key>apple-id</key>\n\t\t<string>" + appleId + "</string>\n");
|
||
stringBuilder.Append("\t\t<key>client-id</key>\n\t\t<string>" + text + "</string>\n");
|
||
stringBuilder.Append("\t\t<key>delegates</key>\n\t\t<dict><key>com.apple.gamecenter</key>\n<dict/>\n<key>com.apple.mobileme</key>\n<dict/>\n<key>com.apple.private.ids</key>\n<dict>\n<key>protocol-version</key>\n<string>4</string>\n</dict> </dict>\n");
|
||
stringBuilder.Append("\t\t<key>password</key>\n\t\t<string>" + applePwd + "</string>\n");
|
||
stringBuilder.Append("\t</dict>\n</plist>");
|
||
return stringBuilder.ToString();
|
||
}
|
||
|
||
public HttpResult getJsoniCloudWebContext(string url, string referer, AppleiCloundLogin cloundLogin, Dictionary<string, string> hander)
|
||
{
|
||
if (cloundLogin == null)
|
||
{
|
||
throw new Exception("没有登录状态");
|
||
}
|
||
HttpItem httpItem = new HttpItem
|
||
{
|
||
URL = url,
|
||
Method = "get",
|
||
Timeout = 30000,
|
||
ReadWriteTimeout = 30000,
|
||
UserAgent = cloundLogin.userAgent,
|
||
Cookie = listCookie.toFonmtCookie(),
|
||
ContentType = "application/json; charset=UTF-8",
|
||
Accept = "*/*",
|
||
Referer = referer,
|
||
ProtocolVersion = HttpVersion.Version11,
|
||
KeepAlive = true,
|
||
ResultType = ResultType.String,
|
||
WebProxy = WebRequest.DefaultWebProxy
|
||
};
|
||
hander.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(cloundLogin.dsid + ":" + cloundLogin.mmeAuthToken)));
|
||
hander.Add("X-Mme-Client-Info", cloundLogin.clientInfo);
|
||
if (hander != null)
|
||
{
|
||
foreach (KeyValuePair<string, string> item in hander)
|
||
{
|
||
httpItem.Header.Add(item.Key, item.Value);
|
||
}
|
||
}
|
||
addHander(httpItem);
|
||
HttpResult httpReuslt = GetHttpReuslt(httpItem);
|
||
addCookle(httpReuslt.Cookie);
|
||
return httpReuslt;
|
||
}
|
||
|
||
public HttpResult postiCloudWebContext(string url, string postData, string referer, string userAgent, Dictionary<string, string> hander)
|
||
{
|
||
HttpItem httpItem = new HttpItem
|
||
{
|
||
URL = url,
|
||
Method = "post",
|
||
Timeout = 30000,
|
||
ReadWriteTimeout = 30000,
|
||
UserAgent = userAgent,
|
||
Cookie = listCookie.toFonmtCookie(),
|
||
ContentType = "application/x-apple-plist; Charset=UTF-8",
|
||
Accept = "*/*",
|
||
Referer = referer,
|
||
ProtocolVersion = HttpVersion.Version11,
|
||
KeepAlive = true,
|
||
Postdata = postData,
|
||
PostDataType = PostDataType.String,
|
||
ResultType = ResultType.String,
|
||
WebProxy = WebRequest.DefaultWebProxy
|
||
};
|
||
if (hander != null)
|
||
{
|
||
foreach (KeyValuePair<string, string> item in hander)
|
||
{
|
||
httpItem.Header.Add(item.Key, item.Value);
|
||
}
|
||
}
|
||
addHander(httpItem);
|
||
HttpResult httpReuslt = GetHttpReuslt(httpItem);
|
||
addCookle(httpReuslt.Cookie);
|
||
return httpReuslt;
|
||
}
|
||
|
||
protected void addCookle(string cookies)
|
||
{
|
||
if (cookies == null || string.IsNullOrEmpty(cookies.Trim()))
|
||
{
|
||
return;
|
||
}
|
||
foreach (CookieItem item in HttpCookieHelper.GetCookieList(cookies))
|
||
{
|
||
if (item.Key == "Max-Age" || item.Key == "Path" || item.Key == "Expires" || item.Key == "domain" || item.Key == "Domain" || item.Key == "path")
|
||
{
|
||
continue;
|
||
}
|
||
CookieItem cookieItem = listCookie.Where((CookieItem c) => c.Key == item.Key).FirstOrDefault();
|
||
if (cookieItem == null)
|
||
{
|
||
if (!string.IsNullOrEmpty(item.Value.Trim()))
|
||
{
|
||
listCookie.Add(item);
|
||
}
|
||
}
|
||
else if (!string.IsNullOrEmpty(item.Value.Trim()))
|
||
{
|
||
cookieItem.Value = item.Value.Trim();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|