|
目录pyautogui模拟点击发消息微信wxauto不错可执行代码:WeRoBot还没测pyautogui免费不错pyautogui模拟点击发消息Python发送微信消息(文字、图片、文件)给指定好友和微信群,零基础可看懂(附源码和教程)_python本地文件发送到微信群-CSDN博客微信wxauto不错GitHub-cluic/wxauto:Windows版本微信客户端(非网页版)自动化,可实现简单的发送、接收微信消息,简单微信机器人可执行代码:打开pc上的微信并登录,这个代码就可以自动和指定联系人发消息并获取聊天记录fromwxautoimportWeChatwx=WeChat()#发送消息who='辰辰'foriinrange(3):wx.SendMsg(f'wxauto测试{i+1}',who)#获取当前聊天页面(文件传输助手)消息,并自动保存聊天图片msgs=wx.GetAllMessage(savepic=True)formsginmsgs:print(f"{msg[0]}:{msg[1]}")print('wxauto测试完成!')【Python微信机器人】第六篇:优化使用方式,可pip安装_pipinstallwechathelper-CSDN博客WeRoBot还没测探索WeRoBot:一个强大的微信机器人框架-CSDN博客pyautogui免费不错参考博文importpyautoguiimporttimeimportwin32apiimportwin32conimportwin32guiimportwin32clipboardaswfromPILimportImageGrabimportrequestsimportbase64defFindWindow(chatroom):win=win32gui.FindWindow('WeChatMainWndForPC',chatroom)print("找到窗口句柄:%x"%win)ifwin!=0:win32gui.ShowWindow(win,win32con.SW_SHOWMINIMIZED)win32gui.ShowWindow(win,win32con.SW_SHOWNORMAL)win32gui.ShowWindow(win,win32con.SW_SHOW)win32gui.SetWindowPos(win,win32con.HWND_TOP,0,0,500,700,win32con.SWP_SHOWWINDOW)win32gui.SetForegroundWindow(win)#获取控制time.sleep(1)tit=win32gui.GetWindowText(win)print('已启动【'+str(tit)+'】窗口')else:print('找不到【%s】窗口'%chatroom)exit()#设置和粘贴剪贴板defClipboardText(ClipboardText):w.OpenClipboard()w.EmptyClipboard()w.SetClipboardData(win32con.CF_UNICODETEXT,ClipboardText)w.CloseClipboard()time.sleep(1)win32api.keybd_event(17,0,0,0)win32api.keybd_event(86,0,0,0)win32api.keybd_event(86,0,win32con.KEYEVENTF_KEYUP,0)win32api.keybd_event(17,0,win32con.KEYEVENTF_KEYUP,0)#模拟发送动作defSendMsg():win32api.keybd_event(18,0,0,0)win32api.keybd_event(83,0,0,0)win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0)win32api.keybd_event(83,0,win32con.KEYEVENTF_KEYUP,0)#模拟发送微信文本消息defSendWxMsg(wxid,sendtext):#先启动微信FindWindow('微信')time.sleep(1)#定位到搜索框pyautogui.moveTo(143,39)pyautogui.click()#搜索微信ClipboardText(wxid)time.sleep(1)#进入聊天窗口pyautogui.moveTo(155,120)pyautogui.click()#粘贴文本内容ClipboardText(sendtext)#发送SendMsg()print('已发送')#关闭微信窗口time.sleep(1)pyautogui.moveTo(683,16)pyautogui.click()#模拟发送文件消息(图片、文档、压缩包等)defSendWxFileMsg(wxid,imgpath):#先启动微信FindWindow('微信')time.sleep(1)#定位到搜索框pyautogui.moveTo(143,39)pyautogui.click()#搜索微信ClipboardText(wxid)time.sleep(1)#进入聊天窗口pyautogui.moveTo(155,120)pyautogui.click()#选择文件pyautogui.moveTo(373,570)pyautogui.click()ClipboardText(imgpath)time.sleep(1)pyautogui.moveTo(784,509)pyautogui.click()#发送SendMsg()print('已发送')#关闭微信窗口time.sleep(1)pyautogui.moveTo(683,16)pyautogui.click()#转发群里最新的一条消息defZhuanfaMsg(wxid,groupname):#先启动微信FindWindow('微信')time.sleep(1)#定位到搜索框pyautogui.moveTo(143,39)pyautogui.click()#搜索群ClipboardText(groupname)time.sleep(1)#进入群窗口pyautogui.moveTo(155,120)pyautogui.click()#开始转发pyautogui.moveTo(484,439)time.sleep(1)pyautogui.rightClick()pyautogui.moveTo(543,454)time.sleep(1)pyautogui.click()#搜索用户ClipboardText(wxid)time.sleep(1)pyautogui.moveTo(828,406)pyautogui.click()time.sleep(1)#确定转发pyautogui.moveTo(1108,755)pyautogui.click()#获取你的个人信息(昵称、微信号)defGetYourInfo():#先启动微信FindWindow('微信')time.sleep(1)#点击你的头像pyautogui.moveTo(28,56)pyautogui.click()time.sleep(1)#用户信息截图userinfo=(20,60,319,284)userinfo_img=ImageGrab.grab(userinfo)userinfo_img.save('userinfo.png')#识别用户信息截图request_url="https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic"f=open('userinfo.png','rb')img=base64.b64encode(f.read())params={"image":img}access_token='24.21008e8b243c5b2864a7cf0583d907e1.2592000.1661322017.282335-24796078'request_url=request_url+"?access_token="+access_tokenheaders={'content-type':'application/x-www-form-urlencoded'}response=requests.post(request_url,data=params,headers=headers)ifresponse:print(response.json())time.sleep(1)#关闭微信窗口time.sleep(1)pyautogui.moveTo(683,16)pyautogui.click()#获取好友微信的个人信息(昵称、微信号)defGetFriendInfo(wxid):#先启动微信FindWindow('微信')time.sleep(1)#定位到搜索框pyautogui.moveTo(143,39)pyautogui.click()#搜索微信ClipboardText(wxid)time.sleep(1)#进入聊天窗口pyautogui.moveTo(160,93)pyautogui.click()time.sleep(1)#点击右上角···pyautogui.moveTo(678,43)pyautogui.click()time.sleep(1)pyautogui.moveTo(801,51)pyautogui.click()#用户信息截图userinfo=(802,54,1085,331)userinfo_img=ImageGrab.grab(userinfo)userinfo_img.save('userinfo.png')#识别用户信息截图request_url="https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic"f=open('userinfo.png','rb')img=base64.b64encode(f.read())params={"image":img}access_token='24.21008e8b243c5b2864a7cf0583d907e1.2592000.1661322017.282335-24796078'request_url=request_url+"?access_token="+access_tokenheaders={'content-type':'application/x-www-form-urlencoded'}response=requests.post(request_url,data=params,headers=headers)ifresponse:print(response.json())time.sleep(1)#关闭微信窗口time.sleep(1)pyautogui.moveTo(683,16)pyautogui.click()pyautogui.click()#获取群人数defGetCharRoomUserNum(groupname):#先启动微信FindWindow('微信')time.sleep(1)#定位到搜索框pyautogui.moveTo(143,39)pyautogui.click()#搜索群ClipboardText(groupname)time.sleep(1)#进入群窗口pyautogui.moveTo(155,120)pyautogui.click()#群人数区域截图userinfo=(310,0,659,47)userinfo_img=ImageGrab.grab(userinfo)userinfo_img.save('chatroom.png')#识别群人数截图#开发文档:https://cloud.baidu.com/doc/OCR/s/Ck3h7y2iarequest_url="https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic"f=open('chatroom.png','rb')img=base64.b64encode(f.read())params={"image":img}access_token='24.21008e8b243c5b2864a7cf0583d907e1.2592000.1661322017.282335-24796078'request_url=request_url+"?access_token="+access_tokenheaders={'content-type':'application/x-www-form-urlencoded'}response=requests.post(request_url,data=params,headers=headers)ifresponse:print(response.json())time.sleep(1)#关闭微信窗口time.sleep(1)pyautogui.moveTo(683,16)pyautogui.click()#发布群公告defAddGorupNotice(groupname,NoticeText):#先启动微信FindWindow('微信')time.sleep(1)#定位到搜索框pyautogui.moveTo(143,39)pyautogui.click()#搜索群ClipboardText(groupname)time.sleep(1)#进入群窗口pyautogui.moveTo(155,120)pyautogui.click()#定位到群名称pyautogui.moveTo(363,33)pyautogui.click()#定位到群公告time.sleep(1)pyautogui.moveTo(731,509)pyautogui.click()#粘贴群公告内容ClipboardText(NoticeText)#确认发布群公告time.sleep(1)pyautogui.moveTo(288,500)pyautogui.click()pyautogui.moveTo(312,297)pyautogui.click()#邀请好友进群defReqFriendsToGroup(groupname,wxid):#先启动微信FindWindow('微信')time.sleep(1)#定位到搜索框pyautogui.moveTo(143,39)pyautogui.click()#搜索群ClipboardText(groupname)time.sleep(1)#进入群窗口pyautogui.moveTo(155,120)pyautogui.click()#定位到群名称pyautogui.moveTo(363,33)pyautogui.click()#定位到邀请time.sleep(1)pyautogui.moveTo(852,300)pyautogui.click()#搜索好友ClipboardText(wxid)#发出邀请time.sleep(1)pyautogui.moveTo(232,197)pyautogui.click()time.sleep(1)pyautogui.moveTo(493,561)pyautogui.click()time.sleep(1)pyautogui.moveTo(395,427)pyautogui.click()#获取好友最新的聊天记录defGetChatRecord(wxid):#先启动微信FindWindow('微信')time.sleep(1)#搜索微信号pyautogui.moveTo(166,38)pyautogui.click()ClipboardText(wxid)time.sleep(1)pyautogui.moveTo(197,123)pyautogui.click()#聊天内容区域截图userinfo=(314,68,683,549)userinfo_img=ImageGrab.grab(userinfo)userinfo_img.save('chatrecord.png')#识别当前聊天窗口截图#开发文档:https://cloud.baidu.com/doc/OCR/s/Ck3h7y2iarequest_url="https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic"f=open('chatrecord.png','rb')img=base64.b64encode(f.read())params={"image":img}access_token='24.21008e8b243c5b2864a7cf0583d907e1.2592000.1661322017.282335-24796078'request_url=request_url+"?access_token="+access_tokenheaders={'content-type':'application/x-www-form-urlencoded'}response=requests.post(request_url,data=params,headers=headers)ifresponse:print(response.json())#置顶群或好友defSetTop(groupname_wxid):#先启动微信FindWindow('微信')time.sleep(1)#定位到搜索框pyautogui.moveTo(143,39)pyautogui.click()#搜索群或好友ClipboardText(groupname_wxid)time.sleep(1)#进入窗口pyautogui.moveTo(155,120)pyautogui.click()#打开设置pyautogui.moveTo(684,38)pyautogui.click()time.sleep(1)#置顶pyautogui.moveTo(914,227)pyautogui.click()time.sleep(1)pyautogui.moveTo(682,18)pyautogui.click()print('已将'+str(groupname_wxid)+'置顶')#添加微信defAddWx(wxid):#先启动微信FindWindow('微信')time.sleep(1)#定位到添加微信位置pyautogui.moveTo(25,151)pyautogui.click()time.sleep(1)pyautogui.moveTo(278,39)pyautogui.click()time.sleep(1)pyautogui.moveTo(153,39)pyautogui.click()time.sleep(1)#搜索微信号ClipboardText(wxid)time.sleep(1)pyautogui.moveTo(183,91)pyautogui.click()time.sleep(2)#对搜索微信号结果进行截图userinfo=(306,68,565,240)userinfo_img=ImageGrab.grab(userinfo)userinfo_img.save('addwx.png')#对搜索微信号结果进行识别#开发文档:https://cloud.baidu.com/doc/OCR/s/Ck3h7y2iarequest_url="https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic"f=open('addwx.png','rb')img=base64.b64encode(f.read())params={"image":img}access_token='24.21008e8b243c5b2864a7cf0583d907e1.2592000.1661322017.282335-24796078'request_url=request_url+"?access_token="+access_tokenheaders={'content-type':'application/x-www-form-urlencoded'}response=requests.post(request_url,data=params,headers=headers)ifresponse:print(response.json())#添加time.sleep(1)pyautogui.moveTo(435,203)pyautogui.click()time.sleep(1)pyautogui.moveTo(300,621)pyautogui.click()time.sleep(1)pyautogui.moveTo(278,37)pyautogui.click()print('已向'+str(wxid)+'发送添加好友请求')pyautogui.moveTo(682,18)pyautogui.click()#发送文本消息(微信号或微信昵称或备注,需要发送的文本消息)SendWxMsg('文件传输助手','Python发送微信消息')#发送文件消息(图片、文档、压缩包等)#SendWxFileMsg('微信号',r"文件路径")#转发群里最新的一条消息(微信号或微信昵称或备注,群名称)#ZhuanfaMsg('微信号','群名称')#获取你的个人信息(昵称、微信号)#GetYourInfo('微信号')#获取好友微信的个人信息(昵称、微信号)#GetFriendInfo('微信号')#获取微信群人数#GetCharRoomUserNum('群名称')#发布群公告#AddGorupNotice('群名称','Python发布群公告')#邀请好友进群#ReqFriendsToGroup('群名称','cbzqx88')#获取好友最新的聊天记录#GetChatRecord('微信号')#置顶群或好友#SetTop('微信号')#添加微信#AddWx('微信号')
|
|