提交 02c78b33 编写于 作者: K Kerwin

c# example

上级 1f056b9a
......@@ -12,3 +12,4 @@
/wxRobot/bin/Debug/
/wxRobot/bin/Release/*.pdb
*/__pycache__/
packages
\ No newline at end of file
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<WxUserInfo>(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<WxUserInfo>(wx.CGetWxUserInfo(wxId));
Console.WriteLine($"消息类型:{msgType}");
Console.WriteLine($"对话类型:{roomType}");
if (roomType == RoomType.Group)
{
var groupInfo = JsonConvert.DeserializeObject<WxUserInfo>(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,
/// <summary>
/// 服务号群发的消息
/// </summary>
ServiceGroup = 49,
}
enum RoomType
{
Private = 0,
Group = 1,
Service = 2,
Subscription = 3,
}
public class WxUserInfo
{
/// <summary>
/// 原始 id
/// </summary>
public string WxId { get; set; }
/// <summary>
/// 修改过的微信号
/// </summary>
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; }
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
</packages>
\ No newline at end of file
......@@ -33,6 +33,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
......@@ -48,6 +51,18 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<COMReference Include="WeChatRobotCOMLib">
<Guid>{721ABB35-141A-4AA2-94F2-762E2833FA6C}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>False</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册