diff --git a/.gitignore b/.gitignore index 604101a5563bb04e468a18833dbc9a7e8816fda4..a79607ec29b2c799478629d66fd9669250c9ab47 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ /wxRobot/bin/Debug/ /wxRobot/bin/Release/*.pdb */__pycache__/ +packages \ No newline at end of file diff --git a/wxRobot/Program.cs b/wxRobot/Program.cs index 01ddad0e7436d7c630d109f691ec49f6be6918d3..9f9fb68105a8bd1b8ae4c27b3da8eb2ec5f375d3 100644 --- a/wxRobot/Program.cs +++ b/wxRobot/Program.cs @@ -1,4 +1,9 @@ -using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.ComponentModel; +using System.Runtime.InteropServices; +using System.Threading; namespace wxRobot { @@ -6,25 +11,143 @@ namespace wxRobot { static void Main() { - System.Type wxProtId = Type.GetTypeFromProgID("WeChatRobot.CWeChatRobot"); - if (wxProtId == null) - return; - string workpath = System.AppDomain.CurrentDomain.BaseDirectory; - string basePath = workpath.Replace("wxRobot\\bin\\Release\\",""); - dynamic wx = Activator.CreateInstance(wxProtId); - wx.CStartRobotService(); - wx.CSendText("filehelper", "来自C艹艹的消息"); - wx.CSendImage("filehelper", basePath + "test\\测试图片.png"); - wx.CSendFile("filehelper", basePath + "test\\测试文件"); - wx.CSendArticle("filehelper","PC微信逆向--获取通讯录", "确定不来看看么?", "https://www.ljczero.top/article/2022/3/13/133.html"); - string selfinfo = wx.CGetSelfInfo(); - Console.WriteLine(selfinfo); - System.Object[,,] FriendList = wx.CGetFriendList(); - int length = FriendList.GetLength(0); - for (int i = 0; i < 1/*length*/; i++) { - Console.WriteLine(FriendList[i, 0, 1]); + var wx = new WeChatRobotCOMLib.WeChatRobotClass(); + try + { + string workpath = System.AppDomain.CurrentDomain.BaseDirectory; + string basePath = workpath.Replace("wxRobot\\bin\\Release\\", ""); + + wx.CStartRobotService(); + + wx.CSendText("filehelper", "来自C艹艹的消息"); + wx.CSendImage("filehelper", basePath + "test\\测试图片.png"); + wx.CSendFile("filehelper", basePath + "test\\测试文件"); + wx.CSendArticle("filehelper", "PC微信逆向--获取通讯录", "确定不来看看么?", "https://www.ljczero.top/article/2022/3/13/133.html"); + + var selfinfo = wx.CGetSelfInfo(); + if (string.IsNullOrWhiteSpace(selfinfo)) + { + Console.WriteLine("无法获取用户信息"); + wx.CStopRobotService(); + return; + } + Console.WriteLine(selfinfo); + var info = JsonConvert.DeserializeObject(selfinfo); + + wx.CStartReceiveMessage(); + + try + { + while (true) + { + var message = wx.CReceiveMessage() as System.Object[,]; + if (message == null) + { + Thread.Sleep(500); + continue; + } + var msgType = (MessageType)Convert.ToInt32(message[0, 1]); + var sender = message[1, 1].ToString(); + var wxId = message[2, 1].ToString(); + var roomType = RoomType.Private; + if (msgType == MessageType.ServiceGroup) + { + roomType = RoomType.Service; + } + else if (sender != wxId) + { + roomType = RoomType.Group; + } + var content = message[3, 1].ToString(); + var filePath = message[4, 1].ToString(); + var wxUser = JsonConvert.DeserializeObject(wx.CGetWxUserInfo(wxId)); + Console.WriteLine($"消息类型:{msgType}"); + Console.WriteLine($"对话类型:{roomType}"); + if (roomType == RoomType.Group) + { + var groupInfo = JsonConvert.DeserializeObject(wx.CGetWxUserInfo(sender)); + Console.WriteLine($"群:{groupInfo.WxId}\t{groupInfo.WxNickName}"); + } + Console.WriteLine($"来自:{wxUser.WxNumber}\t{wxUser.WxNickName}"); + Console.WriteLine($"内容:{content}"); + Console.WriteLine(); + Thread.Sleep(500); + } + } + catch (Exception ex) + { + Console.WriteLine(ex); + } + finally + { + wx.CStopReceiveMessage(); + } + + + System.Object[,,] FriendList = wx.CGetFriendList() as System.Object[,,]; + int length = FriendList.GetLength(0); + for (int i = 0; i < 1/*length*/; i++) + { + Console.WriteLine(FriendList[i, 1, 1]); + } + } + catch (Exception ex) + { + Console.WriteLine(ex); + } + finally + { + + wx.CStopRobotService(); } - wx.CStopRobotService(); } } + + enum MessageType + { + Text = 1, + + Image = 3, + + /// + /// 服务号群发的消息 + /// + ServiceGroup = 49, + } + + enum RoomType + { + Private = 0, + + Group = 1, + + Service = 2, + + Subscription = 3, + } + + + public class WxUserInfo + { + /// + /// 原始 id + /// + public string WxId { get; set; } + /// + /// 修改过的微信号 + /// + public string WxNumber { get; set; } + public string WxV3 { get; set; } + public string WxRemark { get; set; } + public string WxNickName { get; set; } + public string WxBigAvatar { get; set; } + public string WxSmallAvatar { get; set; } + public string WxSignature { get; set; } + public string WxNation { get; set; } + public string WxProvince { get; set; } + public string WxCity { get; set; } + public string WxBackground { get; set; } + public string PhoneNumber { get; set; } + } + } diff --git a/wxRobot/packages.config b/wxRobot/packages.config new file mode 100644 index 0000000000000000000000000000000000000000..5eaa239b49e08a8e2a83565b69aadf65161c6e35 --- /dev/null +++ b/wxRobot/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/wxRobot/wxRobot.csproj b/wxRobot/wxRobot.csproj index 81d2986caec3e9d1924818ae1b46e416e85061ce..295224444141de8f2d1ee56e5c4705cc33a55723 100644 --- a/wxRobot/wxRobot.csproj +++ b/wxRobot/wxRobot.csproj @@ -33,6 +33,9 @@ 4 + + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll + @@ -48,6 +51,18 @@ + + + + + {721ABB35-141A-4AA2-94F2-762E2833FA6C} + 1 + 0 + 0 + tlbimp + False + False + \ No newline at end of file