Exemplo n.º 1
0
        public JsonResult GetCoupons(string q, int pageno = 1)
        {
            ITopClient client             = new DefaultTopClient(config.url, config.appkey, config.secret);
            TbkDgItemCouponGetRequest req = new TbkDgItemCouponGetRequest();

            req.AdzoneId = config.addzoneId;
            req.Platform = 2L;

            req.PageSize = 40L;
            req.Q        = q;
            req.PageNo   = pageno;

            LogHelper.WriteLog(typeof(HomeController), "搜索记录:" + q);

            TbkDgItemCouponGetResponse rsp = client.Execute(req);

            if (rsp.Results != null)
            {
                return(Json(new { success = true, data = rsp.Results.OrderByDescending(s => s.Volume) }));
            }
            else
            {
                return(Json(new { success = false }));
            }
        }
Exemplo n.º 2
0
        public async Task <object> GetCoupons(string q, long?pageNo, long?pageSize)
        {
            string     url                = "http://gw.api.taobao.com/router/rest";
            string     format             = "json";
            ITopClient client             = new DefaultTopClient(url, appkey, appsecret, format);
            TbkDgItemCouponGetRequest req = new TbkDgItemCouponGetRequest();

            req.AdzoneId = 132554802L;
            req.Q        = q;
            req.PageNo   = pageNo ?? 1;
            req.PageSize = pageSize ?? 24;
            TbkDgItemCouponGetResponse response = client.Execute(req);

            return(response.Body);
        }
Exemplo n.º 3
0
        public static string GetCouponList(string cat = "", string keyword = "", int pageIndex = 1, int pageSize = 20)
        {
            var topClient = GetTaoClientSinglone();
            TbkDgItemCouponGetRequest req = new TbkDgItemCouponGetRequest();

            req.AdzoneId = adzone_id;
            req.Platform = 1L;
            req.Cat      = cat;
            req.PageSize = pageSize;
            req.Q        = keyword;
            req.PageNo   = pageIndex;
            TbkDgItemCouponGetResponse rsp = topClient.Execute(req);


            rsp.Results.ForEach(dgItem =>
            {
                var result = GetTaoCode(dgItem.Title, dgItem.CouponClickUrl, dgItem.PictUrl);
            });

            return(rsp.Body);
        }
Exemplo n.º 4
0
        public static List <string> PostQuans(string q, long PageNo)
        {
            List <string> ReturnInfos = new List <string>();
            string        serverUrl   = "http://gw.api.taobao.com/router/rest";
            string        appkey      = "24984684";
            string        secret      = "b52c6c517d488ca9ccb95411daede241";
            long          adzonrid    = 11262850424L;
            ITopClient    client      = new DefaultTopClient(serverUrl, appkey, secret);
            //调用好券清单API,返回一个列表
            TbkDgItemCouponGetRequest GetReq = new TbkDgItemCouponGetRequest();

            GetReq.AdzoneId = adzonrid;
            GetReq.Platform = 1;
            GetReq.PageSize = 15L;
            GetReq.Q        = q;
            GetReq.PageNo   = PageNo;
            TbkDgItemCouponGetResponse GetRsp = client.Execute(GetReq);     //获取一个结果列表

            foreach (var item in GetRsp.Results)
            {
                //获取每个宝贝的现价、优惠价
                TbkItemInfoGetRequest InfoReq = new TbkItemInfoGetRequest();
                InfoReq.NumIids  = item.NumIid.ToString();
                InfoReq.Platform = 1;
                TbkItemInfoGetResponse InfoRsp = client.Execute(InfoReq);

                //生成淘口令
                TbkTpwdCreateRequest TpwdReq = new TbkTpwdCreateRequest();
                TpwdReq.Text = item.Title;
                TpwdReq.Url  = item.CouponClickUrl;
                TpwdReq.Logo = item.PictUrl;
                TbkTpwdCreateResponse TpwdRsp = client.Execute(TpwdReq);

                //淘口令短链接
                TbkSpreadGetRequest SpreadReq = new TbkSpreadGetRequest();
                List <TbkSpreadGetRequest.TbkSpreadRequestDomain> urls       = new List <TbkSpreadGetRequest.TbkSpreadRequestDomain>();
                TbkSpreadGetRequest.TbkSpreadRequestDomain        native_url = new TbkSpreadGetRequest.TbkSpreadRequestDomain();
                urls.Add(native_url);
                native_url.Url      = item.CouponClickUrl;
                SpreadReq.Requests_ = urls;
                TbkSpreadGetResponse SpreadRsp = client.Execute(SpreadReq);

                if (SpreadRsp.Results.FirstOrDefault().ErrMsg == "OK")
                {
                    //拼接字符串:商品标题,图片,现价,折后价,下单链接,淘口令
                    string Detail_Info = string.Empty;
                    Detail_Info += string.Format("【{0}】\n", item.Title);
                    Detail_Info += string.Format("[CQ:emoji,id=128073]{0}\n", item.ItemDescription);
                    Detail_Info += string.Format("[CQ:image,file={0}]\n", item.PictUrl);
                    Detail_Info += string.Format("现价:¥{0}\n", item.ZkFinalPrice);
                    Detail_Info += string.Format("券后价:¥{0}\n", ZHPrice(item.ZkFinalPrice, item.CouponInfo));
                    Detail_Info += string.Format("【领券下单链接】{0}", SpreadRsp.Results.FirstOrDefault().Content);
                    Detail_Info += string.Format("点击链接,再选择浏览器打开,或者复制这段描述{0}后到淘宝", TpwdRsp.Data.Model);
                    ReturnInfos.Add(Detail_Info);
                }
                else
                {
                    continue;
                }
            }

            return(ReturnInfos);
        }
