Esempio n. 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, GoodsModel goods)
        {
            bool isLogin = true;

            foreach (var item in shareData)
            {
                try
                {
                    Tuple <string, string> resultTuple = TaobaoHelper.GetGaoYongToken(goods.goodsDetailUrl, goods.goodsId, item.tpwd, MyUserInfo.GetTbToken(), MyUserInfo.cookies, out isLogin);
                    if (resultTuple != null)
                    {
                        if (!isLogin)
                        {
                            hotForm.isTaskRuning = true;
                            isStartTask          = false;
                            hotForm.SendNotify();
                            System.Threading.Thread.Sleep(5000);
                            break;
                        }
                        item.status = 0;
                        if (item.text.Contains("[二合一淘口令]"))
                        {
                            item.text = item.text.Replace("[二合一淘口令]", resultTuple.Item1);
                        }
                        else
                        {
                            item.text += "复制这条信息,打开『手机淘宝』" + resultTuple.Item1 + "领券下单即可抢购宝贝";
                        }

                        if (item.text.Contains("[短链接]"))
                        {
                            item.text = item.text.Replace("[短链接]", resultTuple.Item2);
                        }
                        LogicHotTao.Instance(MyUserInfo.currentUserId).UpdateUserShareTextStatus(item.id, item.text, resultTuple.Item1);
                    }
                    else
                    {
                        bool flag = LogicHotTao.Instance(MyUserInfo.currentUserId).BuildTpwd(MyUserInfo.currentUserId, MyUserInfo.LoginToken, goods, item, appkey, appsecret);
                        if (!flag)
                        {
                            continue;
                        }
                    }

                    if (!isStartTask || MyUserInfo.currentUserId == 0)
                    {
                        break;
                    }

                    ClipboardObjectData(item.text);
                    //如果当前微信已经发送,则结束本循环
                    if (textResult.Contains(item.title))
                    {
                        continue;
                    }
                    wins = WinApi.GetAllDesktopWindows();
                    if (wins == null || wins.Count() == 0)
                    {
                        continue;
                    }

                    bool b = wins.Exists(win => { return(win.szWindowName == item.title); });
                    if (b)
                    {
                        var win = wins.Find(w => { return(w.szWindowName == item.title); });
                        //设置微信为输入焦点

                        //复制粘贴发送
                        WinApi.SendData(win.hWnd, win.winType == 1);

                        SleepImage(0.5m);

                        if (!textResult.Contains(item.title))
                        {
                            textResult.Add(item.title);
                        }

                        if (isImageText)
                        {
                            UpdateShareTextStatus(item.id);//更新修改状态
                        }
                    }
                    else
                    {
                        SendNotify(item.title);//通知
                    }
                }
                catch (Exception ex)
                {
                    //通知
                    SendNotify(item.title);

                    if (!textResult.Contains(item.title))
                    {
                        textResult.Add(item.title);
                    }

                    //添加错误日志
                    AddErrorLog(item, 1);
                    if (isImageText)
                    {
                        UpdateShareTextStatus(item.id);//更新修改状态
                    }
                    log.Error(ex);
                }
            }
        }
Esempio n. 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, bool sendVideo = false, bool isJoinImage = false)
        {
            string path = System.Environment.CurrentDirectory + "\\temp\\joinimage";

            if (!isJoinImage)
            {
                if (image == null)
                {
                    return;
                }
                if (!sendVideo)
                {
                    Clipboard.SetImage(image);
                }
            }
            else
            {
                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }
            }
            //粘贴图片
            foreach (var item in shareData)
            {
                try
                {
                    if (isJoinImage)
                    {
                        try
                        {
                            string fileName = EncryptHelper.MD5(item.taskid.ToString() + item.field3);

                            if (File.Exists(string.Format("{0}\\{1}.jpg", path, fileName)))
                            {
                                using (Stream stream = new FileStream(string.Format("{0}\\{1}.jpg", path, fileName), FileMode.Open))
                                {
                                    image = Image.FromStream(stream);
                                }
                                Clipboard.SetImage(image);
                            }
                            else
                            {
                                log.Info(string.Format("商品图片不存在,群[{0}]未发送", item.title));
                                continue;
                            }
                        }
                        catch (Exception)
                        {
                            //通知
                            SendNotify(item.title);
                            continue;
                        }
                    }



                    if (!isStartTask || MyUserInfo.currentUserId == 0)
                    {
                        break;
                    }

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

                    wins = WinApi.GetAllDesktopWindows();
                    if (wins == null || wins.Count() == 0)
                    {
                        continue;
                    }

                    bool b = wins.Exists(win => { return(win.szWindowName == item.title); });
                    if (b)
                    {
                        var win = wins.Find(w => { return(w.szWindowName == item.title); });
                        if (sendVideo && win.winType == 1)
                        {
                        }
                        else
                        {
                            //复制粘贴发送
                            WinApi.SendData(win.hWnd, win.winType == 1);


                            SleepImage(0.5m);
                            if (!sendVideo && !imageResult.Contains(item.title))
                            {
                                imageResult.Add(item.title);
                            }
                        }

                        if (!isImageText)
                        {
                            //更新修改状态
                            UpdateShareTextStatus(item.id);
                        }
                    }
                    else
                    {
                        //通知
                        SendNotify(item.title);
                    }
                }
                catch (Exception ex)
                {
                    //通知
                    SendNotify(item.title);

                    if (!sendVideo && !imageResult.Contains(item.title))
                    {
                        imageResult.Add(item.title);
                    }

                    AddErrorLog(item, 0);

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