/// <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);
                }
            }
        }
Exemple #2
0
        /// <summary>
        ///生成商品文案
        /// </summary>
        /// <param name="userid">The userid.</param>
        /// <param name="taskid">The taskid.</param>
        /// <param name="templateText">The template text.</param>
        /// <param name="data">The data.</param>
        /// <param name="group">The group.</param>
        /// <returns>true if XXXX, false otherwise.</returns>
        private bool BuildShareText(string loginToken, int userid, int taskid, string templateText, List <GoodsModel> data, weChatGroupModel group, string appkey, string appsecret, out JoinGoodsList joinList, Action <weChatShareTextModel> result = null, bool isJoinImage = false)
        {
            joinList = null;
            if (data == null)
            {
                return(false);
            }
            weChatShareTextModel share = new weChatShareTextModel()
            {
                userid = userid,
                taskid = taskid,
                status = -1,
                title  = group.title
            };

            if (isJoinImage)
            {
                joinList = new JoinGoodsList();
            }

            List <int> ids = new List <int>();

            List <JoinGoodsInfo> imageList = new List <JoinGoodsInfo>();

            foreach (var item in data)
            {
                if (item.goodsPrice - item.couponPrice <= 0)
                {
                    continue;
                }
                string url = GlobalConfig.couponUrl;
                url           += "?src=ht_hot&activityId=" + item.couponId;
                url           += "&itemId=" + item.goodsId.Replace("=", "");
                url           += "&pid=" + (string.IsNullOrEmpty(group.pid) ? "mm_33648229_22032774_73500078" : group.pid);
                item.shareLink = url;
                string shortUrl = string.Empty;
                //将淘口令改成pid,2017-04-07 修改,淘口令改到分享时生产
                string tpwd = (string.IsNullOrEmpty(group.pid) ? "mm_33648229_22032774_73500078" : group.pid);// "[二合一淘口令]";// HotTaoApiService.Instance.taobao_wireless_share_tpwd_create(item.goodsMainImgUrl, item.shareLink, item.goodsName, appkey, appsecret);
                string text = templateText;

                if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(tpwd))
                {
                    if (text.Contains("[商品标题]"))
                    {
                        text = text.Replace("[商品标题]", item.goodsName);
                    }
                    if (text.Contains("[商品价格]"))
                    {
                        text = text.Replace("[商品价格]", item.goodsPrice.ToString());
                    }
                    if (text.Contains("[券后价格]"))
                    {
                        text = text.Replace("[券后价格]", (item.goodsPrice - item.couponPrice).ToString());
                    }
                    if (text.Contains("[来源]"))
                    {
                        text = text.Replace("[来源]", item.goodsSupplier);
                    }
                    if (text.Contains("[销量]"))
                    {
                        text = text.Replace("[销量]", item.goodsSalesAmount.ToString());
                    }
                    if (text.Contains("[优惠券价格]"))
                    {
                        text = text.Replace("[优惠券价格]", item.couponPrice.ToString());
                    }
                    if (text.Contains("[分隔符]"))
                    {
                        text = text.Replace("[分隔符]", "-----------------");
                    }
                    if (text.Contains("[简介描述]"))
                    {
                        text = text.Replace("[简介描述]", string.IsNullOrEmpty(item.goodsIntro) ? "" : item.goodsIntro);
                    }

                    if (text.Contains("[商品地址]"))
                    {
                        text = text.Replace("[商品地址]", item.goodsDetailUrl);
                    }

                    if (text.Contains("[优惠券地址]"))
                    {
                        text = text.Replace("[优惠券地址]", item.couponUrl);
                    }
                }
                else
                {
                    share.status = 2;
                }
                share.goodsid = Convert.ToInt32(item.id);
                share.text    = text;
                share.tpwd    = tpwd;
                share.field1  = item.goodslocatImgPath;

                if (isJoinImage)
                {
                    string _url = GlobalConfig.couponUrl;
                    _url += "?src=ht_hot&activityId=" + item.couponId;
                    _url += "&itemId=" + item.goodsId.Replace("=", "");
                    _url += "&pid=" + tpwd;
                    var _tpwd = "";
                    share.field2 = _tpwd;

                    bool isLogin = true;

                    Tuple <string, string> resultTuple = TaobaoHelper.GetGaoYongToken(item.goodsDetailUrl, item.goodsId, tpwd, MyUserInfo.GetTbToken(), MyUserInfo.cookies, out isLogin);
                    string shareText = "";
                    if (resultTuple != null)
                    {
                        if (isLogin)
                        {
                            shareText = resultTuple.Item1;
                        }
                    }
                    //商品数据
                    joinList.collectionGoodsList.Add(new CollectionGoods()
                    {
                        goodsId           = item.goodsId,
                        goodsName         = item.goodsName,
                        price             = item.goodsPrice,
                        discountAmount    = item.couponPrice,
                        goodsPromotionUrl = _url,
                        goodsPrimaryImg   = item.goodsMainImgUrl,
                        shareText         = shareText
                    });
                    //图片
                    joinList.ImageList.Add(new JoinGoodsInfo()
                    {
                        GoodsName   = item.goodsName,
                        GoodsPrice  = item.goodsPrice,
                        CouponPrice = item.couponPrice,
                        imagePath   = item.goodslocatImgPath,
                        GoodsIntro  = item.goodsIntro
                    });
                }
                share.field6 = isJoinImage ? 1 : 0;
                share.field3 = group.id.ToString();
                AddUserWechatSharetext(share);
                result?.Invoke(share);
            }
            if (isJoinImage)
            {
                joinList.TaskId = taskid;
                joinList.id     = Convert.ToInt32(group.id);
            }
            return(true);
        }