public GoodsSelectedModel GetGoodsInfo(string goodsId) { ITopClient client = new DefaultTopClient(url, appkey, appsecret); TbkItemInfoGetRequest req = new TbkItemInfoGetRequest(); req.Fields = "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url"; req.Platform = 1L; req.NumIids = goodsId; TbkItemInfoGetResponse rsp = client.Execute(req); if (!rsp.IsError) { List <NTbkItem> data = rsp.Results; if (data != null && data.Count() > 0) { NTbkItem item = data[0]; GoodsSelectedModel model = new GoodsSelectedModel() { goodsId = item.NumIid.ToString(), goodsName = item.Title, goodsPrice = Convert.ToDecimal(item.ZkFinalPrice), goodsDetailUrl = item.ItemUrl, goodsImageUrl = item.PictUrl, goodsSalesAmount = Convert.ToInt32(item.Volume), }; return(model); } } return(null); }
/// <summary> /// taobao.tbk.item.info.get( 淘宝客商品详情(简版) ) /// doc:https://open.taobao.com/api.htm?docId=24518&docType=2 /// </summary> public static List <Items> QueryItemDetailInfo(string numiids, int platform) { var client = GetClient(); TbkItemInfoGetRequest req = new TbkItemInfoGetRequest(); req.NumIids = numiids; //123,456商品Id,必须 req.Platform = platform; //链接形式:1:PC,2:无线,默认:1 //req.Ip = "11.22.33.43"; var configMap = new MapperConfiguration( cfg => cfg.CreateMap <NTbkItemDomain, Items>() .ForMember(dest => dest.Area, m => m.MapFrom(src => src.Provcity)) .ForMember(dest => dest.SellPrice, m => m.MapFrom(src => src.ZkFinalPrice)) .ForMember(dest => dest.PicUrl, m => m.MapFrom(src => src.PictUrl)) .ForMember(dest => dest.ShopName, m => m.MapFrom(src => src.Nick)) .ForMember(dest => dest.SmallImages, m => m.MapFrom(src => src.SmallImages.ToListString(','))) .ForMember(dest => dest.Price, m => m.MapFrom(src => src.ReservePrice)) .ForMember(dest => dest.CategoryName, m => m.MapFrom(src => src.CatName)) ); var mapper = configMap.CreateMapper(); List <Items> result = null; try { TbkItemInfoGetResponse rsp = client.Execute(req); if (rsp.Results.Count == 0) { return(null); } result = new List <Items>(rsp.Results.Count); foreach (var item in rsp.Results) { var dest = mapper.Map <NTbkItemDomain, Items>(item); dest.LastTime = DateTime.Now; dest.Tags = item.CatName; if (dest.Commission <= 0) { dest.Commission = dest.SellPrice * dest.CommissionRate / 100; } if (dest.Category > 0) { dest.CateId = dest.Category; } dest.Status = 1; dest.ProductUrl += string.IsNullOrEmpty(dest.ProductUrl) ? "" : pid; result.Add(dest); } } catch (Exception ex) { Logger.WriteErrorLog(ex.Message); } return(result); }
public static NTbkItem GetProduct(long itemId) { ITopClient client = new DefaultTopClient(url, appkey, secret); TbkItemInfoGetRequest req = new TbkItemInfoGetRequest(); req.Fields = "seller_id,num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,click_url,nick,volume"; req.Platform = 1L; req.NumIids = itemId.ToString(); TbkItemInfoGetResponse rsp = client.Execute(req); return(rsp.Results.FirstOrDefault()); }
/// <summary> /// 获取商品详情 /// </summary> /// <param name="req"></param> /// <returns></returns> public AliGoodDetailRes GetGoodDetail(AliGoodDetailReq req) { AliGoodDetailRes res = new AliGoodDetailRes(); ITopClient client = new DefaultTopClient(AliUrl, AliAppKey, AliAppSecret); TbkItemInfoGetRequest request = new TbkItemInfoGetRequest() { Ip = req.Ip, NumIids = req.NumIids, Platform = req.Platform }; TbkItemInfoGetResponse rsp = client.Execute(request); res = DeserializeObject <AliGoodDetailRes>(SerializeObject(rsp)); return(res); }
public ActionResult GetUserOrder(string userids, string typecode, int?page = 1, int?pageSize = 20) { try { var usermodel = db.tb_userinfos.FirstOrDefault(s => s.UserID == userids); if (usermodel == null) { return(Json(Comm.ToJsonResult("nofind", "用户不存在"), JsonRequestBehavior.AllowGet)); } else { int userid = usermodel.ID; int starpagesize = page.Value * pageSize.Value - pageSize.Value; int endpagesize = page.Value * pageSize.Value; List <temptborder> data = new List <temptborder>(); //查询所有订单 if (typecode == "all") { //拼接参数 SqlParameter[] parameters = { new SqlParameter("@userid", SqlDbType.Int), new SqlParameter("@Adzoneid", SqlDbType.NVarChar), new SqlParameter("@starpagesize", SqlDbType.Int), new SqlParameter("@endpagesize", SqlDbType.Int) }; parameters[0].Value = userid; parameters[1].Value = usermodel.Adzoneid; parameters[2].Value = starpagesize; parameters[3].Value = endpagesize; string sqlstr = string.Empty; sqlstr = string.Format(@"SELECT * FROM (SELECT CAST(ROW_NUMBER() over(order by COUNT(g.ID) DESC) AS INTEGER) AS Ornumber,g.GoodsName,g.OrderCode,g.OrderPrice,g.GoodsImage, g.OrderTime,g.SettlementTime,us.EstimateIncome,g.GoodsID,g.ID,g.OrderState FROM dbo.Tborders g INNER JOIN dbo.UserSettlements us ON us.OrderCode=g.OrderCode WHERE us.UserID=@userid AND us.FromUserAdzoneid=@Adzoneid and us.EstimateIncome>0 GROUP BY g.GoodsName,g.OrderCode,g.OrderPrice,g.GoodsImage, g.OrderTime,g.SettlementTime,us.EstimateIncome,g.GoodsID,g.ID,g.OrderState) t WHERE t.Ornumber > @starpagesize AND t.Ornumber<=@endpagesize"); data = db.Database.SqlQuery <temptborder>(sqlstr, parameters).ToList(); } //查询待结算和已结算订单 else if (typecode == "settlementstr" || typecode == "alreadysettledstr") { int state = 0; if (typecode == "settlementstr") { state = 0; } else if (typecode == "alreadysettledstr") { state = 1; } //拼接参数 SqlParameter[] parameters = { new SqlParameter("@userid", SqlDbType.Int), new SqlParameter("@state", SqlDbType.Int), new SqlParameter("@starpagesize", SqlDbType.Int), new SqlParameter("@endpagesize", SqlDbType.Int), new SqlParameter("@Adzoneid", SqlDbType.NVarChar), }; parameters[0].Value = userid; parameters[1].Value = state; parameters[2].Value = starpagesize; parameters[3].Value = endpagesize; parameters[4].Value = usermodel.Adzoneid; string sqlstr = string.Empty; sqlstr = string.Format(@"SELECT * FROM (SELECT CAST(ROW_NUMBER() over(order by COUNT(g.ID) DESC) AS INTEGER) AS Ornumber,g.GoodsName,g.OrderCode,g.OrderPrice,g.GoodsImage, g.OrderTime,g.SettlementTime,us.EstimateIncome,g.GoodsID,g.ID,g.OrderState FROM dbo.Tborders g INNER JOIN dbo.UserSettlements us ON us.OrderCode=g.OrderCode WHERE us.UserID=@userid and us.SettlementState=@state AND us.FromUserAdzoneid=@Adzoneid AND us.EstimateIncome>0 GROUP BY g.GoodsName,g.OrderCode,g.OrderPrice,g.GoodsImage, g.OrderTime,g.SettlementTime,us.EstimateIncome,g.GoodsID,g.ID,g.OrderState) t WHERE t.Ornumber > @starpagesize AND t.Ornumber<=@endpagesize"); data = db.Database.SqlQuery <temptborder>(sqlstr, parameters).ToList(); } else if (typecode == "subordinatestr") { //拼接参数 SqlParameter[] param = { new SqlParameter("@userid", SqlDbType.Int), }; param[0].Value = userid; string tempsql = string.Format(@"SELECT DISTINCT b.ID FROM dbo.tb_userinfo a CROSS JOIN dbo.tb_userinfo b WHERE b.ParentID = @userid"); List <tempuserid> useriddata = db.Database.SqlQuery <tempuserid>(tempsql, param).ToList(); string tempuserstr = ""; if (useriddata.Count > 0) { for (int i = 0; i < useriddata.Count; i++) { if (tempuserstr == "") { tempuserstr = useriddata[i].ID.ToString(); } else { tempuserstr = tempuserstr + "," + useriddata[i].ID.ToString(); } } //拼接参数 SqlParameter[] parameters = { new SqlParameter("@useridstr", SqlDbType.NVarChar), new SqlParameter("@starpagesize", SqlDbType.Int), new SqlParameter("@endpagesize", SqlDbType.Int) }; parameters[0].Value = tempuserstr; parameters[1].Value = starpagesize; parameters[2].Value = endpagesize; string sqlstr = string.Empty; sqlstr = string.Format(@"SELECT * FROM (SELECT CAST(ROW_NUMBER() over(order by COUNT(g.ID) DESC) AS INTEGER) AS Ornumber,g.GoodsName,g.OrderCode,g.OrderPrice,g.GoodsImage, g.OrderTime,g.SettlementTime,us.EstimateIncome,g.GoodsID,g.ID,g.OrderState FROM dbo.Tborders g INNER JOIN dbo.UserSettlements us ON us.OrderCode=g.OrderCode WHERE us.UserID in(@useridstr) AND us.EstimateIncome>0 GROUP BY g.GoodsName,g.OrderCode,g.OrderPrice,g.GoodsImage, g.OrderTime,g.SettlementTime,us.EstimateIncome,g.GoodsID,g.ID,g.OrderState) t WHERE t.Ornumber > @starpagesize AND t.Ornumber<=@endpagesize"); data = db.Database.SqlQuery <temptborder>(sqlstr, parameters).ToList(); } } List <temptborder> tempdata = new List <temptborder>(); if (data.Count > 0) { for (int i = 0; i < data.Count; i++) { temptborder model = new temptborder(); string tempimg = data[i].GoodsImage; if (string.IsNullOrWhiteSpace(tempimg)) { //根据商品id获取商品图片 ITopClient client = new DefaultTopClient(AliPayConfig.tkapp_url, AliPayConfig.tkapp_key, AliPayConfig.tkapp_secret, "json"); TbkItemInfoGetRequest req = new TbkItemInfoGetRequest(); req.NumIids = data[i].GoodsID; req.Platform = 2L; //req.Ip = "11.22.33.43"; TbkItemInfoGetResponse rsp = client.Execute(req); var jsondataformain = Newtonsoft.Json.JsonConvert.DeserializeObject(rsp.Body) as JContainer;//转json格式 var jsonreturn = jsondataformain.SelectToken("tbk_item_info_get_response"); if (jsonreturn != null) { string s = jsonreturn.ToString(); var js = Newtonsoft.Json.JsonConvert.DeserializeObject(s) as JContainer; string s1 = js.SelectToken("results").ToString(); var js1 = Newtonsoft.Json.JsonConvert.DeserializeObject(s1) as JContainer; string s2 = js1.SelectToken("n_tbk_item").ToString(); s2 = s2.TrimEnd(']'); s2 = s2.TrimStart('['); Newtonsoft.Json.Linq.JObject datas = JsonHelper.DeserializeObject(s2.Trim()); if (datas != null) { int tempid = data[i].ID; string tempstr = datas.SelectToken("pict_url").ToString(); Tborder ordermodel = db.Tborder.Find(tempid); ordermodel.GoodsImage = tempstr; db.SaveChanges(); model.GoodsImage = tempstr; } } else { model.GoodsImage = string.Empty; } } else { model.GoodsImage = data[i].GoodsImage; } model.GoodsName = data[i].GoodsName; model.OrderCode = data[i].OrderCode; model.OrderPrice = data[i].OrderPrice; model.OrderTimestr = data[i].OrderTime.ToString(); model.EstimateIncome = data[i].EstimateIncome; model.SettlementTimestr = data[i].SettlementTime.ToString(); tempdata.Add(model); } return(Json(Comm.ToJsonResult("Success", "成功", tempdata), JsonRequestBehavior.AllowGet)); } else { return(Json(Comm.ToJsonResult("Success", "成功", tempdata), JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { return(Json(Comm.ToJsonResult("Error", ex.Message), JsonRequestBehavior.AllowGet)); } }
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); }
//查券 //链接转换 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、链接转换-暂时不实现 }