mirror of
https://git.oceanpay.cc/danial/kami_itunes_june.git
synced 2025-12-18 22:31:24 +00:00
472 lines
12 KiB
C#
472 lines
12 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
using AppleBatch_June.ExecuteTasks;
|
|
using AppleBatch_June.Forms;
|
|
using AppleBatch_June.Model;
|
|
using AppleBatch_June.StartTaskModel;
|
|
using AppleBatch_June.Utils;
|
|
using DotNet.Utilities;
|
|
using Microsoft.VisualBasic;
|
|
|
|
namespace AppleBatch_June
|
|
{
|
|
public class BaseForm : Form
|
|
{
|
|
private ListView lvLogList;
|
|
|
|
protected ITaskRunState taskState { get; set; }
|
|
|
|
public virtual string TaskName { get; set; }
|
|
|
|
protected ListView listData { get; set; }
|
|
|
|
protected Button startBtn { get; set; }
|
|
|
|
protected Label labCout { get; set; }
|
|
|
|
public BaseForm()
|
|
{
|
|
TaskName = "BaseForm";
|
|
}
|
|
|
|
public BaseForm(string _taskName)
|
|
{
|
|
TaskName = _taskName;
|
|
}
|
|
|
|
public BaseForm(string _taskName, ITaskRunState _taskState)
|
|
{
|
|
TaskName = _taskName;
|
|
base.FormClosing += BaseForm_FormClosing;
|
|
if (_taskState == null)
|
|
{
|
|
taskState = new BaseFormTaskRunState(TaskName);
|
|
}
|
|
else
|
|
{
|
|
taskState = _taskState;
|
|
}
|
|
}
|
|
|
|
public void asynTaskRunState(ITaskRunState state)
|
|
{
|
|
}
|
|
|
|
protected virtual void BaseForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
if (taskState.TaskIsRun && MessageBox.Show("该任务在运行,确定退出吗?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
|
|
{
|
|
e.Cancel = true;
|
|
return;
|
|
}
|
|
taskState.TaskIsRun = false;
|
|
taskState.Stop();
|
|
}
|
|
|
|
public void InitLv(ListView _lvLogList)
|
|
{
|
|
if (_lvLogList != null)
|
|
{
|
|
lvLogList = _lvLogList;
|
|
lvLogList.ColumnClick += lv_ColumnClick;
|
|
}
|
|
}
|
|
|
|
public void BindMenuPaste(RichTextBox obj)
|
|
{
|
|
ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
|
|
ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem
|
|
{
|
|
Text = "粘贴",
|
|
Size = new Size(124, 22)
|
|
};
|
|
contextMenuStrip.Items.AddRange(new ToolStripItem[1] { toolStripMenuItem });
|
|
toolStripMenuItem.Tag = obj;
|
|
toolStripMenuItem.Click += DelmunItem_Click1;
|
|
obj.ContextMenuStrip = contextMenuStrip;
|
|
}
|
|
|
|
private void DelmunItem_Click1(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem;
|
|
IDataObject dataObject = Clipboard.GetDataObject();
|
|
if (dataObject.GetDataPresent(DataFormats.Text) && toolStripMenuItem != null && toolStripMenuItem.Tag is RichTextBox)
|
|
{
|
|
(toolStripMenuItem.Tag as RichTextBox).Text = (string)dataObject.GetData(DataFormats.Text);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MessageBox.Show("粘贴失败");
|
|
}
|
|
}
|
|
|
|
public void BindMenuStrip(bool addTwoFactor = false, ToolStripMenuItem[] toolStripAdds = null, bool shouItems = false)
|
|
{
|
|
ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
|
|
ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem
|
|
{
|
|
Text = "删除",
|
|
Size = new Size(124, 22)
|
|
};
|
|
ToolStripMenuItem toolStripMenuItem2 = new ToolStripMenuItem
|
|
{
|
|
Text = "重新执行",
|
|
Size = new Size(124, 22)
|
|
};
|
|
ToolStripMenuItem toolStripMenuItem3 = new ToolStripMenuItem
|
|
{
|
|
Text = "复制账号信息",
|
|
Size = new Size(124, 22)
|
|
};
|
|
contextMenuStrip.Items.AddRange(new ToolStripItem[3] { toolStripMenuItem, toolStripMenuItem2, toolStripMenuItem3 });
|
|
if (addTwoFactor)
|
|
{
|
|
ToolStripMenuItem toolStripMenuItem4 = new ToolStripMenuItem
|
|
{
|
|
Text = "输入双重验证码",
|
|
Size = new Size(124, 22)
|
|
};
|
|
toolStripMenuItem4.Click += TwoFactorItem_Click;
|
|
contextMenuStrip.Items.Add(toolStripMenuItem4);
|
|
}
|
|
if (toolStripAdds != null)
|
|
{
|
|
foreach (ToolStripMenuItem value in toolStripAdds)
|
|
{
|
|
contextMenuStrip.Items.Add(value);
|
|
}
|
|
}
|
|
if (shouItems && lvLogList != null)
|
|
{
|
|
ToolStripMenuItem toolStripMenuItem5 = new ToolStripMenuItem
|
|
{
|
|
Text = "设置显示列",
|
|
Size = new Size(124, 22)
|
|
};
|
|
toolStripMenuItem5.Click += ShouItemsIndex_Click;
|
|
contextMenuStrip.Items.Add(toolStripMenuItem5);
|
|
}
|
|
toolStripMenuItem3.Click += Copy_Click;
|
|
toolStripMenuItem.Click += DelmunItem_Click;
|
|
toolStripMenuItem2.Click += ReExecute_Click;
|
|
contextMenuStrip.Size = new Size(125, 70);
|
|
contextMenuStrip.ResumeLayout(performLayout: false);
|
|
contextMenuStrip.SuspendLayout();
|
|
lvLogList.ContextMenuStrip = contextMenuStrip;
|
|
}
|
|
|
|
private void TwoFactorItem_Click(object sender, EventArgs e)
|
|
{
|
|
string text = Interaction.InputBox("请输入ID双重验证码", "请输入ID双重验证码");
|
|
if (!string.IsNullOrEmpty(text))
|
|
{
|
|
TwoFactorItem_over_Click(text);
|
|
}
|
|
}
|
|
|
|
public virtual void TwoFactorItem_over_Click(string reust)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void ShouItemsIndex_Click(object sender, EventArgs e)
|
|
{
|
|
FormEditListViewHander formEditListViewHander = new FormEditListViewHander();
|
|
formEditListViewHander.lvData = lvLogList;
|
|
formEditListViewHander.isAstrict = false;
|
|
formEditListViewHander.ShowDialog();
|
|
}
|
|
|
|
public virtual void ReExecute_Click(object sender, EventArgs e)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
protected virtual void DelmunItem_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
foreach (ListViewItem selectedItem in lvLogList.SelectedItems)
|
|
{
|
|
lvLogList.Items.Remove(selectedItem);
|
|
}
|
|
if (labCout != null)
|
|
{
|
|
labCout.Text = lvLogList.Items.Count.ToString();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
|
|
private void Copy_Click(object sender, EventArgs e)
|
|
{
|
|
copy();
|
|
}
|
|
|
|
public void copy()
|
|
{
|
|
if (lvLogList == null)
|
|
{
|
|
MessageBox.Show("请先调用InitLv");
|
|
return;
|
|
}
|
|
ListView listView = lvLogList;
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
int num = 0;
|
|
foreach (ListViewItem selectedItem in listView.SelectedItems)
|
|
{
|
|
num = 0;
|
|
foreach (ListViewItem.ListViewSubItem subItem in selectedItem.SubItems)
|
|
{
|
|
if (num != 0 && listView.Columns.Count > num && listView.Columns[num].Width > 0)
|
|
{
|
|
if (num > 2)
|
|
{
|
|
if (listView.Columns.Count > num)
|
|
{
|
|
stringBuilder.Append(listView.Columns[num].Text + subItem.Text + "-");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
stringBuilder.Append(subItem.Text + "----");
|
|
}
|
|
}
|
|
num++;
|
|
}
|
|
stringBuilder.Append("\n");
|
|
}
|
|
if (stringBuilder.Length <= 0)
|
|
{
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
Clipboard.SetText(stringBuilder.ToString());
|
|
MessageBox.Show("复制成功");
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MessageBox.Show("复制失败");
|
|
}
|
|
}
|
|
|
|
private void lv_ColumnClick(object sender, ColumnClickEventArgs e)
|
|
{
|
|
if (lvLogList.Tag == null)
|
|
{
|
|
lvLogList.Tag = "1";
|
|
}
|
|
if (lvLogList.Tag.ToString() == "1")
|
|
{
|
|
lvLogList.ListViewItemSorter = new ListViewItemComparer(e.Column, 1);
|
|
lvLogList.Tag = "0";
|
|
}
|
|
else
|
|
{
|
|
lvLogList.ListViewItemSorter = new ListViewItemComparer(e.Column, 0);
|
|
lvLogList.Tag = "1";
|
|
}
|
|
lvLogList.Sort();
|
|
}
|
|
|
|
public void UpdataUi(Action act)
|
|
{
|
|
if (base.IsHandleCreated && !base.IsDisposed)
|
|
{
|
|
try
|
|
{
|
|
BeginInvoke(act);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|
|
public void startAct()
|
|
{
|
|
UpdataUi(delegate
|
|
{
|
|
startBtn.Text = "停止";
|
|
startBtn.ForeColor = Color.Red;
|
|
});
|
|
}
|
|
|
|
public void endTakAct()
|
|
{
|
|
UpdataUi(delegate
|
|
{
|
|
startBtn.Tag = null;
|
|
startBtn.Text = "开始执行";
|
|
startBtn.ForeColor = Color.Green;
|
|
});
|
|
}
|
|
|
|
public void ApiApplyAct(int type, string typeName)
|
|
{
|
|
APIUtlis.ApiApplyAct(type, typeName);
|
|
}
|
|
|
|
public void ExperList(ListView lv)
|
|
{
|
|
FromExper fromExper = new FromExper();
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
int num = 0;
|
|
foreach (ColumnHeader column in lv.Columns)
|
|
{
|
|
if (num != 0 && column.Width > 10)
|
|
{
|
|
stringBuilder.Append(column.Text + "\t");
|
|
}
|
|
num++;
|
|
}
|
|
stringBuilder.Append("\n");
|
|
foreach (ListViewItem item in lv.Items)
|
|
{
|
|
num = 0;
|
|
foreach (ListViewItem.ListViewSubItem subItem in item.SubItems)
|
|
{
|
|
if (num != 0 && lv.Columns.Count > num && lv.Columns[num].Width > 10)
|
|
{
|
|
stringBuilder.Append(subItem.Text + "\t");
|
|
}
|
|
num++;
|
|
}
|
|
stringBuilder.Append("\n");
|
|
}
|
|
fromExper.txtInfo = stringBuilder.ToString();
|
|
fromExper.Show();
|
|
}
|
|
|
|
protected void endRuning(TaskRunModel runModel)
|
|
{
|
|
runModel.isRuning = false;
|
|
}
|
|
|
|
protected bool startRuning(TaskRunModel runModel, Action<string, DisplyType, string> _action, string appleId)
|
|
{
|
|
if (Tools.ToNetWorkInt(ConfigUtlis.getConfigValue("comNetworkConfig"), 0) == 3)
|
|
{
|
|
int num = Tools.ToInt(ConfigUtlis.getConfigValue("txtAdslIdCount"), 10);
|
|
if (AppleExecuteTask.TaskRunAppleIdCount >= num)
|
|
{
|
|
_action?.Invoke(appleId, DisplyType.xinxi, "等待拨号...");
|
|
bool flag = false;
|
|
do
|
|
{
|
|
flag = false;
|
|
foreach (TaskRunModel taskRunModel in AppleExecuteTask.TaskRunModels)
|
|
{
|
|
if (taskRunModel.isRuning)
|
|
{
|
|
flag = true;
|
|
break;
|
|
}
|
|
}
|
|
Thread.Sleep(new Random().Next(100, 300));
|
|
}
|
|
while (flag);
|
|
lock (AppleExecuteTask.obj)
|
|
{
|
|
if (AppleExecuteTask.TaskRunAppleIdCount >= num)
|
|
{
|
|
string configValue = ConfigUtlis.getConfigValue("txtAdslUserName");
|
|
string configValue2 = ConfigUtlis.getConfigValue("txtAdslPwd");
|
|
Thread.Sleep(new Random().Next(500, 1000));
|
|
_action?.Invoke(appleId, DisplyType.xinxi, "断开宽带连接");
|
|
RasTools.Disconnect();
|
|
Thread.Sleep(new Random().Next(200, 500));
|
|
_action?.Invoke(appleId, DisplyType.xinxi, "开始宽带重新拨号");
|
|
if (!RasTools.Connect(configValue, configValue2, out var errMsg))
|
|
{
|
|
_action?.Invoke(appleId, DisplyType.xinxi, "拨号失败:" + errMsg);
|
|
return false;
|
|
}
|
|
_action?.Invoke(appleId, DisplyType.xinxi, "重新拨号成功");
|
|
Thread.Sleep(new Random().Next(500, 1000));
|
|
AppleExecuteTask.TaskRunAppleIdCount = 0L;
|
|
}
|
|
}
|
|
}
|
|
AppleExecuteTask.TaskRunAppleIdCount++;
|
|
}
|
|
runModel.isRuning = true;
|
|
return true;
|
|
}
|
|
|
|
public AppleItunesLogin getItunesLogin(bool openVpn, AppleAcount account, int type, ItunesUtlis utlis, ref string msg, int isStore = 0, string notityKey = "", HttpResult httpReust = null)
|
|
{
|
|
if (httpReust == null)
|
|
{
|
|
httpReust = APIUtlis.getIsLogin(type);
|
|
}
|
|
if (httpReust.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
dynamic val = Tools.Todejosn<object>(httpReust.Html);
|
|
if (val["Code"] == "0000")
|
|
{
|
|
if (val["Data"]["integral"] >= AppSysConfig.getTypeById(type).consNum)
|
|
{
|
|
string msgReust = "";
|
|
AppleItunesLogin appleItunesLogin = iTunesAccountLoginCache.getLoginIdUserInfo(account.appleId, account.applePwd);
|
|
if (string.IsNullOrEmpty(utlis.ProxyIp))
|
|
{
|
|
utlis.ProxyIp = ProxyAccountCache.getProxyAccountIP(account.appleId);
|
|
}
|
|
if (appleItunesLogin == null || isStore == 2)
|
|
{
|
|
appleItunesLogin = ((!AppSysConfig.iTunesisRemoteLogin) ? utlis.appleLogin(account.appleId, account.applePwd + (account.isDoubleModl ? account.DoublePwd : ""), 1, ref msgReust, out var _) : utlis.remoteAppleLogin(account.appleId, account.applePwd + (account.isDoubleModl ? account.DoublePwd : ""), ref msgReust, isStore));
|
|
if (appleItunesLogin != null)
|
|
{
|
|
if (account.isDoubleModl)
|
|
{
|
|
appleItunesLogin.pwd = account.applePwd;
|
|
}
|
|
iTunesAccountLoginCache.addReddemUserInfo(account.appleId, appleItunesLogin);
|
|
}
|
|
}
|
|
if (appleItunesLogin != null)
|
|
{
|
|
return appleItunesLogin;
|
|
}
|
|
msg = msgReust;
|
|
}
|
|
else
|
|
{
|
|
msg = "点数不足,请联系客服充值";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
msg = val["Message"];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
msg = "网络请求失败";
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public virtual void insertLog(string txt)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
base.SuspendLayout();
|
|
}
|
|
}
|
|
}
|