Files
kami_itunes_june/AppleBatch_June/ApiNetReq.cs
danial 06b0fcce08 chore(build): 更新项目配置和依赖以支持.NET 8
- 在.settings.local.json中添加dotnet clean命令权限
- 更新项目文件以启用不安全的二进制序列化和禁用平台兼容性警告
- 配置调试和发布模式的编译常量及优化选项
- 在解决方案文件中升级Visual Studio版本并添加多平台配置
- 移除FormLogin构造函数中的MessageBox调试代码
- 为过时的WebRequest、WebClient和ServicePointManager API添加编译警告抑制
- 简化异常处理逻辑并在Program.cs中改进启动流程
- 移除多个未使用的局部变量声明
- 添加launchSettings.json以支持开发环境配置
- 在表单构造函数中初始化components容器
- 优化网络请求超时设置并改善错误处理机制
2025-11-10 19:34:27 +08:00

124 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)
{
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;
}
}
}