C#+FlaUI自动化+chatGPT实现微信AI问答Namenull

1、将文件传输助手置顶,模拟鼠标点击文件传输助手;

2、一直刷新会话列表,有新的消息就需要回复内容;

3、当刷新到新的消息时,模拟鼠标点击到对应的会话人,此时判断是群聊还是人,如果是群聊则不回复。

4、获取消息后转发给chatGPT,同时等待chatGPT回复内容。

6、模拟鼠标点击文件传输助手,等待其它消息。

三、功能代码

3.1、获取聊天消息并发送

voidGetChatInfo

{

if(!IsInit)

return;

}

if(wxWindow==null)

//wxWindow.FindAllDescendants(x=>x.ByControlType(FlaUI.Core.Definitions.ControlType.Button)).AsParallel.FirstOrDefault(s=>s!=null&&s.Name=="聊天").Click(false);

wxWindow.FindFirstDescendant(cf=>cf.ByName("聊天")).Click(false);

Task.Run(=>

AutomationElementassFirst=null;

objectobj=newobject;

while(true)

if(ChatListCancellationToken.IsCancellationRequested)

break;

try

DateTimedateTime3=DateTime.Now;

varsearchTextBox=wxWindow.FindFirstDescendant(cf=>cf.ByName("会话")).AsListBoxItem;

if(searchTextBox!=null)

varlist=searchTextBox.FindAllChildren;

if(assFirst==null)

assFirst=list.AsParallel.FirstOrDefault(t=>t!=null&&"文件传输助手".Equals(t.Name));//并行查询---需要将文件传输助手置顶

assFirst.Click;

continue;

Parallel.ForEach(list,item=>

if(item!=null&&!string.IsNullOrEmpty(item.Name)&&!"折叠置顶聊天".Equals(item.Name)

&&!"腾讯新闻".Equals(item.Name)&&!"群聊".Contains(item.Name))

DateTimet1=DateTime.Now;

varallText=item.FindAllByXPath(".//Text");//定位元素的局部搜索:.//Text;全局搜索://*/Text

DateTimet2=DateTime.Now;

Trace.WriteLine($"allText用时:{(t2-t1).TotalMilliseconds}ms");

//回复消息列表还未回复的

if(allText!=null&&allText.Length>=4)

if(int.TryParse(allText[3].Name,outvarcount)&&count>0)

lock(obj)

varname=allText[0].Name;

vartime=allText[1].Name;

varcontent=allText[2].Name;

if(wxWindow.Patterns.Window.PatternOrDefault!=null)

wxWindow.Patterns.Window.Pattern.SetWindowVisualState(FlaUI.Core.Definitions.WindowVisualState.Normal);

item.Click;

DateTimet7=DateTime.Now;

varitemFirst=wxWindow.FindAllDescendants(x=>x.ByControlType(FlaUI.Core.Definitions.ControlType.Text)).AsParallel

.FirstOrDefault(t=>t!=null&&t.Parent.ControlType==ControlType.Pane&&!t.IsOffscreen&&t.Name.Trim.IsSpecificNumbers);

DateTimet8=DateTime.Now;

Trace.WriteLine($"itemFirst:{(t8-t7).TotalMilliseconds}ms");

//判断是否为群聊

if(itemFirst==null)

AutoGetMesg(content);

});

DateTimedateTime4=DateTime.Now;

Trace.WriteLine($"任务888耗时:{(dateTime4-dateTime3).TotalMilliseconds}ms");

else

Thread.Sleep(10);

//ScrollEvent(-700);

catch(Exceptionex)

finally

//awaitTask.Delay(1);

},ChatListCancellationToken);

3.2、自动回复IChat_chat;

privatevoidAutoGetMesg(stringtxt)

if(_chat==null)

_chat=newChatAchieve;

_chat.RequestContent=GetMessage;

Trace.WriteLine($"发送消息:{txt}");

_chat.RequestGPT(txt);

privateFlaUI.Core.AutomationElements.TextBox_mesText;

publicFlaUI.Core.AutomationElements.TextBoxMesText

get

if(_mesText==null)

_mesText=wxWindow.FindFirstDescendant(x=>x.ByControlType(FlaUI.Core.Definitions.ControlType.Text)).AsTextBox;