Exemplo n.º 5
0
        //查券
        //链接转换
        public static string Handle4(string message)
        {
            string     serverUrl = "http://gw.api.taobao.com/router/rest";
            string     appkey    = "24984684";
            string     secret    = "b52c6c517d488ca9ccb95411daede241";
            long       adzonrid  = 11262850424L;
            ITopClient client    = new DefaultTopClient(serverUrl, appkey, secret);

            //分析语句中的操作关键词
            //提取关键词,返回操作结果
            //1、有没有,还有,我要,我想要,我要买,我想买,优惠
            string keyword = string.Empty;
            string CallbackMessage;

            keyword = GetKeyword(message);
            if (keyword == "NoKey")
            {
                //抛出异常
                CallbackMessage = "warning:无法识别所要识别的商品," + message;
            }
            else
            {
                //调用好券清单API
                TbkDgItemCouponGetRequest req = new TbkDgItemCouponGetRequest();
                req.AdzoneId = adzonrid;
                req.Platform = 1L;
                //req.Cat = "16,18";
                req.PageSize = 1L;
                req.Q        = keyword;
                req.PageNo   = 1L;
                TbkDgItemCouponGetResponse rsp = client.Execute(req);

                if (rsp.Results.Count > 0)
                {
                    var item = rsp.Results.FirstOrDefault();
                    //调用淘口令生成API生成淘口令
                    TbkTpwdCreateRequest treq = new TbkTpwdCreateRequest();
                    treq.Text = item.Title;
                    treq.Url  = item.CouponClickUrl;
                    treq.Logo = item.SmallImages.FirstOrDefault();
                    TbkTpwdCreateResponse trsp = client.Execute(treq);

                    //调用接口生成商品详情信息
                    TbkItemInfoGetRequest ireq = new TbkItemInfoGetRequest();
                    ireq.NumIids  = item.NumIid.ToString();
                    ireq.Platform = 1;
                    TbkItemInfoGetResponse irsp = client.Execute(ireq);

                    if (trsp.Data != null && irsp.Results.Count > 0)
                    {
                        //CallbackMessage = string.Format("【{0}】\n{1}\n在浏览器里打开链接或者复制这段描述{2}在淘宝里打开", item.Title, item.CouponClickUrl, trsp.Data.Model);
                        string searchUrl = "http://52lequan.cn/index.php?r=l&kw=" + System.Web.HttpUtility.UrlEncode(keyword, System.Text.Encoding.UTF8);
                        CallbackMessage = string.Format("【{0}】\n" +
                                                        "[CQ:image,file={6}]\n" +
                                                        "现价:{1}\n" +
                                                        "券后价:{2}\n" +
                                                        //"【下单链接】\n" +
                                                        "——————————\n" +
                                                        "复制这条信息,{4},打开【手机淘宝】即可查看\n" +
                                                        "更多优惠请点击{5}", item.Title, item.ZkFinalPrice, ZHPrice(item.ZkFinalPrice, item.CouponInfo), item.CouponClickUrl, trsp.Data.Model, searchUrl, item.PictUrl);
                    }
                    else
                    {
                        CallbackMessage = "error:获取淘口令出错," + trsp.SubErrMsg;
                    }
                }
                else
                {
                    CallbackMessage = "error:获取优惠信息出错," + rsp.SubErrMsg;
                }


                //CallbackMessage = string.Format("{0}\n券后价:{1}\n在售价:{2}\n【下单链接】\n{3}\n——————————\n复制这条信息,{4},打开【手机淘宝】即可查看\n更多优惠请点击{5}[CQ:image,file={6}\n测试:{7}", item.Title, item.ZkFinalPrice, item.ReservePrice, item.ItemUrl, tbkTpwdCreateResponse.Data.Model, searchurl, item.PictUrl, item.ClickUrl);
            }
            return(CallbackMessage);

            //2、链接转换-暂时不实现
        }
