Files
kami_itunes_june/AppleBatch_June/FormRemovePay.cs
2024-07-22 00:43:14 +08:00

506 lines
18 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.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Web;
using System.Windows.Forms;
using AppleBatch_June.Model;
using DotNet.Utilities;
namespace AppleBatch_June
{
public class FormRemovePay : BaseForm
{
private IContainer components;
private TextBox textBox1;
private Label label6;
private GroupBox groupBox4;
private RichTextBox txtAppleId;
private GroupBox groupBox5;
private Button btnStopRemovePay;
private Button btnRemovePayLog;
private Button btnStartRemovePay;
private CheckBox ckRemovePayVpn;
private Label label5;
private Label labRemovePayDianShu;
private Label label31;
private GroupBox groupBox3;
private RichTextBox txtLog;
private ContextMenuStrip contextMenuStrip1;
private ToolStripMenuItem ToolStripMenuItem;
public FormRemovePay()
: base("移除支付方式", null)
{
InitializeComponent();
}
private void FormRemovePay_Load(object sender, EventArgs e)
{
labRemovePayDianShu.Text = AppSysConfig.getTypeById(19).consNum.ToString();
ckRemovePayVpn.Checked = ((ConfigUtlis.getConfigValue("ckRemovePayVpn") == "True") ? true : false);
}
public override void insertLog(string logText)
{
if (!base.IsHandleCreated || base.IsDisposed)
{
return;
}
try
{
BeginInvoke((Action)delegate
{
txtLog.Text = txtLog.Text.Insert(0, DateTime.Now.ToString("HH:mm:ss") + " " + logText + "\n");
});
}
catch (Exception)
{
}
}
private bool getPaymentList(ItunesUtlis utlis, AppleItunesLogin itunesLogin, AppleAcount acount, ref string reustMsg)
{
insertLog("查询支付方式");
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add("X-Apple-Store-Front", itunesLogin.software);
bool result = false;
string url = "https://p" + itunesLogin.ServerId + "-buy.itunes.apple.com/account/stackable/paymentInfos?managePayments=true&guid=" + itunesLogin.Guid + "&xToken=" + HttpUtility.UrlEncode(itunesLogin.xtoken);
HttpResult jsonItunesWebContext = utlis.getJsonItunesWebContext(url, "https://finance-app.itunes.apple.com/account/manage-payments", itunesLogin, dictionary, addToken: true);
if (jsonItunesWebContext.StatusCode == HttpStatusCode.OK)
{
PaymentList paymentList = Tools.Todejosn<PaymentList>(jsonItunesWebContext.Html);
PaymentList.Paymentinfo[] array = paymentList?.data?.attributes?.paymentInfos;
foreach (PaymentList.Paymentinfo paymentinfo in array)
{
if (paymentinfo.paymentMethodType != null && paymentinfo.paymentMethodType != "None")
{
insertLog("正在移除支付方式:" + paymentinfo.translatedDisplayNameForCC);
reustMsg += paymentinfo.translatedDisplayNameForCC;
if (DeletePayApply(utlis, paymentinfo.paymentId, itunesLogin, acount, ref reustMsg))
{
result = true;
insertLog(acount.appleId + ",移除成功:" + paymentinfo.translatedDisplayNameForCC);
}
reustMsg += ",";
}
}
if (paymentList != null)
{
int? num = paymentList.data?.attributes?.paymentInfos.Where((PaymentList.Paymentinfo c) => c.paymentMethodType != "None").Count();
int i = 0;
if ((num.GetValueOrDefault() == 0) & num.HasValue)
{
reustMsg += "没有支付方式需要移除";
insertLog(acount.appleId + ",没有支付方式需要移除");
return true;
}
}
}
return result;
}
private bool DeletePayApply(ItunesUtlis utlis, string paymentId, AppleItunesLogin itunesLogin, AppleAcount acount, ref string reustMsg)
{
string referer = "https://finance-app.itunes.apple.com/account/manage-payments/edit-payment/" + paymentId;
string url = "https://p" + itunesLogin.ServerId + "-buy.itunes.apple.com/account/stackable/paymentInfos/" + paymentId + "/delete?guid=" + itunesLogin.Guid;
string postData = "";
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add("X-Apple-Store-Front", "143465-19,12");
HttpResult httpResult = utlis.postItunesWebContext(url, postData, referer, itunesLogin, dictionary);
if (httpResult.StatusCode == HttpStatusCode.OK)
{
if (httpResult.Html.Contains("account.edit-billing-stackable"))
{
reustMsg += "移除成功";
return true;
}
Dictionary<string, object> dictionary2 = (dynamic)Tools.Todejosn<object>(httpResult.Html);
string text = "原因未知";
text = ((!dictionary2.ContainsKey("explanation")) ? httpResult.Html : ((string)(dynamic)dictionary2["explanation"]));
reustMsg += text;
insertLog(acount.appleId + ",移除失败:" + text);
}
else
{
insertLog("请求失败,未知错误");
}
return false;
}
private void btnStartRemovePay_Click(object sender, EventArgs e)
{
List<AppleAcount> list = AppleUtlis.accountInput(txtAppleId.Text.Trim());
if (list.Count == 0)
{
MessageBox.Show("请按正确格式输入ID");
return;
}
if (base.taskState.TaskIsRun)
{
MessageBox.Show("任务还没结束,请等待");
return;
}
insertLog("开始执行:数量:" + list.Count);
ConfigUtlis.saveConfigKey("ckRemovePayVpn", ckRemovePayVpn.Checked.ToString());
btnStartRemovePay.Enabled = false;
base.taskState.isRun = true;
int id = 19;
int count = list.Count;
if (AppSysConfig.integral < count * AppSysConfig.getTypeById(19).consNum)
{
MessageBox.Show("账号点数不足 , 执行账号数量:" + count + " ,至少需要 " + count * AppSysConfig.getTypeById(id).consNum + " 点数。");
}
else
{
startRemovePay(list, ckRemovePayVpn.Checked);
}
}
public async void startRemovePay(List<AppleAcount> appleId, bool startVpn)
{
base.taskState.isRun = true;
base.taskState.TaskIsRun = true;
AppleExecuteTask.TaskRunAppleIdCount = 0L;
AppleExecuteTask.TaskRunModels.Clear();
await Task.Run(delegate
{
string guid = Guid.NewGuid().ToString("n");
TaskRunModel taskRunModel = new TaskRunModel
{
guid = guid,
isRuning = false
};
AppleExecuteTask.TaskRunModels.Add(taskRunModel);
ApiNetReq.startNowFun = 19;
foreach (AppleAcount item in appleId)
{
try
{
if (!base.taskState.isRun)
{
break;
}
if (startRuning(taskRunModel, delegate(string appleid, DisplyType reustType, string dasReust2)
{
insertLog(dasReust2);
}, item.appleId))
{
string applePwd = item.applePwd;
ItunesUtlis utlis = new ItunesUtlis(base.taskState, item.appleId, delegate(string appleKey, DisplyType type, string reust)
{
insertLog(appleKey + "," + reust);
}, startVpn);
insertLog("正在登录" + item.appleId + ",密码:" + item.applePwd);
string msg = "";
AppleItunesLogin itunesLogin = getItunesLogin(startVpn, item, 19, utlis, ref msg);
if (msg.Contains("需要提供 Apple ID 验证码才能登录"))
{
insertLog("登录失败:" + msg);
object obj = Invoke((Func<string>)delegate
{
VerificationCodeFrom verificationCodeFrom = new VerificationCodeFrom();
verificationCodeFrom.AppleId = "Apple账号:" + item.appleId;
verificationCodeFrom.ShowDialog();
return verificationCodeFrom.reustCode;
});
if (obj.ToString().Length == 6)
{
insertLog("正在使用验证码登录");
item.applePwd += obj.ToString();
itunesLogin = getItunesLogin(startVpn, item, 19, utlis, ref msg);
}
}
if (itunesLogin != null)
{
insertLog("登录成功,国家:" + itunesLogin.Area);
string reustMsg = "";
if (getPaymentList(utlis, itunesLogin, item, ref reustMsg))
{
if (!reustMsg.Contains("没有支付方式需要移除"))
{
APIUtlis.ApiApplyAct(19, "移除支付方式");
}
if (base.IsHandleCreated)
{
BeginInvoke((Action)delegate
{
string[] array = txtAppleId.Text.Split('\n');
foreach (string text in array)
{
if (text.StartsWith(item.appleId))
{
txtAppleId.Text = txtAppleId.Text.Replace(text, "");
}
}
});
}
}
SqliteHelper.ExecuteInsert("itunes_db", new Dictionary<string, string>
{
{ "type", "removePay" },
{
"addTime",
Tools.GenerateTimeStamp().ToString()
},
{ "value1", item.appleId },
{ "value2", applePwd },
{ "value3", reustMsg }
});
}
else
{
insertLog("ID登录失败" + msg);
}
goto IL_0372;
}
}
catch (Exception ex)
{
APIUtlis.ApiSeriveError(ex);
insertLog("请求失败:" + ex.Message);
goto IL_0372;
}
continue;
IL_0372:
endRuning(taskRunModel);
}
});
AppleExecuteTask.TaskRunModels.Clear();
base.taskState.isRun = false;
base.taskState.TaskIsRun = false;
btnStartRemovePay.Enabled = true;
insertLog("执行结束");
}
private void btnStopRemovePay_Click(object sender, EventArgs e)
{
base.taskState.Stop();
insertLog("正在请求停止,请稍后");
}
private void btnRemovePayLog_Click(object sender, EventArgs e)
{
FromDBDataQuery fromDBDataQuery = new FromDBDataQuery();
fromDBDataQuery.sqlTitle = new Dictionary<string, string>
{
{ "value1", "账号|200" },
{ "value2", "密码|100" },
{ "value3", "信息|250" }
};
fromDBDataQuery.type = "removePay";
fromDBDataQuery.typeName = "Apple移除支付方式";
fromDBDataQuery.Show();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
IDataObject dataObject = Clipboard.GetDataObject();
if (dataObject.GetDataPresent(DataFormats.Text))
{
txtAppleId.Text = (string)dataObject.GetData(DataFormats.Text);
}
}
catch (Exception)
{
MessageBox.Show("粘贴失败");
}
}
private void FormRemovePay_FormClosing(object sender, FormClosingEventArgs e)
{
base.taskState.isRun = false;
}
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.txtAppleId = new System.Windows.Forms.RichTextBox();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.btnStopRemovePay = new System.Windows.Forms.Button();
this.btnRemovePayLog = new System.Windows.Forms.Button();
this.btnStartRemovePay = new System.Windows.Forms.Button();
this.ckRemovePayVpn = new System.Windows.Forms.CheckBox();
this.label5 = new System.Windows.Forms.Label();
this.labRemovePayDianShu = new System.Windows.Forms.Label();
this.label31 = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.txtLog = new System.Windows.Forms.RichTextBox();
this.groupBox4.SuspendLayout();
this.contextMenuStrip1.SuspendLayout();
this.groupBox5.SuspendLayout();
this.groupBox3.SuspendLayout();
base.SuspendLayout();
this.textBox1.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.textBox1.Location = new System.Drawing.Point(109, 12);
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(332, 21);
this.textBox1.TabIndex = 19;
this.textBox1.Text = "xxx@xx.com----密码";
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(26, 15);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(89, 12);
this.label6.TabIndex = 18;
this.label6.Text = "输入的ID格式";
this.groupBox4.Controls.Add(this.txtAppleId);
this.groupBox4.Location = new System.Drawing.Point(25, 38);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(548, 202);
this.groupBox4.TabIndex = 17;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "输入AppleID 多个ID请换行";
this.txtAppleId.ContextMenuStrip = this.contextMenuStrip1;
this.txtAppleId.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtAppleId.Location = new System.Drawing.Point(3, 17);
this.txtAppleId.Name = "txtAppleId";
this.txtAppleId.Size = new System.Drawing.Size(542, 182);
this.txtAppleId.TabIndex = 0;
this.txtAppleId.Text = "";
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[1] { this.ToolStripMenuItem });
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(101, 26);
this.ToolStripMenuItem.Name = "粘贴ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(100, 22);
this.ToolStripMenuItem.Text = "粘贴";
this.ToolStripMenuItem.Click += new System.EventHandler(ToolStripMenuItem_Click);
this.groupBox5.Controls.Add(this.btnStopRemovePay);
this.groupBox5.Controls.Add(this.btnRemovePayLog);
this.groupBox5.Controls.Add(this.btnStartRemovePay);
this.groupBox5.Location = new System.Drawing.Point(594, 29);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(169, 208);
this.groupBox5.TabIndex = 20;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "操作";
this.btnStopRemovePay.Location = new System.Drawing.Point(21, 117);
this.btnStopRemovePay.Name = "btnStopRemovePay";
this.btnStopRemovePay.Size = new System.Drawing.Size(130, 24);
this.btnStopRemovePay.TabIndex = 8;
this.btnStopRemovePay.Text = "停止执行";
this.btnStopRemovePay.UseVisualStyleBackColor = true;
this.btnStopRemovePay.Click += new System.EventHandler(btnStopRemovePay_Click);
this.btnRemovePayLog.Location = new System.Drawing.Point(21, 161);
this.btnRemovePayLog.Name = "btnRemovePayLog";
this.btnRemovePayLog.Size = new System.Drawing.Size(86, 23);
this.btnRemovePayLog.TabIndex = 7;
this.btnRemovePayLog.Text = "移除记录";
this.btnRemovePayLog.UseVisualStyleBackColor = true;
this.btnRemovePayLog.Click += new System.EventHandler(btnRemovePayLog_Click);
this.btnStartRemovePay.Location = new System.Drawing.Point(21, 54);
this.btnStartRemovePay.Name = "btnStartRemovePay";
this.btnStartRemovePay.Size = new System.Drawing.Size(130, 46);
this.btnStartRemovePay.TabIndex = 6;
this.btnStartRemovePay.Text = "开始执行";
this.btnStartRemovePay.UseVisualStyleBackColor = true;
this.btnStartRemovePay.Click += new System.EventHandler(btnStartRemovePay_Click);
this.ckRemovePayVpn.AutoSize = true;
this.ckRemovePayVpn.ForeColor = System.Drawing.Color.Red;
this.ckRemovePayVpn.Location = new System.Drawing.Point(28, 263);
this.ckRemovePayVpn.Name = "ckRemovePayVpn";
this.ckRemovePayVpn.Size = new System.Drawing.Size(108, 16);
this.ckRemovePayVpn.TabIndex = 25;
this.ckRemovePayVpn.Text = "使用随机IP代理";
this.ckRemovePayVpn.UseVisualStyleBackColor = true;
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(403, 264);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(293, 12);
this.label5.TabIndex = 24;
this.label5.Text = "支付方式移除成功才扣除点数,没有支付方式不扣点数\r\n";
this.labRemovePayDianShu.AutoSize = true;
this.labRemovePayDianShu.Font = new System.Drawing.Font("微软雅黑", 10.5f, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 134);
this.labRemovePayDianShu.ForeColor = System.Drawing.Color.Crimson;
this.labRemovePayDianShu.Location = new System.Drawing.Point(349, 263);
this.labRemovePayDianShu.Name = "labRemovePayDianShu";
this.labRemovePayDianShu.Size = new System.Drawing.Size(18, 19);
this.labRemovePayDianShu.TabIndex = 23;
this.labRemovePayDianShu.Text = "0";
this.label31.AutoSize = true;
this.label31.Location = new System.Drawing.Point(278, 267);
this.label31.Name = "label31";
this.label31.Size = new System.Drawing.Size(65, 12);
this.label31.TabIndex = 22;
this.label31.Text = "消耗点数:";
this.groupBox3.Controls.Add(this.txtLog);
this.groupBox3.Location = new System.Drawing.Point(16, 287);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(775, 334);
this.groupBox3.TabIndex = 21;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "日志";
this.txtLog.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtLog.ForeColor = System.Drawing.Color.LightSeaGreen;
this.txtLog.Location = new System.Drawing.Point(3, 17);
this.txtLog.Name = "txtLog";
this.txtLog.ReadOnly = true;
this.txtLog.Size = new System.Drawing.Size(769, 314);
this.txtLog.TabIndex = 0;
this.txtLog.Text = "";
base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
base.ClientSize = new System.Drawing.Size(800, 633);
base.Controls.Add(this.ckRemovePayVpn);
base.Controls.Add(this.label5);
base.Controls.Add(this.labRemovePayDianShu);
base.Controls.Add(this.label31);
base.Controls.Add(this.groupBox3);
base.Controls.Add(this.groupBox5);
base.Controls.Add(this.textBox1);
base.Controls.Add(this.label6);
base.Controls.Add(this.groupBox4);
base.MaximizeBox = false;
base.MinimizeBox = false;
base.Name = "FormRemovePay";
base.ShowIcon = false;
base.ShowInTaskbar = false;
base.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "移除支付方式";
base.FormClosing += new System.Windows.Forms.FormClosingEventHandler(FormRemovePay_FormClosing);
base.Load += new System.EventHandler(FormRemovePay_Load);
this.groupBox4.ResumeLayout(false);
this.contextMenuStrip1.ResumeLayout(false);
this.groupBox5.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
base.ResumeLayout(false);
base.PerformLayout();
}
}
}