return_mesText;

privateAutomationElement_btnSend;

publicAutomationElementbtnSend

if(_btnSend==null)

_btnSend=wxWindow.FindFirstDescendant(cf=>cf.ByName("sendBtn"));

//_btnSend=wxWindow.FindAllDescendants(x=>x.ByControlType(FlaUI.Core.Definitions.ControlType.Button)).FirstOrDefault(s=>s.Name=="发送(S)");

return_btnSend;

constint_offSize=300;

privatevoidGetMessage(stringmes)

SendMes(mes);

Trace.WriteLine($"回复:{mes}");

privatevoidSendMes(stringmes)

inttempLen=0;

stringtxt=string.Empty;

if(!string.IsNullOrWhiteSpace(mes))

string[]lines=mes.Split(Environment.NewLine);

foreach(stringlineinlines)

tempLen+=line.Length;

txt+=line+Environment.NewLine;

if(tempLen>_offSize)

MesText.Text=txt;

btnSend.Click;

tempLen=0;

txt=string.Empty;

if(!string.IsNullOrWhiteSpace(txt))

Thread.Sleep(3);

Trace.WriteLine(ex.Message);

3.3、其它代码///

///启动

///

///

///

privatevoidbtnStart_Click(objectsender,EventArgse)

InitWechat;

privatevoidFrmMain_Load(objectsender,EventArgse)

privatevoidFrmMain_FormClosing(objectsender,FormClosingEventArgse)

this.Dispose;

GC.Collect;

privateCancellationTokenFriendCancellationToken{get;set;}

privateCancellationTokenSourceFriendTokenSource{get;set;}

privateCancellationTokenChatListCancellationToken{get;set;}

privateCancellationTokenSourceChatListTokenSource{get;set;}

privateCancellationTokenGetFriendCancellationToken{get;set;}

privateCancellationTokenSourceGetFriendTokenSource{get;set;}

///

privateintProcessId{get;set;}

privateWindowwxWindow{get;set;}

privateboolIsInit{get;set;}

///获取

voidGetWxHandle

varprocess=Process.GetProcessesByName("Wechat").FirstOrDefault;

if(process!=null)

ProcessId=process.Id;

voidInitWechat

IsInit=true;

GetWxHandle;

GetFriendTokenSource=newCancellationTokenSource;

GetFriendCancellationToken=GetFriendTokenSource.Token;

ChatListTokenSource=newCancellationTokenSource;

ChatListCancellationToken=ChatListTokenSource.Token;

FriendTokenSource=newCancellationTokenSource;

FriendCancellationToken=FriendTokenSource.Token;

varapplication=FlaUI.Core.Application.Attach(ProcessId);

varautomation=newUIA3Automation;

wxWindow=application.GetMainWindow(automation);

if(MessageBox.Show(ex.Message,"异常",MessageBoxButtons.OK,MessageBoxIcon.Error)==DialogResult.OK)

this.Close;

//加载好友

IsListenCronyList=true;

//加载聊天信息

GetChatInfo;

///获取好友列表

voidGetFriends

wxWindow.FindAllDescendants(x=>x.ByControlType(FlaUI.Core.Definitions.ControlType.Button)).AsParallel

.FirstOrDefault(item=>item!=null&&item.Name=="通讯录").Click(false);

stringlastName=string.Empty;

varlist=newList;

varsync=SynchronizationContext.Current;

Task.Run(async=>

if(GetFriendCancellationToken.IsCancellationRequested)

varall=wxWindow.FindAllDescendants(x=>x.ByControlType(FlaUI.Core.Definitions.ControlType.ListItem));

varallItem=all.AsParallel.Where(s=>s!=null&&s.Parent!=null&&"联系人".Equals(s.Parent.Name)).ToList;

foreach(variteminallItem)

if(!string.IsNullOrWhiteSpace(item.Name)&&!listBox1.Items.Contains(item.Name.ToString))

sync.Post(s=>

listBox1.Items.Add(s);

},item.Name.ToString);

awaitTask.Delay(1);

},GetFriendCancellationToken);

///监听好友列表

privatevoidbtnListenCronyList_Click(objectsender,EventArgse)

