Пример #1
0
 /// <summary>
 /// 群异常通知
 /// </summary>
 /// <param name="title"></param>
 private void SendNotify(string title)
 {
     if (notifyMap.ContainsKey(title))
     {
         DateTime nowDt = DateTime.Now;
         notifyMap.TryGetValue(title, out nowDt);
         if (nowDt.AddMinutes(30).CompareTo(DateTime.Now) < 0)
         {
             notifyMap[title] = DateTime.Now;
             HotJavaApi.SendUserNotice(MyUserInfo.LoginToken, WeChatTemplateMessageSceneType.群异常, title);
         }
     }
     else
     {
         notifyMap[title] = DateTime.Now;
         HotJavaApi.SendUserNotice(MyUserInfo.LoginToken, WeChatTemplateMessageSceneType.群异常, title);
     }
 }
Пример #2
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);
            }
        }
Пример #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;
                }
            }
        }