150 lines
5.5 KiB
C#
150 lines
5.5 KiB
C#
|
using Api.Framework;
|
|||
|
using Api.Framework.SDK;
|
|||
|
using Chat.Framework;
|
|||
|
using Chat.Framework.WXSdk.Implement;
|
|||
|
using MessageForwarder.Properties;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Text.RegularExpressions;
|
|||
|
using System.Threading;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace MessageForwarder
|
|||
|
{
|
|||
|
public class Class1 : Plugin
|
|||
|
{
|
|||
|
|
|||
|
public Class1()
|
|||
|
{
|
|||
|
this.Name = Resources.PluginName;
|
|||
|
this.Note = Resources.PluginNote;
|
|||
|
this.Logo = Resources.消息转发;
|
|||
|
}
|
|||
|
|
|||
|
#region 自定义变量
|
|||
|
public static Config Config;
|
|||
|
private MainForm mainForm = null;
|
|||
|
//public static VariateReplace variateReplace = null;
|
|||
|
#endregion
|
|||
|
|
|||
|
public override void Start()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
#region 判断表是否存在,不存在创建表
|
|||
|
|
|||
|
#endregion
|
|||
|
Config = this.ReadConfig<Config>();
|
|||
|
|
|||
|
SDK.ReciveIMEvent += SDK_ReciveIMEvent;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
this.OnLog(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override void ShowForm()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (mainForm == null || mainForm.IsDisposed)
|
|||
|
{
|
|||
|
mainForm = new MainForm();
|
|||
|
mainForm.Show();
|
|||
|
}
|
|||
|
mainForm.TopMost = true;
|
|||
|
mainForm.TopMost = false;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
this.OnLog(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override void Stop()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (mainForm != null)
|
|||
|
{
|
|||
|
mainForm.CloseForm();
|
|||
|
mainForm = null;
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
this.OnLog(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private static string _MessMD5 = string.Empty;
|
|||
|
|
|||
|
private void SDK_ReciveIMEvent(object sender, ReciveIMEvent e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (string.IsNullOrWhiteSpace(e.Groupid)) return;
|
|||
|
if (e.Groupid != Config.ClusterId) return;
|
|||
|
if (e.Username != Config.ListeningAccount) return;
|
|||
|
var mess_MD5 = Api.Framework.Tools.Util.GetMd5_32byte(e.Message);
|
|||
|
if (_MessMD5 != mess_MD5)
|
|||
|
{
|
|||
|
_MessMD5 = mess_MD5;
|
|||
|
var result = CsharpHttpHelper.HttpExtend.JsonToDictionary(Class1.Config.Data);
|
|||
|
if (result == null) return;
|
|||
|
var weixinBases = Chat.Framework.ChatClient.WXClient.Values.ToList();
|
|||
|
Parallel.ForEach(result.Keys, (item) =>
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var wx = weixinBases.FirstOrDefault(f => f.WeixinHao == item && f.WeixinType == Chat.Framework.WXSdk.Implement.WeixinType.Grpc微信 && f.Status == Chat.Framework.WXSdk.WxStatus.在线);
|
|||
|
if (wx != null)
|
|||
|
{
|
|||
|
var groupids = result[item].ToString().Replace(",", ",").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(f => f.Trim()).ToList();
|
|||
|
for (int i = 0; i < groupids.Count; i++)
|
|||
|
{
|
|||
|
var mess = e.Message;
|
|||
|
var reg = Regex.Match(e.Message, @"\[图片=(?<图片地址>[^\]]+)\]");
|
|||
|
if (reg.Success)
|
|||
|
{
|
|||
|
var imagePath = reg.Groups["图片地址"].Value;
|
|||
|
var MD5Hash = FileTools.GetMD5Hash(imagePath);
|
|||
|
if (ChatClient.ImageCDNs.ContainsKey(MD5Hash))
|
|||
|
{
|
|||
|
var obj = ChatClient.ImageCDNs[MD5Hash];
|
|||
|
string aeskey = obj.GetType().GetProperty("aeskey").GetValue(obj).ToString();
|
|||
|
string cdnurl = obj.GetType().GetProperty("cdnurl").GetValue(obj).ToString();
|
|||
|
var ipad = e.Sender as WXClientImpl_IPAD;
|
|||
|
if (ipad != null)
|
|||
|
{
|
|||
|
ipad.SendCDNInfo(groupids[i], cdnurl, aeskey, Chat.Framework.WXSdk.IPAD.CDNType.发送图片);
|
|||
|
Thread.Sleep(500);
|
|||
|
continue;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
wx.SendMessage(groupids[i], mess);
|
|||
|
Thread.Sleep(500);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
this.OnLog($"微信:{item} - {ex.Message}");
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
this.OnLog(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|