(5)实现对微信窗体元素静默操作-微信UI自动化(.Net+C#)

 整理 | 小耕家的喵大仙

出品 | CSDN(ID:lichao19897314)

Q Q | 978124155

 往期知识回顾: 

(1)C#开启探索微信自动化之路-微信UI自动化

(2)C#创建微信窗体自动化实例-微信UI自动化

(3)C#针对系统热键管理-微信UI自动化

(4)C#采集微信通讯录和联系人-微信UI自动化

(5)C#实现针对微信窗体鼠标静默点击-微信UI自动化

(6)C#搜索微信通讯录联系人-微信UI自动化

(7)C#实现微信消息群发-微信UI自动化

(8)C#监控微信进程运行状态-微信UI自动化

(9)C#监控微信网络连接状态-微信UI自动化

(11)C#实现微信窗体尺寸跟随调整-微信UI自动化

(12)C#采集微信聊天记录及历史消息-微信UI自动化

(13)C#实现自动回复微信消息-微信UI自动化

(14)C#针对微信界面元素截图操作-微信UI自动化

(15)C#实现对微信窗体的行为管控-微信UI自动化

(16)C#实现微信多开-微信UI自动化

(17)C#实现微信聊天文件接收及下载-微信UI自动化

👆 以上文章是以往对使用自动化技术操作微信的一些文章及案例!!!!

因为文章可能无法满足读者要求,如需源码和支持请联系本人QQ 978124155 

本篇目的

       上文我们进行了微信通讯录联系人采集的实现, 最开始如果我用了FLAUI中的鼠标模拟方法,发现鼠标光标会跟随我们的调用而在屏幕移动位置,效果并不是特别友好,那么我们能不能不移动鼠标而进行点击呢?

        答案是肯定的,我们通过模拟WIN消息来实现!

技术实现

(1)定义WINDOW发送消息的函数

     我们寻找FLAUI组件,发现在FLAUI中已经定义好win发送消息的函数和消息类型,就直接拿了用了!

FlaUI.Core.WindowsAPI.User32中定义了很多常用的window函数.

FlaUI.Core.WindowsAPI.WindowsMessages定义了window消息的类型(键盘,鼠标事件等)

我们将类中的详细代码贴出来供大家参考!可以跳过不看

   [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

 public static class WindowsMessages
    {
        public const uint WM_ACTIVATE = 0x0006;
        public const uint WM_ACTIVATEAPP = 0x001C;
        public const uint WM_AFXFIRST = 0x0360;
        public const uint WM_AFXLAST = 0x037F;
        public const uint WM_APP = 0x8000;
        public const uint WM_APPCOMMAND = 0x0319;
        public const uint WM_ASKCBFORMATNAME = 0x030C;
        public const uint WM_CANCELJOURNAL = 0x004B;
        public const uint WM_CANCELMODE = 0x001F;
        public const uint WM_CAPTURECHANGED = 0x0215;
        public const uint WM_CHANGECBCHAIN = 0x030D;
        public const uint WM_CHANGEUISTATE = 0x0127;
        public const uint WM_CHAR = 0x0102;
        public const uint WM_CHARTOITEM = 0x002F;
        public const uint WM_CHILDACTIVATE = 0x0022;
        public const uint WM_CLEAR = 0x0303;
        public const uint WM_CLOSE = 0x0010;
        public const uint WM_COMMAND = 0x0111;
        public const uint WM_COMMNOTIFY = 0x0044;
        public const uint WM_COMPACTING = 0x0041;
        public const uint WM_COMPAREITEM = 0x0039;
        public const uint WM_CONTEXTMENU = 0x007B;
        public const uint WM_COPY = 0x0301;
        public const uint WM_COPYDATA = 0x004A;
        public const uint WM_CREATE = 0x0001;
        public const uint WM_CTLCOLORBTN = 0x0135;
        public const uint WM_CTLCOLORDLG = 0x0136;
        public const uint WM_CTLCOLOREDIT = 0x0133;
        public const uint WM_CTLCOLORLISTBOX = 0x0134;
        public const uint WM_CTLCOLORMSGBOX = 0x0132;
        public const uint WM_CTLCOLORSCROLLBAR = 0x0137;
        public const uint WM_CTLCOLORSTATIC = 0x0138;
        public const uint WM_CUT = 0x0300;
        public const uint WM_DEADCHAR = 0x0103;
        public const uint WM_DELETEITEM = 0x002D;
        public const uint WM_DESTROY = 0x0002;
        public const uint WM_DESTROYCLIPBOARD = 0x0307;
        public const uint WM_DEVICECHANGE = 0x0219;
        public const uint WM_DEVMODECHANGE = 0x001B;
        public const uint WM_DISPLAYCHANGE = 0x007E;
        public const uint WM_DRAWCLIPBOARD = 0x0308;
        public const uint WM_DRAWITEM = 0x002B;
        public const uint WM_DROPFILES = 0x0233;
        public const uint WM_ENABLE = 0x000A;
        public const uint WM_ENDSESSION = 0x0016;
        public const uint WM_ENTERIDLE = 0x0121;
        public const uint WM_ENTERMENULOOP = 0x0211;
        public const uint WM_ENTERSIZEMOVE = 0x0231;
        public const uint WM_ERASEBKGND = 0x0014;
        public const uint WM_EXITMENULOOP = 0x0212;
        public const uint WM_EXITSIZEMOVE = 0x0232;
        public const uint WM_FONTCHANGE = 0x001D;
        public const uint WM_GETDLGCODE = 0x0087;
        public const uint WM_GETFONT = 0x0031;
        public const uint WM_GETHOTKEY = 0x0033;
        public const uint WM_GETICON = 0x007F;
        public const uint WM_GETMINMAXINFO = 0x0024;
        public const uint WM_GETOBJECT = 0x003D;
        public const uint WM_GETTEXT = 0x000D;
        public const uint WM_GETTEXTLENGTH = 0x000E;
        public const uint WM_HANDHELDFIRST = 0x0358;
        public const uint WM_HANDHELDLAST = 0x035F;
        public const uint WM_HELP = 0x0053;
        public const uint WM_HOTKEY = 0x0312;
        public const uint WM_HSCROLL = 0x0114;
        public const uint WM_HSCROLLCLIPBOARD = 0x030E;
        public const uint WM_ICONERASEBKGND = 0x0027;
        public const uint WM_IME_CHAR = 0x0286;
        public const uint WM_IME_COMPOSITION = 0x010F;
        public const uint WM_IME_COMPOSITIONFULL = 0x0284;
        public const uint WM_IME_CONTROL = 0x0283;
        public const uint WM_IME_ENDCOMPOSITION = 0x010E;
        public const uint WM_IME_KEYDOWN = 0x0290;
        public const uint WM_IME_KEYLAST = 0x010F;
        public const uint WM_IME_KEYUP = 0x0291;
        public const uint WM_IME_NOTIFY = 0x0282;
        public const uint WM_IME_REQUEST = 0x0288;
        public const uint WM_IME_SELECT = 0x0285;
        public const uint WM_IME_SETCONTEXT = 0x0281;
        public const uint WM_IME_STARTCOMPOSITION = 0x010D;
        public const uint WM_INITDIALOG = 0x0110;
        public const uint WM_INITMENU = 0x0116;
        public const uint WM_INITMENUPOPUP = 0x0117;
        public const uint WM_INPUT = 0x00FF;
        public const uint WM_INPUTLANGCHANGE = 0x0051;
        public const uint WM_INPUTLANGCHANGEREQUEST = 0x0050;
        public const uint WM_KEYDOWN = 0x0100;
        public const uint WM_KEYFIRST = 0x0100;
        public const uint WM_KEYLAST = 0x0109;
        public const uint WM_KEYUP = 0x0101;
        public const uint WM_KILLFOCUS = 0x0008;
        public const uint WM_LBUTTONDBLCLK = 0x0203;
        public const uint WM_LBUTTONDOWN = 0x0201;
        public const uint WM_LBUTTONUP = 0x0202;
        public const uint WM_MBUTTONDBLCLK = 0x0209;
        public const uint WM_MBUTTONDOWN = 0x0207;
        public const uint WM_MBUTTONUP = 0x0208;
        public const uint WM_MDIACTIVATE = 0x0222;
        public const uint WM_MDICASCADE = 0x0227;
        public const uint WM_MDICREATE = 0x0220;
        public const uint WM_MDIDESTROY = 0x0221;
        public const uint WM_MDIGETACTIVE = 0x0229;
        public const uint WM_MDIICONARRANGE = 0x0228;
        public const uint WM_MDIMAXIMIZE = 0x0225;
        public const uint WM_MDINEXT = 0x0224;
        public const uint WM_MDIREFRESHMENU = 0x0234;
        public const uint WM_MDIRESTORE = 0x0223;
        public const uint WM_MDISETMENU = 0x0230;
        public const uint WM_MDITILE = 0x0226;
        public const uint WM_MEASUREITEM = 0x002C;
        public const uint WM_MENUCHAR = 0x0120;
        public const uint WM_MENUCOMMAND = 0x0126;
        public const uint WM_MENUDRAG = 0x0123;
        public const uint WM_MENUGETOBJECT = 0x0124;
        public const uint WM_MENURBUTTONUP = 0x0122;
        public const uint WM_MENUSELECT = 0x011F;
        public const uint WM_MOUSEACTIVATE = 0x0021;
        public const uint WM_MOUSEFIRST = 0x0200;
        public const uint WM_MOUSEHOVER = 0x02A1;
        public const uint WM_MOUSELAST = 0x020D; // Win95: 0x0209, WinNT4,98: 0x020A
        public const uint WM_MOUSELEAVE = 0x02A3;
        public const uint WM_MOUSEMOVE = 0x0200;
        public const uint WM_MOUSEWHEEL = 0x020A;
        public const uint WM_MOVE = 0x0003;
        public const uint WM_MOVING = 0x0216;
        public const uint WM_NCACTIVATE = 0x0086;
        public const uint WM_NCCALCSIZE = 0x0083;
        public const uint WM_NCCREATE = 0x0081;
        public const uint WM_NCDESTROY = 0x0082;
        public const uint WM_NCHITTEST = 0x0084;
        public const uint WM_NCLBUTTONDBLCLK = 0x00A3;
        public const uint WM_NCLBUTTONDOWN = 0x00A1;
        public const uint WM_NCLBUTTONUP = 0x00A2;
        public const uint WM_NCMBUTTONDBLCLK = 0x00A9;
        public const uint WM_NCMBUTTONDOWN = 0x00A7;
        public const uint WM_NCMBUTTONUP = 0x00A8;
        public const uint WM_NCMOUSEHOVER = 0x02A0;
        public const uint WM_NCMOUSELEAVE = 0x02A2;
        public const uint WM_NCMOUSEMOVE = 0x00A0;
        public const uint WM_NCPAINT = 0x0085;
        public const uint WM_NCRBUTTONDBLCLK = 0x00A6;
        public const uint WM_NCRBUTTONDOWN = 0x00A4;
        public const uint WM_NCRBUTTONUP = 0x00A5;
        public const uint WM_NCXBUTTONDBLCLK = 0x00AD;
        public const uint WM_NCXBUTTONDOWN = 0x00AB;
        public const uint WM_NCXBUTTONUP = 0x00AC;
        public const uint WM_NEXTDLGCTL = 0x0028;
        public const uint WM_NEXTMENU = 0x0213;
        public const uint WM_NOTIFY = 0x004E;
        public const uint WM_NOTIFYFORMAT = 0x0055;
        public const uint WM_NULL = 0x0000;
        public const uint WM_PAINT = 0x000F;
        public const uint WM_PAINTCLIPBOARD = 0x0309;
        public const uint WM_PAINTICON = 0x0026;
        public const uint WM_PALETTECHANGED = 0x0311;
        public const uint WM_PALETTEISCHANGING = 0x0310;
        public const uint WM_PARENTNOTIFY = 0x0210;
        public const uint WM_PASTE = 0x0302;
        public const uint WM_PENWINFIRST = 0x0380;
        public const uint WM_PENWINLAST = 0x038F;
        public const uint WM_POWER = 0x0048;
        public const uint WM_POWERBROADCAST = 0x0218;
        public const uint WM_PRINT = 0x0317;
        public const uint WM_PRINTCLIENT = 0x0318;
        public const uint WM_QUERYDRAGICON = 0x0037;
        public const uint WM_QUERYENDSESSION = 0x0011;
        public const uint WM_QUERYNEWPALETTE = 0x030F;
        public const uint WM_QUERYOPEN = 0x0013;
        public const uint WM_QUERYUISTATE = 0x0129;
        public const uint WM_QUEUESYNC = 0x0023;
        public const uint WM_QUIT = 0x0012;
        public const uint WM_RBUTTONDBLCLK = 0x0206;
        public const uint WM_RBUTTONDOWN = 0x0204;
        public const uint WM_RBUTTONUP = 0x0205;
        public const uint WM_RENDERALLFORMATS = 0x0306;
        public const uint WM_RENDERFORMAT = 0x0305;
        public const uint WM_SETCURSOR = 0x0020;
        public const uint WM_SETFOCUS = 0x0007;
        public const uint WM_SETFONT = 0x0030;
        public const uint WM_SETHOTKEY = 0x0032;
        public const uint WM_SETICON = 0x0080;
        public const uint WM_SETREDRAW = 0x000B;
        public const uint WM_SETTEXT = 0x000C;
        public const uint WM_SETTINGCHANGE = 0x001A;
        public const uint WM_SHOWWINDOW = 0x0018;
        public const uint WM_SIZE = 0x0005;
        public const uint WM_SIZECLIPBOARD = 0x030B;
        public const uint WM_SIZING = 0x0214;
        public const uint WM_SPOOLERSTATUS = 0x002A;
        public const uint WM_STYLECHANGED = 0x007D;
        public const uint WM_STYLECHANGING = 0x007C;
        public const uint WM_SYNCPAINT = 0x0088;
        public const uint WM_SYSCHAR = 0x0106;
        public const uint WM_SYSCOLORCHANGE = 0x0015;
        public const uint WM_SYSCOMMAND = 0x0112;
        public const uint WM_SYSDEADCHAR = 0x0107;
        public const uint WM_SYSKEYDOWN = 0x0104;
        public const uint WM_SYSKEYUP = 0x0105;
        public const uint WM_TABLET_FIRST = 0x02C0;
        public const uint WM_TABLET_LAST = 0x02DF;
        public const uint WM_TCARD = 0x0052;
        public const uint WM_THEMECHANGED = 0x031A;
        public const uint WM_TIMECHANGE = 0x001E;
        public const uint WM_TIMER = 0x0113;
        public const uint WM_UNDO = 0x0304;
        public const uint WM_UNICHAR = 0x0109;
        public const uint WM_UNINITMENUPOPUP = 0x0125;
        public const uint WM_UPDATEUISTATE = 0x0128;
        public const uint WM_USER = 0x0400;
        public const uint WM_USERCHANGED = 0x0054;
        public const uint WM_VKEYTOITEM = 0x002E;
        public const uint WM_VSCROLL = 0x0115;
        public const uint WM_VSCROLLCLIPBOARD = 0x030A;
        public const uint WM_WINDOWPOSCHANGED = 0x0047;
        public const uint WM_WINDOWPOSCHANGING = 0x0046;
        public const uint WM_WININICHANGE = 0x001A;
        public const uint WM_WTSSESSION_CHANGE = 0x02B1;
        public const uint WM_XBUTTONDBLCLK = 0x020D;
        public const uint WM_XBUTTONDOWN = 0x020B;
        public const uint WM_XBUTTONUP = 0x020C;
    }

(2)定义静默点击FLAUI元素方法(发送win鼠标消息到FLAUI元素)

public  class WXWindowMessage
    {
        /// <summary>
        /// 实现静默点击向窗口发送windows消息
        /// </summary>
        /// <param name="ele"></param>
        public static void Click(AutomationElement ele)
        {
            if (ele == null)
            {
                Log.WXLog.Current.Log("点击事件元素为空");
                return;
            }
            //元素设置焦点
            ele.Focus();
 
            //获取微信船体的大小和所在位置
            var windowsRectangle = UI_WX_Window.Current.Window.BoundingRectangle;

            //获取元素的window句柄对象
            var handler = UI_WX_Window.Current.Window.NativeWindowHandle.ValueOrDefault;

            //计算元素在微信窗体中的相对位置
            int x = point.X - windowsRectangle.X;
            int y = point.Y - windowsRectangle.Y;

            //设置消息值
            IntPtr lParam = (IntPtr)((y << 8) + x);

            IntPtr wParam = IntPtr.Zero; 
            //调用windows鼠标松开函数
            User32.SendMessage(handler, WindowsMessages.WM_LBUTTONUP,  wParam , lParam);
            Log.WXLog.Current.Log("向元素【" + ele.Name + "】发送win消息成功");
        } 
    }

(3)实现静默点击微信中的元素

       public void ClickElement(AutomationElement ele)
        {
            if (ele != null)
            {
                Log.WXLog.Current.Log("开始执行元素【" + ele.Name + "】点击事件");
               

                WXWindowMessage.Click(ele);
            }
            else
            {
                Log.WXLog.Current.Error("元素为空,无法执行点击事件");
            }
        }

   在上文中采集联系人的步骤中我们就调用ClickElement方法来激活联系人面板,以下是调用代码

private void ClickContacts()
        {
             //通过XPATH找到通讯录按钮
            var ele = UI_WX_Window.Current.Find("/Pane[2]/Pane[1]/Button[3]");
            //发送点击事件
            UI_WX_Window.Current.ClickElement(ele);

}

上一篇(4)C#采集微信联系人和通讯录-微信UI自动化(.Net)icon-default.png?t=N7T8https://blog.csdn.net/lichao19897314/article/details/122823991

下一篇(6)C#搜索指定微信通讯录联系人-微信UI自动化icon-default.png?t=N7T8https://blog.csdn.net/lichao19897314/article/details/122962242

因为文章可能无法满足读者要求,如需源码和支持请联系本人QQ 978124155 

  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论
在 uni-app 中实现 H5 静默微信授权,你可以按照以下步骤进行操作: 1. 首先,确保你已经在微信公众平台上注册了你的应用,并获取到了 AppID。 2. 在 uni-app 项目中的 `main.js` 文件中引入微信 JS-SDK: ```javascript import wx from 'weixin-js-sdk' Vue.prototype.$wx = wx ``` 3. 创建一个 `wechat.js` 文件,用于封装微信 JS-SDK 的相关操作,例如: ```javascript import wx from 'weixin-js-sdk' export function initWechatConfig() { // 向后端请求获取微信配置信息 // ... // 初始化微信 JS-SDK wx.config({ debug: false, appId: '', // 你的 AppID timestamp: '', // 后端返回的时间戳 nonceStr: '', // 后端返回的随机字符串 signature: '', // 后端返回的签名 jsApiList: ['checkJsApi', 'login', 'getUserInfo'] // 需要使用的微信 API }) } export function login() { return new Promise((resolve, reject) => { wx.ready(() => { wx.login({ success: res => { if (res.code) { // 将 code 发送到后端服务器进行处理,获取用户信息 // ... resolve(res.code) } else { reject(new Error('微信登录失败')) } }, fail: err => { reject(err) } }) }) }) } export function getUserInfo() { return new Promise((resolve, reject) => { wx.ready(() => { wx.getUserInfo({ success: res => { // 获取到用户信息,进行处理 // ... resolve(res.userInfo) }, fail: err => { reject(err) } }) }) }) } ``` 4. 在需要授权的页面中,调用 `initWechatConfig()` 方法初始化微信 JS-SDK 配置,在需要获取用户信息的地方调用 `login()` 方法进行登录,并在登录成功后再调用 `getUserInfo()` 方法获取用户信息。 5. 根据获取到的用户信息进行业务逻辑处理。 通过以上步骤,你可以在 uni-app H5 中实现静默微信授权。请注意,具体的实现细节可能会因为你的业务逻辑和后端实现而有所不同。
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小耕家的喵大仙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值