Exemplo n.º 6
0
        public ReturnResult <List <CouponInfo> > GetCouponList(long pageNo, long pageSize, string q)
        {
            ReturnResult <List <CouponInfo> > result = new ReturnResult <List <CouponInfo> >();
            List <CouponInfo> data = new List <CouponInfo>();

            if (pageNo == null)
            {
                pageNo = 1;
            }
            if (pageSize == null)
            {
                pageSize = 24;
            }

            string     url                = "http://gw.api.taobao.com/router/rest";
            string     format             = "json";
            ITopClient client             = new DefaultTopClient(url, appkey, appsecret, format);
            TbkDgItemCouponGetRequest req = new TbkDgItemCouponGetRequest();

            req.AdzoneId = 132798493L;
            req.Q        = q;
            req.PageNo   = pageNo;
            req.PageSize = pageSize;
            req.Platform = 2;
            TbkDgItemCouponGetResponse response = client.Execute(req);

            JObject jsonObj = JObject.Parse(response.Body);
            string  coupons;

            try
            {
                coupons = jsonObj["tbk_dg_item_coupon_get_response"]["results"]["tbk_coupon"].ToString();
            }
            catch
            {
                result.code    = -116;
                result.message = "没有相关粉丝福利券!";
                return(result);
            }

            JArray jar = JArray.Parse(coupons);

            foreach (var temp in jar)
            {
                data.Add(
                    new CouponInfo
                {
                    category            = temp["category"].ToString(),
                    commission_rate     = temp["commission_rate"].ToString(),
                    coupon_click_url    = temp["coupon_click_url"].ToString(),
                    coupon_end_time     = temp["coupon_end_time"].ToString(),
                    coupon_info         = temp["coupon_info"].ToString(),
                    coupon_remain_count = temp["coupon_remain_count"].ToString(),
                    coupon_start_time   = temp["coupon_start_time"].ToString(),
                    coupon_total_count  = temp["coupon_total_count"].ToString(),
                    item_description    = temp["item_description"].ToString(),
                    item_url            = temp["item_url"].ToString(),
                    nick           = temp["nick"].ToString(),
                    num_iid        = temp["num_iid"].ToString(),
                    pict_url       = temp["pict_url"].ToString(),
                    seller_id      = temp["seller_id"].ToString(),
                    shop_title     = temp["shop_title"].ToString(),
                    title          = temp["title"].ToString(),
                    user_type      = temp["user_type"].ToString(),
                    volume         = temp["volume"].ToString(),
                    zk_final_price = temp["zk_final_price"].ToString(),
                }
                    );
            }

            result.code = 1;
            result.data = data;

            return(result);
        }
