Esempio n. 1
0
        /// <summary>
        /// 采集商品处理
        /// </summary>
        /// <param name="msgCode"></param>
        /// <param name="msgContent"></param>
        /// <param name="urls"></param>
        /// <param name="isAutoSend"></param>
        /// <param name="EnableCustomTemplate"></param>
        /// <param name="callback"></param>
        private void QqForm_BuildGoodsHandler(long msgCode, string msgGroupName, string msgContent, string msgFullContent, List <string> urls, bool isAutoSend, bool EnableCustomTemplate, Action <MessageCallBackType, int, int> callback)
        {
            lock (lock_goods)
            {
                try
                {
                    List <Dictionary <string, string> > list = new List <Dictionary <string, string> >();
                    Dictionary <string, string>         data = new Dictionary <string, string>();
                    if (urls.Count() > 0)
                    {
                        data["url"] = urls[0];
                    }
                    else
                    {
                        data["url"] = "";
                    }
                    if (urls.Count() > 1)
                    {
                        data["url2"] = urls[1];
                    }
                    else
                    {
                        data["url2"] = "";
                    }
                    data["message"] = msgFullContent;
                    list.Add(data);

                    string jsonUrls = JsonConvert.SerializeObject(list);

                    callback?.Invoke(MessageCallBackType.正在准备, 0, 0);
                    //根据地址,获取商品优惠信息
                    bool result = HotJavaApi.UploadGoodsbyLink(qqForm.GetQQ(), msgGroupName, jsonUrls);

                    if (result)
                    {
                        callback?.Invoke(MessageCallBackType.完成, 0, 0);
                    }
                    else
                    {
                        callback?.Invoke(MessageCallBackType.失败, 0, 0);
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                    callback?.Invoke(MessageCallBackType.失败, 0, 0);
                }
            }
        }
Esempio n. 2
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);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 加载公众号二维码
 /// </summary>
 private void LoadMyQrCode()
 {
     myQrCode.Image = Resources.loading;
     new System.Threading.Thread(() =>
     {
         string url = HotJavaApi.SubscribeForBind(MyUserInfo.LoginToken);
         if (!string.IsNullOrEmpty(url))
         {
             var bytes = HttpRequestService.GetNetWorkImageData(url);
             if (bytes != null)
             {
                 SetQrCodeImage(Image.FromStream(new MemoryStream(bytes)), false);
             }
             else
             {
                 SetQrCodeImage(Resources.loading);
             }
         }
     })
     {
         IsBackground = true
     }.Start();
 }
Esempio n. 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);
            }
        }
Esempio n. 5
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;
                }
            }
        }