示例#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);
                }
            }
        }
示例#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();
        }
示例#3
0
        /// <summary>
        /// 开始执行发送
        /// </summary>
        /// <param name="str">The string.</param>
        /// <param name="image">The image.</param>
        private void StartSend()
        {
            List <WindowInfo> wins = WinApi.GetAllDesktopWindows();

            if (wins == null || wins.Count() == 0)
            {
                //通知
                //sendEmailNOtify("发单失败,请检查发单微信是否掉线!");
                HotJavaApi.SendUserNotice(MyUserInfo.LoginToken, WeChatTemplateMessageSceneType.微信离线);
                return;
            }
            //获取任务数据
            var taskdata = LogicHotTao.Instance(MyUserInfo.currentUserId).FindUserTaskPlanListByUserId(true);

            if (taskdata == null || taskdata.Count() == 0)
            {
                return;
            }

            //获取待执行的任务数据
            taskdata = taskdata.FindAll(item =>
            {
                return(item.status == 0 && item.isTpwd == 1 && item.startTime.CompareTo(DateTime.Now) < 0);
            }).OrderBy(x => x.startTime).ToList();

            if (taskdata == null || taskdata.Count() == 0)
            {
                return;
            }
            //排序
            taskdata = taskdata.OrderBy(x => x.startTime).ToList();

            foreach (var item in taskdata)
            {
                if (!isStartTask || MyUserInfo.currentUserId == 0)
                {
                    break;
                }

                if (item.endTime.CompareTo(DateTime.Now) < 0)
                {
                    break;
                }

                textResult.Clear();
                imageResult.Clear();

                int taskid = Convert.ToInt32(item.id);

                List <UserPidTaskModel> lst = JsonConvert.DeserializeObject <List <UserPidTaskModel> >(item.goodsText);
                List <int> ids = new List <int>();
                //如果群数据和商品数据都为空时
                if (lst == null || lst.Count() == 0)
                {
                    if (!isStartTask || MyUserInfo.currentUserId == 0)
                    {
                        break;
                    }
                    LogicHotTao.Instance(MyUserInfo.currentUserId).UpdateUserTaskPlanExecStatus(taskid, 2);
                    continue;
                }

                lst.ForEach(it =>
                {
                    if (!ids.Contains(it.id))
                    {
                        ids.Add(it.id);
                    }
                });
                //获取商品数据
                var goodslist = LogicHotTao.Instance(MyUserInfo.currentUserId).FindByUserGoodsList(ids);

                if (goodslist == null || goodslist.Count() == 0)
                {
                    if (!isStartTask || MyUserInfo.currentUserId == 0)
                    {
                        break;
                    }
                    LogicHotTao.Instance(MyUserInfo.currentUserId).UpdateUserTaskPlanExecStatus(taskid, 2);
                    continue;
                }
                //发送商品数据
                var result = SendGoods(goodslist, item, wins);

                if (result)
                {
                    if (!isStartTask || MyUserInfo.currentUserId == 0)
                    {
                        break;
                    }
                    LogicHotTao.Instance(MyUserInfo.currentUserId).UpdateUserTaskPlanExecStatus(taskid, 2);
                    //每个任务之间,休息一下
                    SleepTask();
                }
                else
                {
                    break;
                }
            }
        }
示例#4
0
        /// <summary>
        /// 将商品发送到相应的群
        /// </summary>
        /// <param name="shareData">The share data.</param>
        /// <param name="goods">The goods.</param>
        /// <param name="lst">The LST.</param>
        private void SendWeChatGroupShareText(List <weChatShareTextModel> shareData, GoodsModel goods, List <WindowInfo> wins, TaskPlanModel taskModel)
        {
            try
            {
                Image image       = null;
                bool  isSendImage = isImageText();
                try
                {
                    using (Stream stream = new FileStream(goods.goodslocatImgPath, FileMode.Open))
                    {
                        image = Image.FromStream(stream);
                    }
                }
                catch (Exception ex)
                {
                    image = null;
                    //isSendImage = true;
                    log.Error(ex);
                }

                wins = WinApi.GetAllDesktopWindows();
                if (wins == null || wins.Count() == 0)
                {
                    HotJavaApi.SendUserNotice(MyUserInfo.LoginToken, WeChatTemplateMessageSceneType.微信离线);
                }

                if (isSendImage)
                {
                    //复制文件
                    if (image != null)
                    {
                        SendImage(image, shareData, wins, true);
                    }
                    SendText(shareData, wins, true, goods);
                }
                else
                {
                    SendText(shareData, wins, false, goods);
                    //复制文件
                    if (image != null)
                    {
                        SendImage(image, shareData, wins, false);
                    }
                }

                //发完图文后,发送视频或动态,优先短视频
                if (cfgTime != null && cfgTime.enable_sendvideo)
                {
                    //发送视频或GIF图片
                    string videoPath = MyUserInfo.GetVideoFilePath(goods.goodsId);
                    if (!string.IsNullOrEmpty(videoPath))
                    {
                        CopyFileToClipboard(videoPath);
                        SendImage(image, shareData, wins, true, true);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
示例#5
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);
                            WinApi.Paste(win.hWnd);
                            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();
            }
        }