Exemplo n.º 7
0
        /// <summary>
        /// taobao.tbk.dg.item.coupon.get( 好券清单API【导购】 )
        /// </summary>
        public static List <Items> QueryDgItemCoupon(PageInfo pageInfo, int cateId, string keyword, int platformId = 1)
        {
            List <Items> result = new List <Items>(100);

            try
            {
                var client = GetClient();
                TbkDgItemCouponGetRequest req = new TbkDgItemCouponGetRequest();
                req.AdzoneId = 108899300176; //pid: mm_25162659_311500292_108899300176的第三位
                req.Platform = platformId;   // 1 淘宝,2 天猫
                if (cateId > 0)
                {
                    req.Cat = cateId.ToString();//后台类目ID,用,分割,最大10个,该ID可以通过taobao.itemcats.get接口获取到
                }
                else
                {
                    req.Q = keyword;
                }

                req.PageSize = pageInfo.PageSize;

                req.PageNo = pageInfo.PageIndex;//第几页,默认:1(当后台类目和查询词均不指定的时候,最多出10000个结果,即page_no*page_size不能超过10000;当指定类目或关键词的时候,则最多出100个结果)
                TbkDgItemCouponGetResponse rsp = client.Execute(req);

                var rsps      = client.Execute(req);
                var configMap = new MapperConfiguration(
                    cfg => cfg.CreateMap <TbkCouponDomain, Items>()
                    .ForMember(dest => dest.TotalCount, m => m.MapFrom(src => src.CouponTotalCount))
                    .ForMember(dest => dest.SellPrice, m => m.MapFrom(src => src.ZkFinalPrice))
                    .ForMember(dest => dest.CommissionRate, m => m.MapFrom(src => src.CommissionRate))
                    .ForMember(dest => dest.PicUrl, m => m.MapFrom(src => src.PictUrl))
                    .ForMember(dest => dest.ShopName, m => m.MapFrom(src => src.ShopTitle))
                    .ForMember(dest => dest.BeginTime, m => m.MapFrom(src => src.CouponStartTime))
                    .ForMember(dest => dest.EndTime, m => m.MapFrom(src => src.CouponEndTime))
                    .ForMember(dest => dest.ClickUrl, m => m.MapFrom(src => src.CouponClickUrl))
                    .ForMember(dest => dest.ItemDesc, m => m.MapFrom(src => src.ItemDescription))
                    .ForMember(dest => dest.RemainCount, m => m.MapFrom(src => src.CouponRemainCount))
                    .ForMember(dest => dest.ItemInfo, m => m.MapFrom(src => src.CouponInfo))
                    .ForMember(dest => dest.ProductUrl, m => m.MapFrom(src => src.ItemUrl))
                    .ForMember(dest => dest.SmallImages, m => m.MapFrom(src => src.SmallImages.ToListString(',')))
                    );
                var mapper = configMap.CreateMapper();

                if (rsp.TotalResults == 0)
                {
                    return(new List <Items>());
                }


                foreach (var item in rsp.Results)
                {
                    var dest = mapper.Map <TbkCouponDomain, Items>(item);
                    dest.TypeId   = 1;
                    dest.LastTime = DateTime.Now;
                    if (dest.Commission <= 0)
                    {
                        dest.Commission = dest.SellPrice * dest.CommissionRate / 100;
                    }
                    dest.CateId      = dest.Category;
                    dest.OrdId       = 1;
                    dest.IsShow      = 1;
                    dest.AliId       = platformId.ToString();
                    dest.Status      = 1;
                    dest.Platform    = platformId.ToString();
                    dest.ProductUrl += string.IsNullOrEmpty(dest.ProductUrl) ? "" : pid;
                    if (keyword != null && keyword.Length < 6)
                    {
                        dest.Tags = keyword;
                    }

                    if (!string.IsNullOrEmpty(dest.ItemInfo))
                    {
                        if (dest.ItemInfo.Contains("无条件"))
                        {
                            var temp = dest.ItemInfo.Split("元");
                            dest.YouhuiPrice = temp[0].TryToDecimal();
                        }
                        else if (dest.ItemInfo.Contains("减"))
                        {
                            var temp = dest.ItemInfo.Split("减");
                            dest.YouhuiPrice = temp[1].Replace("元", "").TryToDecimal();
                        }
                        dest.FinalPrice = dest.SellPrice - dest.YouhuiPrice;
                    }
                    result.Add(dest);
                    Console.WriteLine($"Title:{dest.Title},Rate:{dest.CommissionRate},Time:{DateTime.Now}");
                }
            }
            catch (Exception ex)
            {
                Logger.WriteErrorLog(ex.Message);
            }

            return(result);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 好券清单API【导购】
        /// http://open.taobao.com/docs/api.htm?spm=a219a.7629065.0.0.7LescP&apiId=29821
        /// </summary>
        public void Pull_taobao_tbk_get()
        {
            Console.WriteLine("请输入操作类型(1 好券清单;2 后台类目):");

            var strType = Console.ReadLine();

            if (strType == "1")
            {
                try
                {
                    while (true)
                    {
                        #region 好券清单API

                        Console.WriteLine("请输入查询关键字:");
                        var strKey = Console.ReadLine();

                        Console.WriteLine("请输入查询分类ID,多个用 , 分割,回车之后开始拉取:");
                        var strCateIds = Console.ReadLine();
                        if (string.IsNullOrWhiteSpace(strKey))
                        {
                            while (string.IsNullOrWhiteSpace(strCateIds))
                            {
                                Console.WriteLine("请输入查询分类ID,多个用 , 分割,回车之后开始拉取:");
                                strCateIds = Console.ReadLine();
                            }
                        }

                        List <Taobao_tbk_dg_item_coupon_get> tbkCouponList = new List <Taobao_tbk_dg_item_coupon_get>();
                        DateTime dtNow = DateTime.Now;

                        #region

                        Console.WriteLine("开始拉取...");

                        ITopClient client             = new DefaultTopClient(url, appkey, appsecret);
                        TbkDgItemCouponGetRequest req = new TbkDgItemCouponGetRequest();
                        req.AdzoneId = adzone_id;
                        req.PageNo   = 1;
                        req.PageSize = 100;
                        req.Q        = strKey;
                        req.Cat      = strCateIds;
                        req.Platform = 2;

                        TbkDgItemCouponGetResponse response = client.Execute(req);
                        if (response != null && response.Results != null && response.Results.Count > 0)
                        {
                            foreach (var res in response.Results)
                            {
                                #region

                                Taobao_tbk_dg_item_coupon_get tbk = new Taobao_tbk_dg_item_coupon_get();
                                tbk.Shop_title          = res.ShopTitle;
                                tbk.User_type           = Convert.ToInt32(res.UserType);
                                tbk.Zk_final_price      = res.ZkFinalPrice;
                                tbk.Title               = res.Title;
                                tbk.Nick                = res.Nick;
                                tbk.Seller_id           = res.SellerId;
                                tbk.Volume              = res.Volume;
                                tbk.Pict_url            = res.PictUrl;
                                tbk.Item_url            = res.ItemUrl;
                                tbk.Coupon_total_count  = res.CouponTotalCount;
                                tbk.Commission_rate     = res.CommissionRate;
                                tbk.Coupon_info         = res.CouponInfo;
                                tbk.Category            = Convert.ToInt32(res.Category);
                                tbk.Num_iid             = res.NumIid;
                                tbk.Coupon_remain_count = res.CouponRemainCount;
                                tbk.Coupon_start_time   = res.CouponStartTime;
                                tbk.Coupon_end_time     = res.CouponEndTime;
                                tbk.Coupon_click_url    = res.CouponClickUrl;
                                tbk.Item_description    = res.ItemDescription;
                                //tbk.Small_images = res.SmallImages;
                                tbk.RowCreateTime = dtNow;
                                tbk.IsHandle      = false;

                                #endregion

                                tbkCouponList.Add(tbk);
                            }

                            //Console.WriteLine("防止API频率限制,休眠 100 ms ....");
                            //Thread.Sleep(100);
                            Console.WriteLine(string.Format("结束拉取...成功拉取 {0} 条数据", response.Results.Count));
                        }
                        else
                        {
                            Console.WriteLine(" API 未能返回数据,退出本次拉取...");
                        }

                        #endregion

                        if (tbkCouponList.Count > 0)
                        {
                            //落地数据库
                            Console.WriteLine("开始落地数据库,时间稍长......");
                            using (PointDataDataContext pd = new PointDataDataContext())
                            {
                                pd.Taobao_tbk_dg_item_coupon_get.InsertAllOnSubmit(tbkCouponList);
                                pd.SubmitChanges();
                            }
                            Console.WriteLine("结束落地数据库......");
                        }

                        Console.WriteLine(string.Format("成功拉取 好券清单API【导购】......本次共拉取 {0} 条数据", tbkCouponList.Count));

                        Console.WriteLine("");
                        Console.WriteLine("*****************************************************************");
                        Console.WriteLine("");

                        #endregion
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("拉取 好券清单API【导购】 异常:" + ex.ToString());
                }
            }
            else
            {
                try
                {
                    Console.WriteLine("开始拉取后台类目...");


                    ITopClient client = new DefaultTopClient(url, appkey, appsecret);
                    //ItemAddRequest sdf = new AlibabaWholesaleCategoryGetRequest();
                    //ItemcatsGetRequest req = new ItemcatsGetRequest();
                    ////req.Cids = "18957,19562";
                    ////req.Datetime = DateTime.Parse("2000-01-01 00:00:00");
                    ////req.Fields = "cid,parent_cid,name,is_parent";
                    ////req.ParentCid = 50011999L;
                    //ItemcatsGetResponse rsp = client.Execute(req);
                    //Console.WriteLine(rsp.Body);

                    Console.WriteLine(string.Format("成功拉取后台类目......本次共拉取 {0} 条数据", 12));

                    Console.WriteLine("");
                    Console.WriteLine("*****************************************************************");
                    Console.WriteLine("");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("拉取 后台类目 异常:" + ex.ToString());
                }
            }
        }