Ejemplo n.º 1
0
        /// <summary>
        /// 申请高佣活动/营销计划
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        private static Tuple <string, string> GetGaoyong(string url, CookieCollection cookies)
        {
            Tuple <string, string> result           = null;
            CookieContainer        cookiesContainer = new CookieContainer();

            cookiesContainer.Add(cookies);
            string           content      = HttpRequestService.HttpGet(url, cookiesContainer);
            AuctionCodeModel searchResult = JsonConvert.DeserializeObject <AuctionCodeModel>(content);

            if (searchResult != null && searchResult.ok && searchResult.data != null)
            {
                string token = string.IsNullOrEmpty(searchResult.data.couponLinkTaoToken) ? searchResult.data.taoToken : searchResult.data.couponLinkTaoToken;
                string link  = string.IsNullOrEmpty(searchResult.data.couponShortLinkUrl) ? searchResult.data.shortLinkUrl : searchResult.data.couponShortLinkUrl;
                result = new Tuple <string, string>(token, link);
            }
            return(result);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 检查淘宝登录
 /// </summary>
 /// <param name="tbToken"></param>
 /// <returns></returns>
 public static bool checkLogin()
 {
     try
     {
         string          url = string.Format("http://pub.alimama.com/pubauc/getCommonCampaignByItemId.json?itemId={0}&t={1}&_tb_token_={2}&pvid=", "", getClientMsgId(), MyUserInfo.GetTbToken());
         CookieContainer cookiesContainer = new CookieContainer();
         cookiesContainer.Add(MyUserInfo.cookies);
         string content = HttpRequestService.HttpGet(url, cookiesContainer);
         if (content.Contains("html"))
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取高佣活动和营销计划的淘口令,Item1 淘口令,Item2 短链
        /// </summary>
        /// <param name="goodsUrl"></param>
        /// <param name="goodsId"></param>
        /// <param name="pid">Pid</param>
        /// <returns></returns>
        public static Tuple <string, string> GetGaoYongToken(string goodsUrl, string goodsId, string pid, string tbToken, CookieCollection cookies, out bool isLogin)
        {
            Tuple <string, string> resultTuple = null;

            isLogin = true;
            try
            {
                //PID  mm_aaaa_bbbb_cccc
                //aaaa:memberid
                //bbbb:siteid
                //ccc:adzoneid

                string dictKey = string.Format("{0}_{1}", pid, goodsId);
                //判断同商品相同的推广位,是否已经申请过淘口令
                if (tokenDict.ContainsKey(dictKey))
                {
                    string _token = string.Empty;
                    tokenDict.TryGetValue(dictKey, out resultTuple);
                    return(resultTuple);
                }
                //淘宝未登录,请登录淘宝
                if (cookies == null)
                {
                    isLogin     = false;
                    resultTuple = new Tuple <string, string>("", "");
                    return(resultTuple);
                }


                var pids = pid.Replace("mm_", "").Split('_');

                if (pids.Length != 3)
                {
                    return(resultTuple);
                }

                string          adzoneid         = pids[2];
                string          siteid           = pids[1];
                string          searchUrl        = string.Format("http://pub.alimama.com/items/search.json?q={0}&_t={1}&auctionTag=&perPageSize=40&shopTag=&t={1}&_tb_token_={2}&pvid=", HttpUtility.UrlEncode(goodsUrl), getClientMsgId(), tbToken);
                CookieContainer cookiesContainer = new CookieContainer();
                cookiesContainer.Add(cookies);
                string  content     = HttpRequestService.HttpGet(searchUrl, cookiesContainer);
                decimal tkRate      = 0;
                decimal eventRate   = 0;
                bool    tkMktStatus = false;
                bool    resultOk    = false;
                if (!string.IsNullOrEmpty(content))
                {
                    try
                    {
                        TaobaoSearchResultModel searchResult = JsonConvert.DeserializeObject <TaobaoSearchResultModel>(content);
                        if (searchResult != null && searchResult.ok && searchResult.data.pageList != null)
                        {
                            //通用计划
                            tkRate = searchResult.data.pageList[0].tkRate;

                            if (!string.IsNullOrEmpty(searchResult.data.pageList[0].eventRate))
                            {
                                eventRate = Convert.ToDecimal(searchResult.data.pageList[0].eventRate);
                            }

                            if (!string.IsNullOrEmpty(searchResult.data.pageList[0].tkMktStatus))
                            {
                                tkMktStatus = Convert.ToInt32(searchResult.data.pageList[0].tkMktStatus) == 1;
                            }
                            resultOk = true;
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                if (resultOk)
                {
                    //判断是否是营销计划
                    if (tkMktStatus && tkRate > eventRate)
                    {
                        //开始申请营销计划佣金
                        string url = string.Format("http://pub.alimama.com/common/code/getAuctionCode.json?auctionid={0}&adzoneid={1}&siteid={2}&scenes=1&t={3}&_tb_token_={4}&pvid=", goodsId, adzoneid, siteid, getClientMsgId(), tbToken);
                        resultTuple = GetGaoyong(url, cookies);
                        if (resultTuple != null)
                        {
                            tokenDict[dictKey] = resultTuple;
                            return(resultTuple);
                        }
                    }
                    else //判断是否有高佣金
                    {
                        //获取更多定向计划数据
                        string url = string.Format("http://pub.alimama.com/pubauc/getCommonCampaignByItemId.json?itemId={0}&t={1}&_tb_token_={2}&pvid=", goodsId, getClientMsgId(), tbToken);
                        cookiesContainer = null;
                        cookiesContainer = new CookieContainer();
                        cookiesContainer.Add(cookies);
                        content = HttpRequestService.HttpGet(url, cookiesContainer);
                        if (content.Contains("html"))
                        {
                            isLogin     = false;
                            resultTuple = new Tuple <string, string>("", "");
                            return(resultTuple);
                        }
                        else
                        {
                            try
                            {
                                TaobaoCommonCampaignItemsModel items = JsonConvert.DeserializeObject <TaobaoCommonCampaignItemsModel>(content);
                                if (items != null && items.ok && items.data != null && items.data.Count > 0)
                                {
                                    //过滤人工审核的佣金计划
                                    var data              = items.data.FindAll(r => r.manualAudit == 0);
                                    var listData          = data.OrderByDescending(r => r.commissionRate).ToList();
                                    TaobaoCommonItem item = listData[0];
                                    //如果定向佣金大于通用和高佣活动的佣金
                                    if (tkRate < item.commissionRate && eventRate < item.commissionRate && !tkMktStatus)
                                    {
                                        tkRate    = 0;
                                        eventRate = 0;
                                    }
                                }
                            }
                            catch (Exception) { }
                            //如果高佣活动佣金大于通用佣金
                            if (eventRate > tkRate)
                            {
                                //开始申请高佣活动
                                url         = string.Format("http://pub.alimama.com/common/code/getAuctionCode.json?auctionid={0}&adzoneid={1}&siteid={2}&scenes=3&channel=tk_qqhd&t={3}&_tb_token_={4}&pvid=", goodsId, adzoneid, siteid, getClientMsgId(), tbToken);
                                resultTuple = GetGaoyong(url, cookies);
                                if (resultTuple != null)
                                {
                                    tokenDict[dictKey] = resultTuple;
                                    return(resultTuple);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(string.Format("GetGaoYongToken:message:{0},StackTrace:{1}", ex.Message, ex.StackTrace));
                return(resultTuple);
            }
            return(resultTuple);
        }