479 lines
19 KiB
C#
479 lines
19 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using DevExpress.XtraEditors;
|
|
using UI.Framework.Forms;
|
|
using Api.Framework.Tools;
|
|
using Api.Framework;
|
|
using 监听违规.Entitys;
|
|
using SqlSugar;
|
|
using System.IO;
|
|
using CsharpHttpHelper;
|
|
using Newtonsoft.Json.Linq;
|
|
using Chat.Framework.WXSdk.Implement;
|
|
using Chat.Framework;
|
|
using Api.Framework.Model;
|
|
using Api.Framework.SDK;
|
|
using DevExpress.Utils;
|
|
using System.Threading;
|
|
|
|
namespace 监听违规
|
|
{
|
|
public partial class MainForm : BaseForm
|
|
{
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void CloseForm()
|
|
{
|
|
try
|
|
{
|
|
if (!this.IsDisposed)
|
|
{
|
|
this.Invoke(new Action(delegate
|
|
{
|
|
this.Close();
|
|
this.Dispose();
|
|
}));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
|
{
|
|
cb_qrcode.Checked = Class1.Config.is_qrcord;
|
|
cb_card.Checked = Class1.Config.is_card;
|
|
cb_link.Checked = Class1.Config.is_link;
|
|
cb_messrows.Checked = Class1.Config.is_messrows;
|
|
nd_messrows.Value = Class1.Config.messrows;
|
|
cb_messwords.Checked = Class1.Config.is_messwords;
|
|
nd_messwords.Value = Class1.Config.messwords;
|
|
cb_nickkey.Checked = Class1.Config.is_nickkey;
|
|
tb_nickkey.Text = Class1.Config.nickkey;
|
|
cb_messkey.Checked = Class1.Config.is_messkey;
|
|
tb_messkey.Text = Class1.Config.messkey;
|
|
cb_expelmess.Checked = Class1.Config.is_expelmess;
|
|
tb_expelmess.Text = Class1.Config.expelmess;
|
|
|
|
linkLabel1_LinkClicked(null, null);
|
|
|
|
pageControl2.Bind(SerchData, this.gridControl1, 1000, false, true);
|
|
}
|
|
|
|
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Class1.Config.is_qrcord = cb_qrcode.Checked;
|
|
Class1.Config.is_card = cb_card.Checked;
|
|
Class1.Config.is_link = cb_link.Checked;
|
|
Class1.Config.is_messrows = cb_messrows.Checked;
|
|
Class1.Config.messrows = (int)nd_messrows.Value;
|
|
Class1.Config.is_messwords = cb_messwords.Checked;
|
|
Class1.Config.messwords = (int)nd_messwords.Value;
|
|
Class1.Config.is_nickkey = cb_nickkey.Checked;
|
|
Class1.Config.nickkey = tb_nickkey.Text;
|
|
Class1.Config.is_messkey = cb_messkey.Checked;
|
|
Class1.Config.messkey = tb_messkey.Text;
|
|
Class1.Config.is_expelmess = cb_expelmess.Checked;
|
|
Class1.Config.expelmess = tb_expelmess.Text;
|
|
|
|
Util.Save(Class1.Config);
|
|
}
|
|
catch (Exception ex)
|
|
{ }
|
|
}
|
|
|
|
private void cb_nickkey_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void cb_messkey_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private UI.Framework.Controls.PageControl.SerchResult SerchData(int index, int pagesize)
|
|
{
|
|
try
|
|
{
|
|
var session = ApiClient.GetSession();
|
|
var conModels = new List<IConditionalModel>();
|
|
|
|
var utype = (UserType)Enum.Parse(typeof(UserType), comboBoxEdit1.Text);
|
|
if (utype != UserType.全部状态)
|
|
conModels.Add(new ConditionalModel() { FieldName = "user_type", ConditionalType = ConditionalType.Equal, FieldValue = ((int)utype).ToString() });
|
|
|
|
string where = string.Empty;
|
|
string keyword = this.textEdit1.Text.Trim();
|
|
if (!string.IsNullOrEmpty(keyword))
|
|
conModels.Add(new ConditionalModel() { FieldName = "wxid", ConditionalType = ConditionalType.Equal, FieldValue = keyword });
|
|
|
|
//总记录数
|
|
int totalNumber = 0;
|
|
var result = session.Queryable<UserLists_db>().Where(conModels).ToPageList(index, pagesize, ref totalNumber);
|
|
|
|
return new UI.Framework.Controls.PageControl.SerchResult() { Result = result, Total = totalNumber };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!this.IsDisposed)
|
|
this.UpdateUI(() =>
|
|
{
|
|
BaseForm.ShowError(ex);
|
|
});
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private void simpleButton1_Click(object sender, EventArgs e)
|
|
{
|
|
this.pageControl2.Go(sender, e);
|
|
}
|
|
|
|
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var rows = this.gridView1.GetSelectedRows();
|
|
if (rows.Length != 0)
|
|
{
|
|
var info = this.gridView1.GetRow(rows[0]) as UserLists_db;
|
|
if (XtraMessageBox.Show("您确定要删除选中数据嘛?\r\n" + info.wxid, "友情提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
var session = ApiClient.GetSession();
|
|
session.ExcuteSQL("delete from UserLists_db where id=" + info.id);
|
|
Common.FlushWhiteUserListsCache(true);
|
|
}
|
|
this.pageControl2.GotoPage(1);
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
XtraMessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void 添加ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
new AddForm().ShowDialog();
|
|
this.pageControl2.GotoPage(1);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
XtraMessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
button1.Enabled = false;
|
|
|
|
OpenFileDialog dialog = new OpenFileDialog();
|
|
dialog.Multiselect = false;
|
|
dialog.Title = "请选择文件";
|
|
dialog.Filter = "所有文件(*.json)|*.json";
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
var t = Task.Run(() =>
|
|
{
|
|
var db = ApiClient.GetSession();
|
|
try
|
|
{
|
|
db.BeginTransaction();
|
|
var json = File.ReadAllText(dialog.FileName);
|
|
var jArr = JArray.Parse(json);
|
|
|
|
var list = new List<UserLists_db>();
|
|
foreach (var item in jArr)
|
|
{
|
|
var data = (JObject)item;
|
|
//var wxid = data["wxid"].ToString().Trim();
|
|
//if (string.IsNullOrWhiteSpace(wxid)) continue;
|
|
//if (list.FirstOrDefault(f => f.wxid == wxid) != null) continue;
|
|
var nick = data["nick_name"].ToString();
|
|
list.Add(new UserLists_db() { nick_name = Util.RemoveEmoji(nick), user_type = UserType.黑名单, wxid = data["wxid"].ToString() });
|
|
}
|
|
EventClient.OnEvent(null, "读取完成,正在插入");
|
|
var _num1 = (int)Math.Ceiling((decimal)list.Count / 100m);
|
|
for (int o = 1; o <= _num1; o++)
|
|
{
|
|
var _list = list.Skip((o - 1) * 100).Take(100).ToList();
|
|
try
|
|
{
|
|
db.Insertable(_list).ExecuteCommand();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
EventClient.OnEvent(null, "插入失败,插入 " + o * 100);
|
|
}
|
|
}
|
|
db.Commit();
|
|
ShowSuccessAutoClose("导入成功");
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Rollback();
|
|
ShowError(ex);
|
|
}
|
|
finally
|
|
{
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
button1.Enabled = true;
|
|
}));
|
|
}
|
|
});
|
|
//Task.WaitAll(t);
|
|
}
|
|
}
|
|
|
|
private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var row = e.Row as UserLists_db;
|
|
if (e.Column.Caption == "用户状态")
|
|
e.Value = row.user_type.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
}
|
|
|
|
private void simpleButton2_Click(object sender, EventArgs e)
|
|
{
|
|
if (comboBoxEdit2.SelectedIndex == 0)
|
|
{
|
|
MessageBox.Show("请选择机器人");
|
|
return;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(tb_groupid.Text))
|
|
{
|
|
MessageBox.Show("请填写群id");
|
|
return;
|
|
}
|
|
var robotInfo = comboBoxEdit2.Text;
|
|
simpleButton2.Enabled = false;
|
|
Task.Run(() =>
|
|
{
|
|
try
|
|
{
|
|
var wx = ChatClient.WXClient.Values.FirstOrDefault(f => f.WeixinType == WeixinType.Grpc微信 && f.Status == Chat.Framework.WXSdk.WxStatus.在线 && robotInfo.Contains("(" + f.WeixinHao + ")"));
|
|
if (wx == null) throw new Exception("机器人已经离线或一会再试");
|
|
var members = wx.GetMembers(tb_groupid.Text, true);
|
|
if (members == null) throw new Exception($"获取群({robotInfo})用户失败");
|
|
|
|
var session = ApiClient.GetSession();
|
|
|
|
var inviteInfos = new List<InviteInfo>();
|
|
|
|
for (int z = 0; z < members.Length; z++)
|
|
{
|
|
var item = members[z];
|
|
|
|
UserType userType = UserType.全部状态;
|
|
#region 判断数据中是否存在这个用户
|
|
var member = session.FindSingle<fl_member_info>("select * from fl_member_info where username = @username", new { username = item.Username });
|
|
if (member == null)
|
|
{
|
|
member = new fl_member_info() { crt_time = DateTime.Now, usernick = item.NickName, robot_name = wx.WeixinHao, robot_type = wx.WeixinType == WeixinType.QYHook微信 ? ChatType.企业微信 : ChatType.微信, username = item.Username, alipay_name = string.Empty, alipay_num = string.Empty, remark = string.Empty };
|
|
session.SaveOrUpdate(member);
|
|
}
|
|
|
|
if (member.is_cloud_black || member.status == Api.Framework.Enums.MemberType.黑名单)
|
|
userType = UserType.黑名单;
|
|
else if (member.status == Api.Framework.Enums.MemberType.白名单)
|
|
userType = UserType.白名单;
|
|
if (userType == UserType.全部状态)
|
|
{
|
|
var black = session.FindSingle<UserLists_db>("wxid = @wxid and user_type", new { wxid = item.Username });
|
|
if (black != null)
|
|
userType = black.user_type;
|
|
}
|
|
#endregion
|
|
|
|
inviteInfos.Add(new InviteInfo() { ImgUrl = item.SmallHeadImgUrl, Username = item.Username, Usernick = item.NickName, InviterUserName = item.InviterUserName, InviterNum = 0, UserType = userType, upd_tiem = member.upd_time });
|
|
}
|
|
|
|
int o = 1;
|
|
foreach (var user in inviteInfos)
|
|
{
|
|
user.id = o;
|
|
o++;
|
|
var inviterNum = inviteInfos.Count(f => f.InviterUserName == user.Username);
|
|
|
|
user.InviterNum = inviterNum;
|
|
|
|
if (!string.IsNullOrWhiteSpace(user.ImgUrl))
|
|
{
|
|
var fileName = Util.MapFile(user.Username + ".jpg", "Cache\\image");
|
|
if (!File.Exists(fileName))
|
|
FileTools.DownloadImage(user.ImgUrl, fileName);
|
|
user.ImgUrl = fileName;
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(user.InviterUserName))
|
|
{
|
|
var iUser = inviteInfos.FirstOrDefault(f => f.Username == user.InviterUserName);
|
|
if (iUser == null) continue;
|
|
user.InviterUsernick = iUser.Usernick;
|
|
user.InviterImgUrl = iUser.ImgUrl;
|
|
|
|
if (!string.IsNullOrWhiteSpace(user.InviterImgUrl))
|
|
{
|
|
var fileName = Util.MapFile(user.InviterUserName + ".jpg", "Cache\\image");
|
|
if (!File.Exists(fileName))
|
|
FileTools.DownloadImage(user.InviterImgUrl, fileName);
|
|
user.InviterImgUrl = fileName;
|
|
}
|
|
}
|
|
}
|
|
|
|
//inviteInfos = inviteInfos.OrderByDescending(f => f.InviterNum).ToList();
|
|
//int o = 1;
|
|
//foreach (var item in inviteInfos)
|
|
//{
|
|
// item.id = o;
|
|
// o++;
|
|
//}
|
|
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
gridControl2.DataSource = inviteInfos;
|
|
}));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
simpleButton2.Enabled = true;
|
|
}));
|
|
}
|
|
});
|
|
}
|
|
|
|
private void gridView2_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var row = e.Row as InviteInfo;
|
|
if (e.Column.Caption == "用户信息")
|
|
e.Value = $"{row.Usernick}({row.Username})";
|
|
else if (e.Column.Caption == "被谁拉进的群")
|
|
{
|
|
if (string.IsNullOrWhiteSpace(row.InviterUserName)) return;
|
|
e.Value = $"{row.InviterUsernick}({row.InviterUserName})";
|
|
}
|
|
else if (e.Column.Caption == "_")
|
|
{
|
|
Image img = null;
|
|
try
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(row.ImgUrl))
|
|
img = Image.FromFile(row.ImgUrl);
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
//MessageBox.Show(ee.Message);
|
|
}
|
|
|
|
e.Value = img;
|
|
}
|
|
else if (e.Column.Caption == "__")
|
|
{
|
|
Image img = null;
|
|
try
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(row.InviterImgUrl))
|
|
img = Image.FromFile(row.InviterImgUrl);
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
//MessageBox.Show(ee.Message);
|
|
}
|
|
|
|
e.Value = img;
|
|
}
|
|
else if (e.Column.Caption == "状态")
|
|
{
|
|
if (row.UserType == UserType.全部状态)
|
|
e.Value = string.Empty;
|
|
else
|
|
e.Value = row.UserType.ToString();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
|
{
|
|
comboBoxEdit2.Properties.Items.Clear();
|
|
comboBoxEdit2.Properties.Items.Add("请选择对应机器人");
|
|
var clients = ChatClient.WXClient.Values.Where(f => f.WeixinType == WeixinType.Grpc微信 && f.Status == Chat.Framework.WXSdk.WxStatus.在线);
|
|
foreach (var client in clients)
|
|
comboBoxEdit2.Properties.Items.Add($"{client.User.Nick.ToString()}({client.WeixinHao})");
|
|
}
|
|
|
|
private void toolStripMenuItem1_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
int[] rows = this.gridView2.GetSelectedRows();//获取选中行号
|
|
if (rows != null && rows.Length > 0)
|
|
{
|
|
if (MessageBox.Show("确定要踢出选中的用户吗?", "问题提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) != DialogResult.OK)
|
|
return;
|
|
var groupid = tb_groupid.Text.Trim();
|
|
var wx = ChatClient.WXClient.Values.FirstOrDefault(f => f.WeixinType == WeixinType.Grpc微信 && f.Status == Chat.Framework.WXSdk.WxStatus.在线 && comboBoxEdit2.Text.Contains("(" + f.WeixinHao + ")"));
|
|
if (wx == null) throw new Exception("机器人已经离线或一会再试");
|
|
|
|
for (int i = 0; i < rows.Length; i++)
|
|
{
|
|
try
|
|
{
|
|
var row = this.gridView2.GetRow(rows[i]) as InviteInfo;
|
|
if (row == null) continue;
|
|
wx.DeleteGroupMember(row.Username, groupid);
|
|
Thread.Sleep(50);
|
|
}
|
|
catch (Exception ex)
|
|
{ }
|
|
}
|
|
simpleButton2_Click(null, null);
|
|
MessageBox.Show("选中用户已全部踢出");
|
|
}
|
|
else throw new Exception("没有选中的用户");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
} |