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

125 lines
3.8 KiB
C#

using System;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Windows.Forms;
using AppleBatch_June.Properties;
using DotNet.Utilities;
namespace AppleBatch_June
{
public class ApiNetReq
{
private static readonly object reqObj = new object();
public static string host { get; set; } = "";
private static int reqCount { get; set; } = new Random().Next(0, 90);
public static int startNowFun { get; set; } = 0;
public void Transpond(HttpItem httpItem)
{
httpItem.Header = null;
httpItem.ProtocolVersion = null;
httpItem.WebProxy = null;
string postdata = Tools.Toenjson(httpItem);
HttpItem item = new HttpItem
{
URL = "http://localhost:5000/home/Transpond",
Method = "post",
Postdata = postdata,
UserAgent = "liuyeu_AppleBatch_June",
ContentType = "application/json",
Timeout = 35000,
KeepAlive = true
};
new HttpHelper().GetHtml(item);
}
public HttpResult doPost(object postData, string type, bool retry = false)
{
MessageBox.Show(postData.ToString());
using HttpHelper httpHelper = new HttpHelper();
Stopwatch stopwatch = Stopwatch.StartNew();
string text = "";
lock (reqObj)
{
if (reqCount >= 99)
{
reqCount = 0;
}
reqCount++;
text = (Tools.GenerateTimeStamp() + reqCount + AppSysConfig.uid.ToString().PadLeft(4, '0') + reqCount).PadLeft(16, '0');
}
if (text.Length > 16)
{
text = text.Substring(text.Length - 16, 16);
}
string mD5_ = Tools.GetMD5_32(AppSysConfig.saffMac + "by六月的风");
string key = "7a588e60045849a1";
string text2 = "90e7b0dc3ef2134c";
string text3 = DESEncrypt.Encrypt(Tools.a(Tools.Toenjson(postData), key, text, operation: false, text2), text, text2).Trim();
string text4 = "authentiString=" + HttpUtility.UrlEncode(Tools.EncodeBase64(Encoding.UTF8.GetBytes(text3)));
string mD5_2 = Tools.GetMD5_32(text3 + type + mD5_ + "by六月的风_联系qq:1023092054");
WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
webHeaderCollection.Add("timestamp", text);
webHeaderCollection.Add("mac", mD5_);
webHeaderCollection.Add("startNowFun", startNowFun.ToString());
if (!string.IsNullOrEmpty(AppSysConfig.userToken))
{
string s = DESEncrypt.Encrypt(AppSysConfig.userToken, text, text2).Trim();
webHeaderCollection.Add("token", HttpUtility.UrlEncode(Tools.EncodeBase64(Encoding.UTF8.GetBytes(s))));
}
webHeaderCollection.Add("version", FormLogin.versions);
HttpItem httpItem = new HttpItem();
httpItem.URL = host + "/AppleClientApi/requestApi";
httpItem.Method = "post";
httpItem.Postdata = text4 + "&sign=" + mD5_2 + "&type=" + type;
httpItem.Headers["User-Agent"] = "liuyeu_AppleBatch_June";
httpItem.ContentType = "application/x-www-form-urlencoded";
httpItem.Header = webHeaderCollection;
httpItem.Timeout = 35000;
httpItem.KeepAlive = true;
HttpItem httpItem2 = httpItem;
HttpResult html = httpHelper.GetHtml(httpItem2);
MessageBox.Show(html.Html.ToString());
stopwatch.Stop();
if (html.StatusCode == HttpStatusCode.OK)
{
if (html.Header.AllKeys.Contains("sign"))
{
string text5 = html.Header["sign"];
if (Tools.GetMD5_32("abc_" + html.Html + text + "by六月的风_联系qq:1023092054") != text5)
{
html.Html = "";
html.StatusCode = HttpStatusCode.NotFound;
}
}
else
{
html.Html = "";
html.StatusCode = HttpStatusCode.NotFound;
}
}
else if ((html.StatusCode == HttpStatusCode.NotFound || html.StatusCode == (HttpStatusCode)0) && !retry)
{
return doPost(postData, type, retry: true);
}
APIUtlis.AppRequestHtml(html.Html);
APIUtlis.requestUrl = "ApiNetReq_" + type;
if (httpItem2 != null)
{
httpItem2.Postdata = string.Empty;
}
httpItem2 = null;
return html;
}
}
}