using Api.Framework;
using Api.Framework.Cps;
using Api.Framework.Enums;
using Api.Framework.Events;
using Api.Framework.Model;
using Api.Framework.SDK;
using Api.Framework.Tools;
using Api.Framework.Utils;
using Chat.Framework;
using Chat.Framework.QQSdk;
using Chat.Framework.QQSdk.Events;
using Chat.Framework.WXSdk;
using Chat.Framework.WXSdk.Implement;
using CsharpHttpHelper;
using DevExpress.XtraBars;
using DevExpress.XtraEditors;
using DevExpress.XtraTab;
using FLSystem.Events;
using FLSystem.Properties;
using FLSystem.Win32Api;
using GeneralFramework;
using Grant.Framework;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PCRobot.Pack;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Win32;
using UI.Framework.Controls;
using UI.Framework.Forms;
using UI.Framework.Tools;
using static Api.Framework.Tools.TBHelper;
namespace FLSystem.Forms
{
public partial class main : BaseForm
{
public main()
{
InitializeComponent();
#region 锁屏
timeClear = new TimerClearEventHandler(Time_Clear);//如果操作了系统,则重新计时
mouseKeyHook.KeyDown += new KeyEventHandler(mouseKeyHook_KeyDown);
mouseKeyHook.KeyUp += new KeyEventHandler(mouseKeyHook_KeyUp);
mouseKeyHook.KeyPress += new KeyPressEventHandler(mouseKeyHook_KeyPress);
mouseKeyHook.OnMouseActivity += new MouseEventHandler(mouseKeyHook_OnMouseActivity);
mouseKeyHook.Start(true, true);
#endregion
}
#region 锁主程序
public delegate void TimerClearEventHandler();
public delegate void ShowTimeEventHandler();
private MouseKeyHook mouseKeyHook = new MouseKeyHook(true, true);
public bool lockState = false;
private bool timerEnable = false;
private TimerClearEventHandler timeClear;
private void Time_Clear()
{
if (timerEnable)
{
this.timer1.Stop();
this.timer1.Start();
}
}
void mouseKeyHook_OnMouseActivity(object sender, MouseEventArgs e) { this.Invoke(this.timeClear); }
void mouseKeyHook_KeyPress(object sender, KeyPressEventArgs e) { this.Invoke(this.timeClear); }
void mouseKeyHook_KeyUp(object sender, KeyEventArgs e) { this.Invoke(this.timeClear); }
void mouseKeyHook_KeyDown(object sender, KeyEventArgs e) { this.Invoke(this.timeClear); }
#endregion
KeyboardHook kh;
///
/// 同步黑名单
///
private System.Timers.Timer timerBlackUser = null;
public void main_Load(object sender, EventArgs e)
{
try
{
DevExpress.UserSkins.BonusSkins.Register();
DevExpress.Skins.SkinManager.EnableFormSkins();
DevExpress.Utils.WXPaint.WXPPainter.Default.ThemeChanged += Default_ThemeChanged;
GrantClient.Get().LodingAbout(1003, Program.ReadICO());
if (!ApiClient.SelectDbbase()) Program.Exit();
var skin = Util.AppConfig_GetValue("SkinName");
//DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(skin == "Basic" ? "The Bezier" : skin);
if (!Util.AppConfig_ExistItem("ShowTgwz"))
Util.AppConfig_AddItem("ShowTgwz", "0");
Util.AppConfig_ModifyItem("ShowTgwz", "1");
if (!Util.AppConfig_ExistItem("StartDy"))
Util.AppConfig_AddItem("StartDy", "0");
Util.AppConfig_ModifyItem("StartDy", "1");
if (!Util.AppConfig_ExistItem("BlackUserTime"))
Util.AppConfig_AddItem("BlackUserTime", " ");
#region 菜单导航栏
if (!Util.AppConfig_ExistItem("Nav"))
Util.AppConfig_AddItem("Nav", "");
var navConfig = Util.AppConfig_GetValue("Nav");
if (!string.IsNullOrWhiteSpace(navConfig))
{
try
{
var jsonData = PackTool.DecompressString(navConfig);
var treeList = JsonConvert.DeserializeObject>(jsonData);
var indexList = treeList.GroupBy(f => f.index).Select(f => f.Key).ToList();
for (int i = 0; i < indexList.Count; i++)
{
var tree = treeList.FirstOrDefault(f => f.ceng == 1 && f.index == i);
if (tree != null)
{
if (i == 0)
{
if (!tree.check)
ribbonPage1.Visible = false;
else
SetShow(treeList, i);
}
else if (i == 1)
{
if (!tree.check)
ribbonPage2.Visible = false;
else
SetShow(treeList, i);
}
else if (i == 2)
{
if (!tree.check)
ribbonPage3.Visible = false;
else
SetShow(treeList, i);
}
else if (i == 3)
{
if (!tree.check)
ribbonPage4.Visible = false;
else
SetShow(treeList, i);
}
else if (i == 4)
{
var t2List = treeList.Where(f => f.ceng == 2 && f.index == i && f.check).Select(f => f.name).ToList();
ApiClient.ShowPluginList = t2List;
}
}
}
}
catch (Exception)
{ }
}
#endregion
//if (!Util.AppConfig_ExistItem("WphNav"))
// Util.AppConfig_AddItem("WphNav", "0");
this.Text = GrantClient.Get().About["title"].ToString();
this.notify_pallet.Text = this.Text;
Loding.ShowWaitForm();
var result = ApiClient.Initialization();
//ChatMemberHandleEvent.FindChatObject += ChatMemberHandleEvent_FindChatObject;
//ChatMemberHandleEvent.UpdateChatFriends += ChatMemberHandleEvent_UpdateChatFriends;
//ChatMemberHandleEvent.UpdateChatGroupMembers += ChatMemberHandleEvent_UpdateChatGroupMembers;
if (!result) Program.Exit();
AlimamaApi.Init();
Loding.CloseWaitForm();
//btn_home_manage.Visibility = BarItemVisibility.Never;
ItemClick(btn_home_manage, null);//显示首页
ItemClick(btn_log_manage, null);//显示日志
try
{
ApiClient.SocketInitialization();
}
catch (Exception ex)
{
ShowErrorAutoClose(ex, 10000);
}
//TODO 禁用抖音禁用
var StartDy = Util.AppConfig_GetValue("StartDy");
if (StartDy == "1")
{
barButtonItem_douyin.Enabled = barButtonItem99.Enabled = barButtonItem100.Enabled = true;
ItemClick(barButtonItem_douyin, null);
}
var session = ApiClient.GetSession();
Thread.Sleep(200);
this.Icon = Program.ReadICO();
this.notify_pallet.Icon = this.Icon;
EventClient.MethodEvent += EventClient_MethodEvent;
MainEvent.CommonEvents += Main_CommonEvents;
this.Disposed += Control_Disposed;
ReadNote(false);
barStaticItem12.Caption = "专业版V" + ApiClient.CurVersion;
this.xtraTabControl1.SelectedTabPageIndex = 0;
RefreshAccount();
ChatClient.MessFrequentSleepTime = ApiClient.Setting.SystemConfig.mess_frequent_sleep_time;
//ChatClient.QQPool.LoginChangeEvent += QQPool_LoginChangeEvent;
ChatClient.Events.WXRefreshUserEvent += Events_WXRefreshUserEvent;
ChatClient.Events.WXChangeStatusEvent += Events_WXChangeStatusEvent;
ChatClient.QQEvents.QQRefreshUserEvent += Events_QQRefreshUserEvent;
ChatClient.QQEvents.LoginChangeEvent += QQEvents_LoginChangeEvent;
EventClient.SharedEvent += EventClient_SharedEvent;
UpdTime();
//new Utils();
EventClient.OnEvent(this, MethodType.刷新配置文件);
#region 精简消息
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(main));
this.barButtonItem9.ImageOptions.Image = (System.Drawing.Image)(resources.GetObject("barButtonItem10.ImageOptions.Image"));
this.barButtonItem9.ImageOptions.LargeImage = global::FLSystem.Properties.Resources.停止__4_;
this.barButtonItem9.Caption = "停止接收";
if (ApiClient.Setting.SystemConfig.message_warning_switch)
{
this.barButtonItem93.Caption = "关闭【双12】模式";
this.barButtonItem93.ImageOptions.Image = (System.Drawing.Image)(resources.GetObject("barButtonItem93.ImageOptions.Image"));
this.barButtonItem93.ImageOptions.LargeImage = (System.Drawing.Image)(resources.GetObject("barButtonItem93.ImageOptions.LargeImage"));
}
else
{
this.barButtonItem93.Caption = "开启【双12】模式";
this.barButtonItem93.ImageOptions.Image = ((System.Drawing.Image)(resources.GetObject("barButtonItem94.ImageOptions.Image")));
this.barButtonItem93.ImageOptions.LargeImage = ((System.Drawing.Image)(resources.GetObject("barButtonItem94.ImageOptions.LargeImage")));
}
#endregion
#region ipad协议出现remark为PCWechat Hook的情况,导致无法手动自动登陆(修改为空值)
var _robots = session.FindRobots().Where(f => f.type == ChatType.微信 && f.remark == "PCWechat HOOK" && f.token.StartsWith(@"{""data"":"));
foreach (var item in _robots)
{
item.remark = string.Empty;
session.SaveOrUpdate(item);
}
#endregion
var WxRobots = session.FindRobots(true).Where(f => f.is_login && f.type == ChatType.微信 && f.remark != "PCWechat HOOK").ToList();
TaskTool tasks = new TaskTool();
if (WxRobots.Count != 0)
{
if (BaseForm.ShowSuccessAutoClose(@"对不起,由于近期个别微信有出现封号!
为了您的账号安全,暂时不提供协议登陆!
请下载【易转发-微信官方客户端】登陆,保障您的账号安全!
-------------
下载地址已复制到剪切板,请粘贴到浏览器下载
-------------
注意:如果您执意要通过协议登陆,请点击确定!!!", new DialogResult[] { DialogResult.OK, DialogResult.Cancel }, 0) == DialogResult.OK)
{
if (string.IsNullOrWhiteSpace(ApiClient.Setting.SystemConfig.pay_wechat_hostSign))
{
BaseForm.ShowSuccessAutoClose($@"温馨提示:微信协议用户,如遇微信红包支付异常,请联系客服使用商户支付", 10 * 1000, "友情提示");
}
foreach (var item in WxRobots)
{
var _item = item;
tasks.AddTask(delegate ()
{
try
{
EventClient.OnEvent(this, $"正在自动微信->{_item.nick}({item.name})...");
var flag = ChatClient.LoginWeixin(_item.name, _item.token);
}
catch (Exception ex)
{
EventClient.OnEvent(this, $"登录微信->{_item.nick}({item.name})异常:{ex.Message}");
}
});
}
}
else
{
try
{
Clipboard.SetDataObject(Resources.易转发下载地址 + "?=" + new Random().Next(100, 2000));
}
catch (Exception ex)
{ }
}
}
var QQRobots = session.FindRobots(true).Where(f => f.is_login && f.type == ChatType.QQ).ToList();
if (QQRobots != null && QQRobots.Count != 0)
{
foreach (var item in QQRobots)
{
var QQRobot = item;
tasks.AddTask(delegate ()
{
try
{
EventClient.OnEvent(this, $"正在自动QQ->{QQRobot.nick}({QQRobot.name})...");
if (!string.IsNullOrWhiteSpace(QQRobot.token))
{
var dic = HttpExtend.JsonToDictionary(Encoding.UTF8.GetString(HttpExtend.HexToByte(QQRobot.token)));
if (dic != null)
{
if (dic.ContainsKey("QQ"))
{
var QQ = dic["QQ"]?.ToString();
if (!string.IsNullOrWhiteSpace(QQ) && dic.ContainsKey("Password"))
{
var Password = dic["Password"]?.ToString();
var qq = uint.Parse(QQ);
if (ChatClient.QQClients.ContainsKey(QQ))
{
var qBase = ChatClient.QQClients[QQ];
qBase.Login();
}
else
{
//QQ自动登录
var IsEQQ = false;
if (!string.IsNullOrWhiteSpace(Password) && dic.ContainsKey("IsEQQ"))
IsEQQ = (dic["IsEQQ"].ToString().ToLower() == "true");
var qqClient = ChatClient.LoginQQ(QQ, Password);
}
}
}
}
}
}
catch (Exception ex)
{
EventClient.OnEvent(this, $"登录QQ->{QQRobot.nick}({QQRobot.name})异常:{ex.Message},{ex.StackTrace}");
}
});
Thread.Sleep(500);
}
}
tasks.Start(30, AsyncCallbackMethod);
EventClient.OnEvent(this, MethodType.刷新机器人);
ChatClient.WXSdkConfig.IsDebug = false;
ChatClient.WXSdkConfig.MsgConvertToFriend = ApiClient.Setting.SystemConfig.msg_wx_convertswich == SwitchType.开启 ? true : false;
isLodingOk = true;
kh = new KeyboardHook();
kh.SetHook();
kh.OnKeyDownEvent += kh_OnKeyDownEvent;
System.Timers.Timer timerLok = new System.Timers.Timer();
timerLok.Elapsed += timer_lockForm_Tick;
timerLok.Interval = 5 * 60000;//测试1分钟锁屏
timerLok.Start();
#region 激活抖音xxx
//TODO 禁用抖音禁用
//if (StartDy == "1")
//{
// TaskTool tasks_douyin = new TaskTool();
// var douyinMember = CpsClient.Members.Where(f => f.cpstype == CpsType.抖音联盟 /*&& f.is_download == SwitchType.开启*/).ToList();
// if (douyinMember != null && douyinMember.Count != 0)
// {
//抖音单登版本EO
//if (douyinMember.Count > 1)
//{
// for (int i = 1; i < douyinMember.Count; i++)
// {
// session.Delete(douyinMember[i]);
// CpsClient.Members.Remove(douyinMember[i]);
// }
//}
//抖音多版本EO
//foreach (var item in douyinMember)
//{
// var _item = item;
// try
// {
// _item.is_valid = true;
// _item.online = false;
// EventClient.OnEvent(this, $"激活抖音->{_item.usernick}({item.username})...");
// var api = CpsClient.CreateDouyinRequest(_item);
// var form = new douyin_form_login1();
// DouyinApi.douyinApiAction?.Invoke(api);
// form.Show();
// //抖音隐藏
// if (ApiClient.Setting.SystemConfig.hidedy && !string.IsNullOrWhiteSpace(api.Member.username))
// form.Hide();
// }
// catch (Exception ex)
// {
// EventClient.OnEvent(this, $"激活抖音->{_item.usernick}({item.username})异常:{ex.Message}");
// }
// Thread.Sleep(500);
//}
// }
//}
#endregion
#region 唯品会
//var wphCount = CpsClient.Members.Count(f => f.cpstype == CpsType.唯品联盟);
//var robots = session.FindRobots();
////if (wphCount == 0 && (WphNav == null || WphNav == "0"))
//if (wphCount == 0 && robots != null && robots.Count != 0)
//{
// if (!Util.AppConfig_ExistItem("ShowWphAd"))
// Util.AppConfig_AddItem("ShowWphAd", "1");
// var ShowWphAd = Util.AppConfig_GetValue("ShowWphAd");
// if (ShowWphAd == "1")
// {
// Thread th = new Thread(delegate ()
// {
// Thread.Sleep(5000);
// try
// {
// var Rst = MessageBox.Show("请尽快设置唯品会联盟,目前唯品会高消费年轻人群剧增,是否立即设置?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
// if (Rst != DialogResult.Yes)
// {
// Rst = MessageBox.Show("唯品会设置只需要1分钟,您确定要放弃吗?(≈1个亿)", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
// if (Rst == DialogResult.Yes)
// {
// Util.AppConfig_ModifyItem("ShowWphAd", "0");
// return;
// }
// }
// Rst = MessageBox.Show("您是否已经有唯品会账号,点击Yes登录唯品会,点击No注册唯品会", "询问", MessageBoxButtons.YesNo);
// if (Rst == DialogResult.No)
// {
// var form = new WphRegisterForm();
// form.ShowDialog();
// }
// //登录唯品会
// var cps_member = LoginCps(CpsType.唯品联盟);
// if (cps_member == null)
// //throw new Exception("唯品会cps对象为空,可能登录异常");
// return;
// //打开唯品会插件
// if (PluginClient.Plugins != null)
// {
// var plugin = PluginClient.Plugins.FirstOrDefault(f => f.Name == "唯品会返利");
// if (plugin != null)
// {
// PluginClient.UnInstall(plugin);
// Thread.Sleep(200);
// PluginClient.Install(plugin);
// }
// }
// //创建推广位,判断是否有推广位,没有推广位创建一个推广位,有推广位,给没有设置推广位的机器人设置推广位
// #region 获取唯品会推广位
// var api = CpsClient.CreateWeipinhuiRequest(cps_member);
// var pidResult = WeipinhuiApi.GetWphTgw(api);
// if (result != null)
// {
// //推广位为空,创建推广位
// if (pidResult.total == 0)
// WeipinhuiApi.CreateWphTgw(api);
// pidResult = WeipinhuiApi.GetWphTgw(api);
// if (pidResult != null && pidResult.pidInfoList != null && pidResult.total != 0)
// {
// var tmp = pidResult.pidInfoList[0];
// if (tmp != null)
// {
// var tgw = new Tuiguangwei()
// {
// Member = cps_member,
// Name = tmp.pidName,
// Pid = tmp.pid
// };
// // 设置推广位
// var robotList = session.FindRobots();
// foreach (var robot in robotList)
// {
// setWphTgw((int)robot.id, tgw);
// }
// }
// }
// }
// #endregion
// }
// catch (Exception ex)
// {
// EventClient.OnEvent("引导设置唯品会异常", $"{ex.Message} - {ex.StackTrace}");
// }
// finally
// {
// ////监听刷新
// //PluginClient.LodingPlugin();
// }
// //1.搞个唯品会注册页
// //2.打开联盟登录页,自动登录后关闭窗口即可
// //3.自动启用唯品会插件,并设置好推广位
// //var form = new WPHNavForm();
// //if (form.ShowDialog() == DialogResult.OK)
// //{
// // //下次检测到唯品会未登录是否提示
// // Util.AppConfig_ModifyItem("WphNav", form.isIgnore ? "1" : "0");
// //}
// });
// th.ApartmentState = ApartmentState.STA; //属性设置成单线程
// th.IsBackground = true;
// th.Start();
// }
//}
//else
//{
// if (!Util.AppConfig_ExistItem("ShowWphAd"))
// Util.AppConfig_AddItem("ShowWphAd", "0");
// else
// Util.AppConfig_ModifyItem("ShowWphAd", "0");
//}
#endregion 唯品会
//#region MyRegion
//var ss = Util.Read>("插件-积分管理-配置");
//var ssss = Newtonsoft.Json.JsonConvert.SerializeObject(ss);
//var fff = ssss.Contains("ExchangeCommercialPayTip_MiniApp");
//#endregion
System.Timers.Timer timer = new System.Timers.Timer();
timer.Elapsed += Timer_Elapsed;
timer.Interval = 40 * 60 * 1000;
//timer.Interval = 1000;
timer.Start();
//下载黑名单
timerBlackUser = new System.Timers.Timer(1000);
timerBlackUser.Elapsed += Timer_ElapsedBlackUser;
timer.Interval = 1000;
timerBlackUser.Start();
}
catch (Exception ex)
{
try { Loding.CloseWaitForm(); } catch (Exception) { }
if (ex.Message.Contains("连接数据库过程中发生错误"))
ShowError(@"连接数据库过程中发生错误
检查服务器是否正常连接字符串是否正确");
else
ShowError(ex.Message + "\r\n" + ex.StackTrace);
Program.Exit();
}
finally
{
ItemClick(barButtonItem6, null);
//监听刷新
//PluginClient.LodingPlugin();
this.WindowState = FormWindowState.Normal;
Task.Run(() =>
{
Thread.Sleep(1000 * 60);
CheckSystemEventsHandlersForFreeze();
});
}
}
private static void CheckSystemEventsHandlersForFreeze()
{
try
{
var handlers = typeof(SystemEvents).GetField("_handlers", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
var handlersValues = handlers.GetType().GetProperty("Values").GetValue(handlers);
foreach (var invokeInfos in (handlersValues as IEnumerable).OfType