Пример #1
0
        /// <summary>
        /// 发送文本
        /// </summary>
        /// <param name="shareData">The share data.</param>
        /// <param name="wins">The wins.</param>
        private void SendText(List <weChatShareTextModel> shareData, List <WindowInfo> wins, bool isImageText)
        {
            foreach (var item in shareData)
            {
                try
                {
                    if (!isStartTask || MyUserInfo.currentUserId == 0)
                    {
                        break;
                    }

                    //如果当前微信已经发送,则结束本循环
                    if (textResult.Contains(item.title))
                    {
                        continue;
                    }

                    bool b = wins.Exists(win => { return(win.szWindowName == item.title); });
                    if (b)
                    {
                        var win = wins.Find(w => { return(w.szWindowName == item.title); });
                        Clipboard.SetDataObject(item.text, false);
                        //设置微信为输入焦点
                        WinApi.SetActiveWin(win.hWnd);
                        WinApi.Paste(win.hWnd);
                        //WinApi.InputStr(win.hWnd, item.text);
                        WinApi.Enter(win.hWnd);
                        Clipboard.Clear();
                        SleepImage(0.5m);
                        if (!textResult.Contains(item.title))
                        {
                            textResult.Add(item.title);
                        }

                        if (isImageText)
                        {
                            //更新修改状态
                            UpdateShareTextStatus(item.id);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (!textResult.Contains(item.title))
                    {
                        textResult.Add(item.title);
                    }

                    //添加错误日志
                    AddErrorLog(item, 1);
                    if (isImageText)
                    {
                        //更新修改状态
                        UpdateShareTextStatus(item.id);
                    }
                    log.Error(ex);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 发送图片
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="shareData">The share data.</param>
        /// <param name="wins">The wins.</param>
        private void SendImage(Image image, List <weChatShareTextModel> shareData, List <WindowInfo> wins, bool isImageText)
        {
            if (image != null)
            {
                Clipboard.SetImage(image);
                System.Threading.Thread.Sleep(1000);
                //粘贴图片
                foreach (var item in shareData)
                {
                    try
                    {
                        if (!isStartTask || MyUserInfo.currentUserId == 0)
                        {
                            break;
                        }

                        //如果当前微信已经发送,则结束本循环
                        if (imageResult.Contains(item.title))
                        {
                            continue;
                        }

                        bool b = wins.Exists(win => { return(win.szWindowName == item.title); });
                        if (b)
                        {
                            var win = wins.Find(w => { return(w.szWindowName == item.title); });
                            WinApi.SetActiveWin(win.hWnd);
                            System.Threading.Thread.Sleep(100);
                            WinApi.Paste(win.hWnd);
                            System.Threading.Thread.Sleep(100);
                            WinApi.Enter(win.hWnd);
                            SleepImage(0.5m);
                            if (!imageResult.Contains(item.title))
                            {
                                imageResult.Add(item.title);
                            }

                            if (!isImageText)
                            {
                                //更新修改状态
                                UpdateShareTextStatus(item.id);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (!imageResult.Contains(item.title))
                        {
                            imageResult.Add(item.title);
                        }

                        AddErrorLog(item, 0);

                        if (!isImageText)
                        {
                            //更新修改状态
                            UpdateShareTextStatus(item.id);
                        }
                        log.Error(ex);
                    }
                }
                Clipboard.Clear();
            }
        }