old_flsystem/PCRobot/PCWechat/Wechat_Xiaoxie_QY_Override.cs

743 lines
34 KiB
C#
Raw Permalink Normal View History

2022-09-20 03:10:29 +00:00
using CsharpHttpHelper;
using Newtonsoft.Json;
using NM_WeChat;
using PCRobot.Entitys;
using PCRobot.Pack;
using PCRobot.Properties;
using PCRobot.Utils;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Caching;
using System.Windows.Forms;
namespace PCRobot.PCWechat
{
/*
https://www.showdoc.cc/WxWorkNewHook?page_id=3846144660177490
/////密码784615627.
*/
public partial class Wechat_Xiaoxie_QY
{
public override void AgreeAddMe(string text)
{
try
{
if (string.IsNullOrWhiteSpace(text)) return;
var reg = Regex.Match(text, @"{""user_id"":""(?<user_id>[^""]+?)"",""corp_id"":""(?<corp_id>[^""]+?)""}");
if (reg.Success)
{
var user_id = reg.Groups["user_id"].Value;
var corp_id = reg.Groups["corp_id"].Value;
var __json = CsharpHttpHelper.HttpHelper.ObjectToJson(new { type = MsgType.MT_ACCEPT_FRIEND_REQUEST, data = new { user_id = user_id, corp_id = corp_id } });
SendWxWorkData(User.DwClientId, __json);
}
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, ex.Message + "-._");
}
}
public override void DeleteFriend(string wxid)
{
try
{
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, ex.Message + "._");
}
}
public override void EditCotacts(string wxid, string remark)
{
try
{
var json = CsharpHttpHelper.HttpHelper.ObjectToJson(new { type = MsgType.MT_MODIFY_USER_REMARK_MSG, data = new { user_id = wxid, remark = remark } });
SendWxWorkData(User.DwClientId, json);
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, ex.Message + "*_");
}
}
/// <summary>
/// 创建群
/// </summary>
/// <param name="wxidData"></param>
public override void CreateRoom(string wxidData)
{
try
{
if (string.IsNullOrWhiteSpace(wxidData)) return;
var wxids = wxidData.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
if (wxids != null && wxids.Length != 0)
{
var json = HttpHelper.ObjectToJson(new { type = MsgType.MT_CREATE_ROOM_MSG, data = wxids });
SendWxWorkData(User.DwClientId, json);
}
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, ex.Message);
}
}
/// <summary>
/// 邀请用户进群
/// </summary>
/// <param name="conversation_id"></param>
/// <param name="wxid"></param>
public override void InviteMemberToRoom_40Up(string conversation_id, string wxidData)
{
try
{
if (conversation_id.Trim().StartsWith("R:"))
{
var wxids = wxidData.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
var json = HttpHelper.ObjectToJson(new { type = MsgType.MT_ROOM_ADD_MEMBERS_MSG, data = new { conversation_id = conversation_id, user_list = wxids } });
SendWxWorkData(User.DwClientId, json);
}
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, ex.Message + ".._.");
}
}
public override void InviteMemberToRoom_40Down(string groupid, string wxidData)
{
InviteMemberToRoom_40Up(groupid, wxidData);
}
public override void DeleteRoomMember(string wxid, string room)
{
try
{
if (room.Trim().StartsWith("R:"))
{
var json = HttpHelper.ObjectToJson(new { type = MsgType.MT_ROOM_DEL_MEMBERS_MSG, data = new { conversation_id = room, user_list = new string[] { wxid } } });
SendWxWorkData(User.DwClientId, json);
}
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, ex.Message);
}
}
public override void GetContact()
{
try
{
var json = CsharpHttpHelper.HttpHelper.ObjectToJson(new { type = MsgType.MT_GET_EXTERNAL_USERS_MSG, data = new { } });
SendWxWorkData(User.DwClientId, json);
Thread.Sleep(1000);
json = CsharpHttpHelper.HttpHelper.ObjectToJson(new { type = MsgType.MT_GET_ROOMS_MSG, data = new { } });
SendWxWorkData(User.DwClientId, json);
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, ex.Message + "_*");
}
}
public override void GetContact(bool isUpdate)
{
try
{
var result = GetFriendInfos(true);
var socketClient = EasySoc.GetSocket();
CommonResult msg = new CommonResult();
msg.RobotUsername = User.Wxid;
msg.RobotUsernick = User.Nickname;
msg.RobotType = RobotType.;
msg.MsgId = ServerMsgID;
msg.Cmd = PCRobotCMD.rcvFriendList_workWeChat;
msg.Data = result == null ? string.Empty : HttpHelper.ObjectToJson(result);
socketClient.Send(msg);
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new StackTrace().GetFrame(0).GetMethod().Name, ex.Message);
}
}
/// <summary>
/// 获取好友列表
/// </summary>
/// <param name="flushGroupsCache">刷新缓存数据</param>
/// <returns></returns>
//public override List<WorkFriendInfo> GetFriendInfos(bool flushGroupsCache = false)
public override string GetFriendInfos(bool flushGroupsCache = false)
{
List<WorkFriendInfo> friends = null;
try
{
#region
friends = User.WorkFriends.Where(f => !f.user_id.Contains("R:")).ToList();
if (!flushGroupsCache && friends.Count != 0)
return JsonConvert.SerializeObject(friends);
#endregion
if (!User.IsGetFriend)
{
//获取好友列表(数据库读取)
var json = HttpHelper.ObjectToJson(new { type = MsgType.MT_GET_EXTERNAL_USERS_MSG, data = new { } });
SendWxWorkData(User.DwClientId, json);
User.IsGetFriend = true;
}
var result_ = Task.Factory.StartNew<List<WorkFriendInfo>>(delegate ()
{
DateTime end_time = DateTime.Now.AddSeconds(20);
do
{
if (!User.IsGetFriend)
{
friends = User.WorkFriends.Where(f => !f.user_id.Contains("R:")).ToList();
return friends;
}
Thread.Sleep(200);
} while (end_time > DateTime.Now);
return null;
}).Result;
//return friends;
return JsonConvert.SerializeObject(friends);
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new StackTrace().GetFrame(0).GetMethod().Name, ex.Message + "#__#");
}
return string.Empty;
}
public override void GetGroupAndFriendInfo(string groupId, string wxid)
{
try
{
var json = string.Empty;
WorkGroupInfo group = null;
if (groupId.Contains("R:"))
{
json = HttpHelper.ObjectToJson(new { type = MsgType.MT_GET_ROOM_MEMBERS_MSG, data = new { conversation_id = groupId } });
var g = User.WorkGroups.FirstOrDefault(f => f.conversation_id == groupId);
//User.WorkGroups.Clear();
if (g != null)
{
var u = g.friends.FirstOrDefault(f => f.user_id == wxid);
if (u != null)
group = new WorkGroupInfo() { conversation_id = groupId, friends = new List<WorkFriendInfo>() { u }, total = g.total };
}
if (group == null)
{
SendWxWorkData(User.DwClientId, json);
var _group = Task.Factory.StartNew<WorkGroupInfo>(delegate ()
{
DateTime end_time = DateTime.Now.AddSeconds(15);
do
{
g = User.WorkGroups.FirstOrDefault(f => f.conversation_id == groupId);
if (g != null)
{
var u = g.friends.FirstOrDefault(f => f.user_id == wxid);
if (u != null)
{
group = new WorkGroupInfo() { conversation_id = groupId, friends = new List<WorkFriendInfo>() { u }, total = g.total };
return group;
}
}
Thread.Sleep(200);
} while (end_time > DateTime.Now);
return null;
}).Result;
}
}
var socketClient = EasySoc.GetSocket();
var msg = new WorkWechatContact();
msg.RobotUsername = User.Wxid;
msg.RobotUsernick = User.Nickname;
msg.RobotType = RobotType.;//客户端微信;
msg.MsgId = ServerMsgID;
msg.Cmd = PCRobotCMD.rcvContact_workWeChat;
msg.Message = group == null ? string.Empty : HttpHelper.ObjectToJson(group);
socketClient.Send(msg);
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, ex.Message + "/_");
}
}
public override void GetGroupAndFriendInfo(string groupId, string wxid, bool flush = false)
{
try
{
var json = string.Empty;
WorkGroupInfo group = null;
if (groupId.Contains("R:"))
{
json = HttpHelper.ObjectToJson(new { type = MsgType.MT_GET_ROOM_MEMBERS_MSG, data = new { conversation_id = groupId } });
var g = User.WorkGroups.FirstOrDefault(f => f.conversation_id == groupId);
//User.WorkGroups.Clear();
if (g != null)
{
if (flush)
{
g.friends.Clear();
}
else
{
var u = g.friends.FirstOrDefault(f => f.user_id == wxid);
if (u != null)
group = new WorkGroupInfo() { conversation_id = groupId, friends = new List<WorkFriendInfo>() { u }, total = g.total };
}
}
if (group == null)
{
SendWxWorkData(User.DwClientId, json);
var _group = Task.Factory.StartNew<WorkGroupInfo>(delegate ()
{
DateTime end_time = DateTime.Now.AddSeconds(15);
do
{
g = User.WorkGroups.FirstOrDefault(f => f.conversation_id == groupId);
if (g != null)
{
var u = g.friends.FirstOrDefault(f => f.user_id == wxid);
if (u != null)
{
group = new WorkGroupInfo() { conversation_id = groupId, friends = new List<WorkFriendInfo>() { u }, total = g.total };
return group;
}
}
Thread.Sleep(200);
} while (end_time > DateTime.Now);
return null;
}).Result;
}
}
var socketClient = EasySoc.GetSocket();
var msg = new WorkWechatContact();
msg.RobotUsername = User.Wxid;
msg.RobotUsernick = User.Nickname;
msg.RobotType = RobotType.;//客户端微信;
msg.MsgId = ServerMsgID;
msg.Cmd = PCRobotCMD.rcvContact_workWeChat;
msg.Message = group == null ? string.Empty : HttpHelper.ObjectToJson(group);
socketClient.Send(msg);
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, ex.Message + "/_");
}
}
public override void GetWxidInfo(string wxid)
{
try
{
var json = string.Empty;
var u = User.WorkFriends.FirstOrDefault(f => f.user_id == wxid);
if (u == null)
{
if (wxid.Contains("R:"))
{
json = HttpHelper.ObjectToJson(new { type = MsgType.MT_GET_ROOMS_MSG, data = new { } });
}
else
json = HttpHelper.ObjectToJson(new { type = MsgType.MT_GET_USER_DETAIL_MSG, data = new { user_id = wxid } });
SendWxWorkData(User.DwClientId, json);
var friend = Task.Factory.StartNew<WorkFriendInfo>(delegate ()
{
DateTime end_time = DateTime.Now.AddSeconds(15);
do
{
u = User.WorkFriends.FirstOrDefault(f => f.user_id == wxid);
if (u != null) return u;
Thread.Sleep(200);
} while (end_time > DateTime.Now);
return null;
}).Result;
}
var socketClient = EasySoc.GetSocket();
var msg = new WorkWechatContact();
msg.RobotUsername = User.Wxid;
msg.RobotUsernick = User.Nickname;
msg.RobotType = RobotType.;//客户端微信;
msg.MsgId = ServerMsgID;
msg.Cmd = PCRobotCMD.rcvContact_workWeChat;
msg.Message = u == null ? string.Empty : HttpHelper.ObjectToJson(u);
socketClient.Send(msg);
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new StackTrace().GetFrame(0).GetMethod().Name, ex.Message + "_/");
}
}
public override void SendImage(string wxid, string file)
{
//try
//{
// var conversation_id = wxid;
// if (!wxid.StartsWith("R:"))
// {
// conversation_id = $"S:{User.Wxid}_{wxid}";
// }
// var json = HttpHelper.ObjectToJson(new { type = MsgType.MT_SEND_IMAGE_MSG, data = new { conversation_id = conversation_id, file = file } });
// SendWxWorkData(User.DwClientId, json);
//}
//catch (Exception ex)
//{
// LogHelper.GetSingleObj().Error(new StackTrace().GetFrame(0).GetMethod().Name, ex.Message + ".-");
//}
try
{
var conversation_id = wxid;
if (!wxid.StartsWith("R:"))
conversation_id = $"S:{User.Wxid}_{wxid}";
if (file.StartsWith("http", StringComparison.InvariantCultureIgnoreCase))
{
byte[] ImangByte = null;
string extension = Path.GetExtension(file);
extension = string.IsNullOrWhiteSpace(extension) ? ".jpg" : extension;
ImangByte = new System.Net.WebClient().DownloadData(file);
byte[] imageHash = new MD5CryptoServiceProvider().ComputeHash(ImangByte);
var path = Common.CacheFilePath(User.Wxid, conversation_id, "IMAGE", Guid.NewGuid().ToString("N"), extension);
if (!File.Exists(path))
{
File.WriteAllBytes(path, ImangByte);
}
if (File.Exists(path))
file = path;
}
else
{
if (!File.Exists(file))
{
if (Common.IsBase64(file))
{
var path = Common.CacheFilePath(User.Wxid, wxid, "IMAGE", Guid.NewGuid().ToString("N"), "jpg");
if (Common.Base64ToFileAndSave(file, path) && File.Exists(path))
{
file = path;
}
}
else
{ }
}
}
var json = string.Empty;
if (File.Exists(file))
{
if (file.Trim().EndsWith(".gif", StringComparison.CurrentCultureIgnoreCase))
json = HttpHelper.ObjectToJson(new { type = MsgType.MT_SEND_GIF_MSG, data = new { conversation_id = conversation_id, file = file } });
else
json = HttpHelper.ObjectToJson(new { type = MsgType.MT_SEND_IMAGE_MSG, data = new { conversation_id = conversation_id, file = file } });
}
else
json = HttpHelper.ObjectToJson(new { type = MsgType.MT_SEND_IMAGE_MSG, data = new { conversation_id = conversation_id, file = file } });
SendWxWorkData(User.DwClientId, json);
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Debug("发送图片异常", ex.Message + ".-" + ex.StackTrace);
}
}
public override void SendMessage(string wxid, string message)
{
try
{
//S:1688853956558440_7881301364988874
//{"data":{"content":"我们","content_type":2,"conversation_id":"S:1688853956558440_7881301364988874","local_id":"61","receiver":"1688853956558440","send_time":"1584028171","sender":"7881301364988874","sender_name":"18","server_id":"1000653"},"type":11041}
var conversation_id = wxid;
if (!wxid.StartsWith("R:"))
{
conversation_id = $"S:{User.Wxid}_{wxid}";
}
else
{ }
var json = string.Empty;
message = message.Replace("\r\n", "\n");
if (Common.isXML(message))
{
message = message.Replace("&amp;", "&");
var title = string.Empty;
var desc = string.Empty;
var url = string.Empty;
var image_url = string.Empty;
var reg = Regex.Match(message, @"<title>(?<标题>[\w\W]+?)</title>");
if (reg.Success) title = reg.Groups["标题"].Value;
reg = Regex.Match(message, @"<des>(?<介绍>[\w\W]+?)</des>");
if (reg.Success) desc = reg.Groups["介绍"].Value.Replace("<![CDATA[", "").Replace("]]", "");
reg = Regex.Match(message, @"<url>(?<链接>[\w\W]+?)</url>");
if (!reg.Success) reg = Regex.Match(message, @"<pagepath>(?<链接>[\w\W]+?)</pagepath>");
if (reg.Success) url = reg.Groups["链接"].Value;
reg = Regex.Match(message, @"<thumburl>(?<图片链接>[\w\W]+?)</thumburl>");
if (reg.Success) image_url = reg.Groups["图片链接"].Value;
if (message.Contains("<image_key1>"))
{
var image_key1 = string.Empty;
var image_key2 = string.Empty;
var image_key3 = string.Empty;
var image_size = 0;
var ghid = string.Empty;
var pagepath = string.Empty;
var regKey = Regex.Match(message, @"<image_key1>(?<image_key1>[\w\W]+?)</image_key1>", RegexOptions.IgnoreCase);
if (regKey.Success)
image_key1 = regKey.Groups["image_key1"].Value;
regKey = Regex.Match(message, @"<image_key2>(?<image_key2>[\w\W]+?)</image_key2>", RegexOptions.IgnoreCase);
if (regKey.Success)
image_key2 = regKey.Groups["image_key2"].Value;
regKey = Regex.Match(message, @"<image_key3>(?<image_key3>[\w\W]+?)</image_key3>", RegexOptions.IgnoreCase);
if (regKey.Success)
image_key3 = regKey.Groups["image_key3"].Value;
regKey = Regex.Match(message, @"<image_size>(?<image_size>[\w\W]+?)</image_size>", RegexOptions.IgnoreCase);
if (regKey.Success)
image_size = int.Parse(regKey.Groups["image_size"].Value.XMLReplace(false));
regKey = Regex.Match(message, @"<username>(?<username>[\w\W]+?)</username>", RegexOptions.IgnoreCase);
if (regKey.Success)
ghid = regKey.Groups["username"].Value;
regKey = Regex.Match(message, @"<pagepath>(?<pagepath>[\w\W]+?)</pagepath>", RegexOptions.IgnoreCase);
if (regKey.Success)
pagepath = regKey.Groups["pagepath"].Value;
var weapppagethumbrawurl = string.Empty;
regKey = Regex.Match(message, @"<weapppagethumbrawurl>(?<weapppagethumbrawurl>[\w\W]+?)</weapppagethumbrawurl>", RegexOptions.IgnoreCase);
if (regKey.Success)
weapppagethumbrawurl = regKey.Groups["weapppagethumbrawurl"].Value;
var _json = HttpHelper.ObjectToJson(new { type = MsgType.MT_SEND_MINI_PROGRAM_MSG, data = new { conversation_id = conversation_id, ghid = ghid.XMLReplace(false), wxid = conversation_id, name = title, title = desc, enterpoint = pagepath.XMLReplace(false), headimg = weapppagethumbrawurl.XMLReplace(false), image_key1 = image_key1.XMLReplace(false), image_key2 = image_key2.XMLReplace(false), image_key3 = image_key3.XMLReplace(false), image_size = image_size } });
SendWxWorkData(User.DwClientId, _json);
return;
}
else
{
image_url =
json = CsharpHttpHelper.HttpHelper.ObjectToJson(new { type = MsgType.MT_SEND_LINK_MSG, data = new { conversation_id = conversation_id, title = $"{title.XMLReplace(false)}", desc = $"{desc.XMLReplace(false)}", url = url.XMLReplace(false), image_url = image_url.XMLReplace(false) } });
}
}
else
{
var atUsername = new List<string>();
var regs = Regex.Matches(message, @"\[@([^\]]+?)\]");
if (regs.Count != 0 && wxid.StartsWith("R:"))
{
foreach (Match item in regs)
{
atUsername.Add(item.Groups[1].Value.Trim());
}
message = Regex.Replace(message, @"(\[@[^\]]+?\])", "{$@}");
json = CsharpHttpHelper.HttpHelper.ObjectToJson(new { type = MsgType.MT_SEND_ROOM_AT_MSG, data = new { conversation_id = conversation_id, content = message, at_list = atUsername.ToArray() } });
}
else
json = CsharpHttpHelper.HttpHelper.ObjectToJson(new { type = MsgType.MT_SEND_TEXT_MSG, data = new { conversation_id = conversation_id, content = message } });
}
SendWxWorkData(User.DwClientId, json);
//LogHelper.GetSingleObj().Debug("发送状态", ($"发送:{conversation_id} - {flag}, 内容:{message}"));
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, ex.Message + "-.");
}
}
/// <summary>
/// 发送小程序
/// </summary>
/// <param name="wxid">发送给谁</param>
/// <param name="dataJson">发送的内容json打包</param>
public override void SendProgramMessage(string wxid, string dataJson)
{
try
{
/*
"conversation_id": "S:16888xxxx_7881xxxxx",
"ghid": "gh_52b46203a658@app",
"wxid": "wx35f2a3937c9df889",
"name": "博鸟绘本",
"title": "博鸟绘本,最新最全的儿童绘本租赁平台~",
"enterpoint": "pages/shouye/shouye.html",
"headimg": "http://wx.qlogo.cn/mmhead/xxxx/96",
"image_key1": "306b020102046430620201000xxxxx",
"image_key2": "61706264616C7A77666875xxxx",
"image_key3": "b302e94d9c6f95xxxxxx",
"image_size": 56448
*/
//个人微信/企业微信
//{"data":{"content_type":78,"conversation_id":"R:10696053211018728","enterpoint":"pages/tab/home/index.html?_um_ssrc=oucfI5QRI-8SbyOTKSGYt5-ia0dk&_um_sts=1610033684099","ghid":"gh_a0d7a7672cf7@app","headimg":"http://wx.qlogo.cn/mmhead/Q3auHgzwzM43LsxpXHKd7ua7kwMZQ8WHmZlkYTzr3Tdm8sMOJ7Ypog/96","image_key1":"306b020102046430620201000204bafc490e02030f4df9020473e6607102045ff72a530436333133373039353935305f313734393433343231315f3262393764653133616335373232353633383831336564376334396563616164020100020300ab1004000201010201000400","image_key2":"61747072666A766977766D69726D6168","image_key3":"2b97de13ac57225638813ed7c49ecaad","image_size":43791,"is_pc":0,"local_id":"155","name":"啄木鸟家庭维修","receiver":"1688853956558440","send_time":"1610033747","sender":"7881302484994318","sender_name":"、","server_id":"1042188","title":"直营一口价,维修无猫腻","wxid":"wx3d6b1af0cb07fa5a"},"type":11066}
var conversation_id = wxid;
if (!wxid.StartsWith("R:"))
conversation_id = $"S:{User.Wxid}_{wxid}";
var json = CsharpHttpHelper.HttpExtend.JsonToDictionary(dataJson);
var data = json.ContainsKey("data") ? json["data"] as Dictionary<string, object> : null;
if (data == null) return;
//var content_type = data["content_type"]?.ToString();//内容类型 78
//var conversation_id = data["conversation_id"]?.ToString();//接收者的的会话ID
//var receiver = data["receiver"]?.ToString();//接收者的user_id
//var sender = data["sender"]?.ToString();//发送者的user_id
//var sender_name = data["sender_name"]?.ToString();//发送者昵称
//var server_id = data["server_id"]?.ToString();//消息的服务器ID
var enterpoint = data["enterpoint"]?.ToString();//入口点 - 链接(小程序里面的链接)
var headimg = data["headimg"]?.ToString();//小程序的头像
var name = data["name"]?.ToString();//小程序的名称
var title = data["title"]?.ToString();//小程序标题
var _wxid = data["wxid"]?.ToString();
var image_size = int.Parse(data["image_size"].ToString());
var image_key1 = data["image_key1"]?.ToString();
var image_key2 = data["image_key2"]?.ToString();
var image_key3 = data["image_key3"]?.ToString();
var ghid = data["ghid"]?.ToString();
var _json = HttpHelper.ObjectToJson(new { type = MsgType.MT_SEND_MINI_PROGRAM_MSG, data = new { conversation_id = conversation_id, ghid = ghid, wxid = _wxid, name = name, title = title, enterpoint = enterpoint, headimg = headimg, image_key1 = image_key1, image_key2 = image_key2, image_key3 = image_key3, image_size = image_size } });
SendWxWorkData(User.DwClientId, _json);
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error("发送小程序异常", ex.Message + ex.StackTrace);
}
}
public override void SendVideo(string wxid, string file)
{
try
{
var conversation_id = wxid;
if (!wxid.StartsWith("R:"))
{
conversation_id = $"S:{User.Wxid}_{wxid}";
}
var json = CsharpHttpHelper.HttpHelper.ObjectToJson(new { type = MsgType.MT_SEND_VIDEO_MSG, data = new { conversation_id = conversation_id, file = file } });
SendWxWorkData(User.DwClientId, json);
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, ex.Message + "-_");
}
}
public override void SendFile(string wxid, string file)
{
try
{
var conversation_id = wxid;
if (!wxid.StartsWith("R:"))
{
conversation_id = $"S:{User.Wxid}_{wxid}";
}
var json = CsharpHttpHelper.HttpHelper.ObjectToJson(new { type = MsgType.MT_SEND_FILE_MSG, data = new { conversation_id = conversation_id, file = file } });
SendWxWorkData(User.DwClientId, json);
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, ex.Message + "_-");
}
}
public override void SendCard(string to_wxid, string card_wxid)
{
try
{
var conversation_id = to_wxid;
if (!to_wxid.StartsWith("R:"))
{
conversation_id = $"S:{User.Wxid}_{to_wxid}";
}
if (card_wxid.StartsWith("R:"))
{
InviteMemberToRoom_40Up(card_wxid, to_wxid);
return;
}
var json = CsharpHttpHelper.HttpHelper.ObjectToJson(new { type = MsgType.MT_SEND_PERSON_CARD_MSG, data = new { conversation_id = conversation_id, user_id = card_wxid } });
SendWxWorkData(User.DwClientId, json);
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, ex.Message + "--");
}
}
public override void CloseWechat(string message)
{
try
{
var v = WechatClient.Users.FirstOrDefault(f => f.Value.DwClientId == User.DwClientId && f.Value.Type == WechatType.Xiaoxie_QY).Value;
if (v != null)
{
LogHelper.GetSingleObj().Info("系统", $"CloseWechatQY事件退出,Uin:{v.Uin},微信:{v.Nickname}({v.Wxid})");
WechatClient.RemoveUser(v, true);
if (!string.IsNullOrWhiteSpace(message))
PCRobotForm.ErrorMessAction?.Invoke(message);
}
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, ex.Message + "//");
}
}
}
}