public IHttpActionResult Post(TbkDgMaterialOptionalRequest req) { ITopClient client = new DefaultTopClient(_tbkApiUrl, _appkey, _secret, _format); req.AdzoneId = _adzoneId; TbkDgMaterialOptionalResponse rsp = client.Execute(req); return(Json(rsp.Body)); }
/// <summary> /// 淘宝物料搜索接口,获取佣金、优惠券信息 /// </summary> /// <param name="key"></param> /// <returns></returns> public IList <MapDataDomain> MaterialOptional(string key) { if (string.IsNullOrEmpty(appkey) || string.IsNullOrEmpty(secret) || addzoneId == 0) { throw new Exception("请检查是否设置接口url、淘宝appkey、secret及addzoneId"); } ITopClient client = new DefaultTopClient(apiUrl, appkey, secret); TbkDgMaterialOptionalRequest req = new TbkDgMaterialOptionalRequest(); req.AdzoneId = addzoneId; req.Platform = 2L; req.PageSize = 100L; req.Q = key; req.PageNo = 1L; TbkDgMaterialOptionalResponse rsp = client.Execute(req); return(rsp.ResultList); }
/// <summary> /// taobao.tbk.dg.material.optional( 通用物料搜索API(导购) ) /// </summary> public static void GetDgMaterialOptional() { var client = GetClient(); TbkDgMaterialOptionalRequest req = new TbkDgMaterialOptionalRequest(); req.StartDsr = 10L; req.PageSize = 20L; req.PageNo = 1L; req.Platform = 1L; req.EndTkRate = 1234L; req.StartTkRate = 1234L; req.EndPrice = 10L; req.StartPrice = 10L; req.IsOverseas = false; req.IsTmall = false; req.Sort = "tk_rate_des"; req.Itemloc = "杭州"; req.Cat = "16,18"; req.Q = "女装"; req.MaterialId = 2836L; req.HasCoupon = false; req.Ip = "13.2.33.4"; req.AdzoneId = 12345678L;//mm_xxx_xxx_12345678三段式的最后一段数字,Must req.NeedFreeShipment = true; req.NeedPrepay = true; req.IncludePayRate30 = true; req.IncludeGoodRate = true; req.IncludeRfdRate = true; req.NpxLevel = 2L; req.EndKaTkRate = 1234L; req.StartKaTkRate = 1234L; req.DeviceEncrypt = "MD5"; req.DeviceValue = "xxx"; req.DeviceType = "IMEI"; TbkDgMaterialOptionalResponse rsp = client.Execute(req); Console.WriteLine(rsp.Body); }
public static string GetTaobaoCoupon(RequestMessageText responseMessageText) { string itemInfo = responseMessageText.Content.Trim(); string responeMessage = ""; try { Match m_title = Regex.Match(itemInfo, @"【.*】"); string temp = m_title.Value; if (!string.IsNullOrEmpty(temp)) { temp = temp.Substring(1, temp.Length - 2); } else { return(""); } if (temp.Contains("#手聚App")) { int IndexofA = temp.IndexOf("宝贝不错:"); int IndexofB = temp.IndexOf("(分享自"); temp = temp.Substring(IndexofA + 5, IndexofB - IndexofA - 5); } string title = temp; //通过商品关键字查询商品 ITopClient client = new DefaultTopClient(taobaoApiUrl, taobaoAppkey, taobaoSecret); TbkDgMaterialOptionalRequest req = new TbkDgMaterialOptionalRequest(); req.AdzoneId = addzoneId; req.Platform = 2L; req.PageSize = 100L; req.Q = title; req.PageNo = 1L; TbkDgMaterialOptionalResponse rsp = client.Execute(req); if (rsp.ResultList.Count > 0) { //获取淘宝短链接 Match m_url = Regex.Match(itemInfo, @"htt(p|ps):\/\/([\w\-]+(\.[\w\-]+)*\/)*[\w\-]+(\.[\w\-]+)*\/?(\?([\w\-\.,@?^=%&:\/~\+#]*)+)?"); if (m_url.Value == "") { return(responeMessage); } var s = HttpUtility.HttpGet(m_url.Value, "", "utf-8"); //Match am_url = Regex.Match(s, @"(?<=var url = ')(.*)(?=')"); //获取宝贝item id Match m_item = Regex.Match(s, @"(?<=m.taobao.com\/i)([0-9]*)"); string item_id = m_item.Value; if (string.IsNullOrEmpty(item_id)) { Match am_url = Regex.Match(s, @"(?<=var url = ')(.*)(?=')"); var htmlContent = HttpUtility.HttpGet(am_url.Value, "", "gbk"); Match re_m_item = Regex.Match(htmlContent, @"(?<=taobao.com/item.htm\?id=)([0-9]*)"); item_id = re_m_item.Value; } if (string.IsNullOrEmpty(item_id)) { //LogHelper.WriteLog(typeof(WechatController), "通过抓包方式未获取到宝贝item id"); var g = rsp.ResultList.Where(y => !string.IsNullOrEmpty(y.CouponId)).OrderByDescending(w => w.Volume).FirstOrDefault(); if (g == null) { responeMessage = ConfigurationManager.AppSettings["tbk_nocoupon_msg"].Replace("\\n", "\n").Replace("\\ue231", "\ue231"); } else { var hongbao = (decimal.Parse(g.ZkFinalPrice) - decimal.Parse(Regex.Match(g.CouponInfo, "减" + @"(\d+)").Groups[1].Value)) * decimal.Parse(g.CommissionRate) / 10000 * commission_rate; responeMessage = $"{g.Title}\n【在售价】{g.ZkFinalPrice}元\n【巻后价】{Math.Round(double.Parse(g.ZkFinalPrice) - double.Parse(Regex.Match(g.CouponInfo, "减" + @"(\d+)").Groups[1].Value), 2)} 元\n复制这条信息,打开「手机绹宝」领巻下单{GetTaobaoKePassword(g.CouponShareUrl, g.PictUrl + "_400x400.jpg")}\n"; } return(responeMessage); } else { float numid = 0; try { numid = float.Parse(item_id); } catch (Exception ex) { //通过淘宝链接没有获取到item id,显示销量最高商品 var g = rsp.ResultList.Where(y => !string.IsNullOrEmpty(y.CouponId)).OrderByDescending(y => y.Volume).FirstOrDefault(); var hongbao = (decimal.Parse(g.ZkFinalPrice) - decimal.Parse(Regex.Match(g.CouponInfo, "减" + @"(\d+)").Groups[1].Value)) * decimal.Parse(g.CommissionRate) / 10000 * commission_rate; responeMessage = $"{g.Title}\n【在售价】{g.ZkFinalPrice}元\n【巻后价】{Math.Round(double.Parse(g.ZkFinalPrice) - double.Parse(Regex.Match(g.CouponInfo, "减" + @"(\d+)").Groups[1].Value), 2)} 元\n复制这条信息,打开「手机绹宝」领巻下单{GetTaobaoKePassword(g.CouponShareUrl, g.PictUrl + "_400x400.jpg")}\n"; return(responeMessage); } //在接口返回的商品中找查询的商品 foreach (var g in rsp.ResultList) { if (g.NumIid == numid) { if (string.IsNullOrEmpty(g.CouponInfo)) { var hongbao = decimal.Parse(g.ZkFinalPrice) * decimal.Parse(g.CommissionRate) / 10000 * commission_rate; responeMessage = $"{g.Title}\n【在售价】{g.ZkFinalPrice}元\n【约返利】{Math.Round(hongbao, 2)}元\n复制这条信息,打开「手机绹宝」领巻下单{GetTaobaoKePassword(g.Url, g.PictUrl + "_400x400.jpg")}\n==========================\n下单确认收货后就能收到返利佣金啦~\n 点击查看 <a href='http://mp.weixin.qq.com/s?__biz=Mzg2NTAxOTEyMA==&mid=100000146&idx=1&sn=62405c8df3db46e74940aefb9ac3737b&chksm=4e61340d7916bd1bf645afbc6d10c1f19561d7fa59847516c01e64c0791e6d544f4f56c4f498#rd'>如何领取返利</a>"; return(responeMessage); } else { var hongbao = (decimal.Parse(g.ZkFinalPrice) - decimal.Parse(Regex.Match(g.CouponInfo, "减" + @"(\d+)").Groups[1].Value)) * decimal.Parse(g.CommissionRate) / 10000 * commission_rate; responeMessage = $"{g.Title}\n【在售价】{g.ZkFinalPrice}元\n【巻后价】{Math.Round(double.Parse(g.ZkFinalPrice) - double.Parse(Regex.Match(g.CouponInfo, "减" + @"(\d+)").Groups[1].Value), 2)} 元\n复制这条信息,打开「手机绹宝」领巻下单{GetTaobaoKePassword(g.CouponShareUrl, g.PictUrl + "_400x400.jpg")}\n"; return(responeMessage); } } } //没有找到,有相似宝贝推荐 var w = rsp.ResultList.Where(y => !string.IsNullOrEmpty(y.CouponId)).OrderByDescending(y => y.Volume).FirstOrDefault(); if (w == null) { responeMessage = ConfigurationManager.AppSettings["tbk_nocoupon_msg"].Replace("\\n", "\n").Replace("\\ue231", "\ue231"); } else { var hongbao = (decimal.Parse(w.ZkFinalPrice) - decimal.Parse(Regex.Match(w.CouponInfo, "减" + @"(\d+)").Groups[1].Value)) * decimal.Parse(w.CommissionRate) / 10000 * commission_rate; responeMessage = $"/:rose 亲,这款商品的优惠返利活动结束了~\n已为你推荐以下宝贝。\n==========================\n{w.Title}\n【在售价】{w.ZkFinalPrice}元\n【巻后价】{Math.Round(double.Parse(w.ZkFinalPrice) - double.Parse(Regex.Match(w.CouponInfo, "减" + @"(\d+)").Groups[1].Value), 2)} 元\n复制这条信息,打开「手机绹宝」领巻下单{GetTaobaoKePassword(w.CouponShareUrl, w.PictUrl + "_400x400.jpg")}\n"; } return(responeMessage); } } else { responeMessage = ConfigurationManager.AppSettings["tbk_nocoupon_msg"].Replace("\\n", "\n").Replace("\\ue231", "\ue231"); } } catch (Exception ex) { //LogHelper.WriteLog(typeof(WechatController), "返回消息异常" + ex.Message); } return(responeMessage); }