IsListenCronyList=!IsListenCronyList;

privatebool_isListenCronyList=false;

publicboolIsListenCronyList

set

if(_isListenCronyList==value)

_isListenCronyList=value;

if(value)

txt="关闭监听好友列表";

GetFriends;

txt="开启监听好友列表";

GetFriendTokenSource.Cancel;

btnListenCronyList.ExecBeginInvoke(=>

btnListenCronyList.Text=txt;

get=>this._isListenCronyList;

3.4、扩展方法internalstaticclassSystemEx

///跨线程操作控件

///

///

publicstaticvoidExecBeginInvoke(thisControlcon,Actionaction)

if(action==null)return;

if(con.InvokeRequired)

con.BeginInvoke(newAction(action));

action;

publicstaticvoidExecInvoke(thisControlcon,Actionaction)

THE END
1.微信又上新功能!私聊库尔勒通讯录pc端命令提示符直接在双人私聊语音通话界面中,点击 “+” 拉更多朋友加入。现在,这个功能已经上线全 iOS 端微信,安卓端微信正在灰度测试中。 左右滑动查看 此前 微信Windows PC版4.0.1内测更新 另据此前消息,微信Windows PC版发布4.0.1内测更新。除了支持发布朋友圈,还可查看好友的朋友圈相册,可在“聊天文件”中,管理所有聊天中https://www.163.com/dy/article/JJ5CNKVT0514C61J.html
2.C#高仿微信聊天程序一(制作界面)c#仿微信界面文章浏览阅读2.9k次。需要类似客服的可以看看。先从布局开始:分布布局首先那弄处来聊天的好友界面部分。看图_c# 仿微信界面https://blog.csdn.net/u010919083/article/details/104242297
3.微信长按功能探秘:不同位置触发的神奇操作在这个数字化高速发展的时代,微信作为社交媒体的领军者,早已深入人心。除了基础的聊天、支付等功能外,微信还隐藏着许多不为人知的小秘密。今天,就让我们一起探索微信长按不同位置会触发哪些神奇的功能,感受微信带来的便捷与乐趣。首先,我们来看看微信聊天界面的长按功能。当你在聊天窗口中长按某条消息时,会出现https://baijiahao.baidu.com/s?id=1795822714745351395&wfr=spider&for=pc
4.C#实现微信聊天对话框MY依然C#实现微信聊天对话框 最近喜欢上了玩微信,觉得微信的了聊天对话框挺不错的,于是自己也使用C#实现了一个类似的控件,代码如下: 1usingSystem;2usingSystem.ComponentModel;3usingSystem.Drawing;4usingSystem.Drawing.Drawing2D;5usingSystem.Windows.Forms;67namespaceSun.WinFormControl8{9///10///类似微信的聊天对话https://www.cnblogs.com/sunyujing/archive/2012/07/19/2599444.html
5.WechatBakTool▎软件介绍:一款基于 C# 开发的微信聊天记录备份分析工具,支持两种方式非直接地址获取,支持多微信切换操作。 支持导出 HTML 文件,TXT 文件和批量导出,还支持聊天频率分析,全消息库内容搜索。 ▎软件下载:点击下载 (https://github.com/SuxueCode/WechatBakTool/releases)https://www.lukou.com/userfeed/40569991
6.java写微信刷屏代码微信聊天刷屏代码3、 微信聊天页面和文章页面多窗口显示 4、 代码://multiwebview 5、 查看当前聊天窗口中的消息数量 6、 代码://checkcount 7、 查看小视频参数 8、 代码://vision info 9、 直接调用诊断网络功能。 10、 代码://opentrace 11、 手机信息查询 http://chengdu.cdxwcx.cn/article/hehphd.html
7.C#高仿微信聊天程序一(制作界面)C# 高仿微信聊天 程序一 (制作界面),需要类似客服的可以看看。先从布局开始:分布布局首先那弄处来聊天的好友界面部分。看图https://blog.51cto.com/51souta/5806012
8.net编写的微信聊天机器人开发实例源码下载【C#】 一行代码发送微信消息,市面上最简单的发送微信消息方法 abclmc于 2024-10-24 上传 【C#】 H3C交换机IP-MAC绑定助手 cd37ycs于 2024-10-19 上传 实例介绍 [下载地址] 【实例简介】 net编写的微信聊天机器人,实现了根据聊天内容自动回复 【实例截图】 https://www.haolizi.net/example/view_41268.html
9.c#Winform实现微信功能暂时还没用实现完,只实现了微信临时聊天人员的显示,消息数量显示,聊天窗口记录显示,通讯录人员的显示,订阅的查看等,发送功能没有实现,有兴趣的自己去实现。 微信Winform c#2017-09-19 上传大小:19.00MB 所需:50积分/C币 Winform实现微信支付功能 代码完全测试通过, https://www.iteye.com/resource/wky65007098-9986210
10.电子通讯工具(精选八篇)在聊天模块中, 还可以加入了图片的发送, 是通过C#读取图片的函数, 把图片读取到数据流中, 然后通过类型转换, 把图片类型转换成16进制数据。把图片的16进制数据通过Socket传输给目标客户端, 目标客户端接收到数据后把数据解析成图片, 再通过转换把图片数据编码成图片形式存入PC机中, 从而实现了图片的输送。https://www.360wenmi.com/f/cnkeyt4f8400.html
11.微信聊天记录如何导出来存文本?最简单的操作,不用任何外部软件,利用微信自身的功能即可完成!第一步:在聊天页面 长按聊天消息-多选-https://www.zhihu.com/question/22455860
12.微信聊天记录整理吾爱破解52pojie.cn分享消息,这种消息会含有多种类型,比如分享的收藏,分享的小程序,微信红包等等。这种消息类型可以避免不断添加多种消息类型,像这种预先定义一种消息类型,预留一些字段,这样产品添加消息类型的时候,UI 可以任意组合:49 content就是发送的内容群消息可以根据talker分类提取聊天记录群聊信息rhttps://www.52pojie.cn/archiver/tid-1453590.html
13.Unity实现微信聊天框界面C#教程这篇文章主要为大家详细介绍了Unity实现微信聊天框界面,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下GPT4.0+Midjourney绘画+国内大模型 会员永久免费使用!【 如果你想靠AI翻身,你先需要一个靠谱的工具!】 本文实例为大家分享了Unity实现微信聊天框界面的具体代码,供大家参考,具体内容https://www.jb51.net/article/225407.htm
14.C#开发微信门户及应用若员工离职,企业管理员可在通讯录中删除该成员,该成员即自动取消关注企业号,同时微信中的企业号历史记录也会被清除。 2)应用可配置 –企业可自行在企业号中可配置多个服务号,可以连接不同的企业应用系统,只有授权的企业成员才能使用相应的服务号。 3)消息无限制 https://m.php.cn/faq/352499.html
15.C#中实现qq和微信截屏的功能C#中实现qq和微信截屏的功能 c#中有一个控件可以实现,需要下载 1、创建一个windows窗体应用程序,框架选择netframework2.0 2、下载_SCREEN_CAPTURE.dll,并添加引用 3、添加一个button控件 4、添加代码 using _SCREEN_CAPTURE; usingSystem; usingSystem.Collections.Generic; https://blog.bfw.wiki/user27/15655871551815160073.html
16.后端C#.net服务器前端原生网页微信小程序uni后端集成SignalR比较简单,首先要在解决方案中依赖几个SignalR的库,SignalR的库就是做即时通讯的主要库,我们建立连接、收发信息都需要用这个库来进行。 除了这几个库以外,还要还有几个依赖库要一并依赖进来。 Owin库的作用主要是为了在项目StartUp时将SignalR库的几个Hub文件注册起来,Hub文件就相当于是我们接口中的https://www.zovps.com/article/index.php/post/172948.html
17.C#可视化程序设计案例教程第4版——刘培林史荧本书配套资源,样书均可在本页下载申请,也可联系微信13261377872直接索取 《C#可视化程序设计案例教程 第4版》共10章,前两章介绍Windows应用程序开发入门、窗体与控件;第3、4章讲述C#语言与菜单、工具栏、状态栏、对话框;第5、6章为本书的重点及难点,介绍Visual Studio数据库开发环境与数据库应用程序设计;第7章介绍http://www.cmpedu.com/books/book/5600471.htm