/// <summary> /// 发布商品 /// taobao.item.add 添加一个商品 /// </summary> /// <param name="product">商品</param> /// <returns>商品编号</returns> public Item PublishGoods(Product product) { _log.LogInfo(Resource.Log_PublishGoodsing.StringFormat(product.Title)); var req = new ItemAddRequest(); Util.CopyModel(product, req); var tContext = InstanceLocator.Current.GetInstance <AuthorizedContext>(); ItemAddResponse response = _client.Execute(req, tContext.SessionKey); if (response.IsError) { var ex = new TopResponseException(response.ErrCode, response.ErrMsg, response.SubErrCode, response.SubErrMsg, response.TopForbiddenFields); _log.LogError(Resource.Log_PublishGoodsFailure, product.Title, ex); throw ex; } Item item = response.Item; _log.LogInfo(Resource.Log_PublishGoodsSuccess, product.Title, item.NumIid); return(item); }
private void ImportItem(Item item) { try { ITopClient client = GetProductTopClient(); ItemAddRequest req = new ItemAddRequest(); req.ApproveStatus = item.ApproveStatus; req.EnlistTime = DateTime.Parse(item.EnlistTime); req.Num = int.Parse(item.Num); req.Price = item.Price; req.Type = item.Type; req.StuffStatus = item.StuffStatus; req.Title = item.Title; req.Desc = item.Desc; req.Cid = item.Cid; req.Location = item.Location; req.AutoRepost = item.AutoRepost; req.PostFee = item.PostFee; req.ExpressFee = item.ExpressFee; req.EmsFee = item.EmsFee; req.OuterId = item.OuterId; req.Props = item.Props; // req.SkuProps = item.SkuList; req.HasShowcase = item.HasShowcase; // req.Image = TestUtils.GetResourceAsFileItem("item.jpg"); Item importedItem = client.Execute(req, new ItemJsonParser(), CurrentSessionKey); } catch (Exception e) { throw e; } }
void SetTaoBaoAddData(ItemAddRequest req, DataRow row) { req.StuffStatus = (row["StuffStatus"] == DBNull.Value) ? "" : ((string)row["StuffStatus"]); req.Cid = new long?((long)row["Cid"]); req.Price = ((decimal)row["SalePrice"]).ToString("F2"); req.Type = "fixed"; req.Num = new long?((long)row["Num"]); req.Title = (string)row["ProTitle"]; req.OuterId = (row["ProductCode"] == DBNull.Value) ? "" : ((string)row["ProductCode"]); req.Desc = (row["Description"] == DBNull.Value) ? "暂无该商品的描述信息" : ((string)row["Description"]); req.LocationState = (string)row["LocationState"]; req.LocationCity = (string)row["LocationCity"]; req.HasShowcase = true; req.HasInvoice = new bool?((bool)row["HasInvoice"]); req.HasWarranty = new bool?((bool)row["HasWarranty"]); req.HasDiscount = new bool?((bool)row["HasDiscount"]); if (row["ImageUrl1"] != DBNull.Value) { string path = (string)row["ImageUrl1"]; path = Globals.ApplicationPath + path; if (File.Exists(Globals.MapPath(path))) { FileItem item = new FileItem(Globals.MapPath(path)); req.Image = item; } } if (row["ValidThru"] != DBNull.Value) { req.ValidThru = new long?((long)row["ValidThru"]); } if (row["ListTime"] != DBNull.Value) { req.ListTime = new DateTime?((DateTime)row["ListTime"]); } if (row["FreightPayer"].ToString() == "seller") { req.FreightPayer = "seller"; } else { req.FreightPayer = "buyer"; req.PostFee = (row["PostFee"] == DBNull.Value) ? "" : ((decimal)row["PostFee"]).ToString("F2"); req.ExpressFee = (row["ExpressFee"] == DBNull.Value) ? "" : ((decimal)row["ExpressFee"]).ToString("F2"); req.EmsFee = (row["EMSFee"] == DBNull.Value) ? "" : ((decimal)row["EMSFee"]).ToString("F2"); } req.Props = (row["PropertyAlias"] == DBNull.Value) ? "" : ((string)row["PropertyAlias"]); req.InputPids = (row["InputPids"] == DBNull.Value) ? "" : ((string)row["InputPids"]); req.InputStr = (row["InputStr"] == DBNull.Value) ? "" : ((string)row["InputStr"]); req.SkuProperties = (row["SkuProperties"] == DBNull.Value) ? "" : ((string)row["SkuProperties"]); req.SkuQuantities = (row["SkuQuantities"] == DBNull.Value) ? "" : ((string)row["SkuQuantities"]); req.SkuPrices = (row["SkuPrices"] == DBNull.Value) ? "" : ((string)row["SkuPrices"]); req.SkuOuterIds = (row["SkuOuterIds"] == DBNull.Value) ? "" : ((string)row["SkuOuterIds"]); req.Lang = "zh_CN"; }
public void TestCopeMode() { Product product = new Product(); product.Desc = "asdf"; product.Num = 22; ItemAddRequest req = new ItemAddRequest(); Util.CopyModel(product, req); Console.WriteLine(req.Desc); Console.WriteLine(req.Num); }
/// <summary> /// 发布商品 /// </summary> /// <param name="product">商品</param> /// <returns>商品编号</returns> public Item PublishGoods(Product product) { ItemAddRequest req = new ItemAddRequest(); Util.CopyModel(product, req); TopContext tContext = InstanceLocator.Current.GetInstance<TopContext>(); ItemAddResponse response = client.Execute(req, tContext.SessionKey); if (response.IsError) throw new TopResponseException(response.ErrCode,response.ErrMsg,response.SubErrCode,response.SubErrMsg,response.TopForbiddenFields); return response.Item; }
/// <summary> /// taobao.item.add /// 添加一个商品 /// </summary> /// <param name="item">参考DataContract.ProductItem</param> /// <returns></returns> public static Item AddItem(ProductItem item) { ITopClient client = TopClientService.GetTopClient(); ItemAddRequest req = new ItemAddRequest(); req.Num = item.Num; req.Price = item.Price; req.Type = item.Type; req.StuffStatus = item.StuffStatus; req.Title = item.Title; req.Desc = item.Desc; req.LocationState = item.LocationState; req.LocationCity = item.LocationCity; req.ApproveStatus = item.ApproveStatus; req.Cid = item.Cid; req.Props = item.Props; req.FreightPayer = item.FreightPayer; req.ValidThru = item.ValidThru; req.HasInvoice = item.HasInvoice; req.HasWarranty = item.HasWarranty; req.HasShowcase = item.HasShowcase; req.SellerCids = item.SellerCids; req.HasDiscount = item.HasDiscount; req.PostFee = item.PostFee; req.ExpressFee = item.ExpressFee; req.EmsFee = item.EmsFee; req.ListTime = item.ListTime; req.Increment = item.Increment; FileItem fItem = new FileItem(item.ImgFilePath); req.Image = fItem; req.PostageId = item.PostageId; req.AuctionPoint = item.AuctionPoint; req.PropertyAlias = item.PropertyAlias; req.InputPids = item.InputPids; req.SkuProperties = item.SkuProperties; req.SkuQuantities = item.SkuQuantities; req.SkuPrices = item.SkuPrices; req.SkuOuterIds = item.SkuOuterIds; req.Lang = item.Lang; req.OuterId = item.OuterId; req.ProductId = item.ProductId; req.PicPath = item.PicPath; req.AutoFill = item.AutoFill; req.InputStr = item.InputStr; req.IsTaobao = item.IsTaobao; req.IsEx = item.IsEx; req.Is3D = item.Is3D; req.SellPromise = item.SellPromise; req.AfterSaleId = item.AfterSaleId; req.CodPostageId = item.CodPostageId; req.IsLightningConsignment = item.IsLightningConsignment; req.Weight = item.Weight; req.IsXinpin = item.IsXinpin; req.SubStock = item.SubStock; req.FoodSecurityPrdLicenseNo = item.FoodSecurityPrdLicenseNo; req.FoodSecurityDesignCode = item.FoodSecurityDesignCode; req.FoodSecurityFactory = item.FoodSecurityFactory; req.FoodSecurityFactorySite = item.FoodSecurityFactorySite; req.FoodSecurityContact = item.FoodSecurityContact; req.FoodSecurityMix = item.FoodSecurityMix; req.FoodSecurityPlanStorage = item.FoodSecurityPlanStorage; req.FoodSecurityPeriod = item.FoodSecurityPeriod; req.FoodSecurityFoodAdditive = item.FoodSecurityFoodAdditive; req.FoodSecuritySupplier = item.FoodSecuritySupplier; req.FoodSecurityProductDateStart = item.FoodSecurityProductDateStart; req.FoodSecurityProductDateEnd = item.FoodSecurityProductDateEnd; req.FoodSecurityStockDateStart = item.FoodSecurityStockDateStart; req.FoodSecurityStockDateEnd = item.FoodSecurityStockDateEnd; req.SkuSpecIds = item.SkuSpecIds; req.ScenicTicketPayWay = item.ScenicTicketPayWay; req.ScenicTicketBookCost = item.ScenicTicketBookCost; req.ItemSize = item.ItemSize; req.ItemWeight = item.ItemWeight; req.ChangeProp = item.ChangeProp; req.SellPoint = item.SellPoint; req.DescModules = item.DescModules; req.FoodSecurityHealthProductNo = item.FoodSecurityHealthProductNo; req.LocalityLifeChooseLogis = item.LocalityLifeChooseLogis; req.LocalityLifeExpirydate = item.LocalityLifeExpirydate; req.LocalityLifeNetworkId = item.LocalityLifeNetworkId; req.LocalityLifeMerchant = item.LocalityLifeMerchant; req.LocalityLifeVerification = item.LocalityLifeVerification; req.LocalityLifeRefundRatio = item.LocalityLifeRefundRatio; req.LocalityLifeOnsaleAutoRefundRatio = item.LocalityLifeOnsaleAutoRefundRatio; req.LocalityLifeRefundmafee = item.LocalityLifeRefundmafee; req.PaimaiInfoMode = item.PaimaiInfoMode; req.PaimaiInfoDeposit = item.PaimaiInfoDeposit; req.PaimaiInfoInterval = item.PaimaiInfoInterval; req.PaimaiInfoReserve = item.PaimaiInfoReserve; req.PaimaiInfoValidHour = item.PaimaiInfoValidHour; req.PaimaiInfoValidMinute = item.PaimaiInfoValidMinute; req.GlobalStockType = item.GlobalStockType; req.GlobalStockCountry = item.GlobalStockCountry; ItemAddResponse response = client.Execute(req, SessionKey); return response.Item; }
/// <summary> /// taobao.item.add /// 添加一个商品 /// </summary> /// <param name="item">参考DataContract.ProductItem</param> /// <returns></returns> public static Item AddItem(TB_Product item) { ITopClient client = TopClientService.GetTopClient(); ItemAddRequest req = new ItemAddRequest(); req.Num = item.Num; req.Price = item.Price.ToString(); req.Type = item.Type; req.StuffStatus = item.StuffStatus; req.Title = item.Title; req.Desc = item.Desc; req.LocationState = item.LocationState; req.LocationCity = item.LocationCity; req.ApproveStatus = item.ApproveStatus; req.Cid = item.Cid; req.Props = item.Props; req.FreightPayer = item.FreightPayer; req.ValidThru = item.ValidThru; req.HasInvoice = item.HasInvoice; req.HasWarranty = item.HasWarranty; req.HasShowcase = item.HasShowcase; req.SellerCids = item.SellerCids; req.HasDiscount = item.HasDiscount; req.PostFee = item.PostFee.ToString(); req.ExpressFee = item.ExpressFee.ToString(); req.EmsFee = item.EmsFee.ToString(); req.ListTime = item.ListTime; req.Increment = item.Increment; FileItem fItem = new FileItem(ConfigurationManager.AppSettings["ImageFolderPath"] + item.ImgFilePath); req.Image = fItem; req.PostageId = item.PostageId; req.AuctionPoint = item.AuctionPoint; req.PropertyAlias = item.PropertyAlias; req.InputPids = item.InputPids; req.SkuProperties = item.SkuProperties; req.SkuQuantities = item.SkuQuantities; req.SkuPrices = item.SkuPrices; req.SkuOuterIds = item.SkuOuterIds; req.Lang = item.Lang; req.OuterId = item.OuterId; req.PicPath = item.PicPath; req.InputStr = item.InputStr; req.IsTaobao = item.IsTaobao; req.IsEx = item.IsEx; req.Is3D = item.Is3D; req.SellPromise = item.SellPromise; req.AfterSaleId = item.AfterSaleId; req.CodPostageId = item.CodPostageId; req.IsLightningConsignment = item.IsLightningConsignment; req.Weight = item.Weight; req.IsXinpin = item.IsXinpin; req.SubStock = item.SubStock; req.DescModules = item.DescModules; req.GlobalStockType = item.GlobalStockType; req.GlobalStockCountry = item.GlobalStockCountry; ItemAddResponse response = client.Execute(req, SessionKey); if (response.IsError) { item.IsUploaded = false; throw new Exception("Error Code: " + response.ErrCode + " Error Message: " + response.ErrMsg); } else { item.IsUploaded = true; } return response.Item; }
public void ProcessRequest(HttpContext context) { string appkey = context.Request.Form["appkey"]; string appsecret = context.Request.Form["appsecret"]; string sessionkey = context.Request.Form["sessionkey"]; string productIds = context.Request.Form["productIds"]; string approve_status = context.Request.Form["approve_status"]; string morepic = context.Request.Form["morepic"]; string repub = context.Request.Form["repub"]; string chkdesc = context.Request.Form["chkdesc"]; string chknormal = context.Request.Form["chknormal"]; string chktitle = context.Request.Form["chktitle"]; if (!string.IsNullOrEmpty(appkey) && !string.IsNullOrEmpty(appsecret)) { this.client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", appkey, appsecret, "json"); } DataTable taobaoProducts = SubSiteProducthelper.GetTaobaoProducts(productIds); if (null != taobaoProducts && taobaoProducts.Rows.Count > 0) { Dictionary<int, long> taobaoReturnProductIds = new Dictionary<int, long>(); StringBuilder builder = new StringBuilder(); string pname = ""; int num = 0; string imgurl = ""; int stock = 0; decimal markprice = 0M; string issuccess = "true"; string msg = ""; string imgmsg = ""; string proTitle = "";// (string)row["ProTitle"]; foreach (DataRow row in taobaoProducts.Rows) { proTitle = (string)row["ProTitle"]; ResponseData(row, out imgurl, out stock, out markprice); if ((row["taobaoproductid"] != DBNull.Value) && (repub.ToLower() == "true")) { ItemUpdateRequest req = new ItemUpdateRequest(); req.NumIid = new long?(Convert.ToInt64(row["taobaoproductid"])); req.ApproveStatus = approve_status; if (!string.IsNullOrEmpty(chknormal) && (chknormal.ToLower() == "true")) { this.SetTaoBaoUpdateData(req, row); } if (!string.IsNullOrEmpty(chktitle) && (chktitle.ToLower() == "true")) { req.Title = (row["ProTitle"] == DBNull.Value) ? "请修改商品标题" : ((string)row["ProTitle"]); } if (!string.IsNullOrEmpty(chkdesc) && (chkdesc.ToLower() == "true")) { req.Desc = (row["Description"] == DBNull.Value) ? "暂无该商品的描述信息" : ((string)row["Description"]); } ItemUpdateResponse response = client.Execute<ItemUpdateResponse>(req, sessionkey); if (response.IsError) { num = (int)row["ProductId"]; pname = string.Format("<a href='{0}' target=_blank>{1} </a>", Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { num }), proTitle); imgurl = string.Format("<a href='{0}' target=_blank><img src={1} /></a>", Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { num }), imgurl); msg = string.Format("商品更新失败<br/>({0})", ":" + response.ErrMsg + ":" + response.SubErrMsg); issuccess = "false"; } else { imgurl = string.Format("<a href='http://item.taobao.com/item.htm?id={0}' target=_blank><img src={1} /></a>", response.Item.NumIid, imgurl); pname = string.Format("<a href='http://item.taobao.com/item.htm?id={0}'>{1}</a>", response.Item.NumIid, proTitle); msg = "商品更新成功"; issuccess = "true"; taobaoReturnProductIds.Add((int)row["ProductId"], response.Item.NumIid); } } else { ItemAddRequest req = new ItemAddRequest(); req.ApproveStatus = approve_status; SetTaoBaoAddData(req, row); ItemAddResponse response2 = client.Execute<ItemAddResponse>(req, sessionkey); if (response2.IsError) { num = (int)row["ProductId"]; pname = string.Format("<a href='{0}' target=_blank>{1} </a>", Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { num }), proTitle); imgurl = string.Format("<a href='{0}' target=_blank><img src={1} /></a>", Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { num }), imgurl); msg = string.Format("发布失败<br/>({0})", response2.ErrMsg + ":" + response2.SubErrMsg); issuccess = "false"; } else { imgurl = string.Format("<a href='http://item.taobao.com/item.htm?id={0}' target=_blank><img src={1} /></a>", response2.Item.NumIid, imgurl); pname = string.Format("<a href='http://item.taobao.com/item.htm?id={0}'>{1}</a>", response2.Item.NumIid, proTitle); msg = "商品发布成功"; issuccess = "true"; taobaoReturnProductIds.Add((int)row["ProductId"], response2.Item.NumIid); if (morepic == "true") { List<TbImage> productsImgs = this.GetProductsImgs(row, response2); StringBuilder builder2 = new StringBuilder(); foreach (TbImage image in productsImgs) { string path = Globals.ApplicationPath + image.Imgpath; if (File.Exists(Globals.MapPath(path))) { FileItem item = new FileItem(Globals.MapPath(path)); ItemImgUploadRequest request = new ItemImgUploadRequest(); request.Image = item; request.NumIid = new long?(image.TbProductId); request.IsMajor = false; ItemImgUploadResponse itemImgUploadResponse = this.client.Execute<ItemImgUploadResponse>(request, sessionkey); if (itemImgUploadResponse.IsError) { builder2.AppendFormat("[\"{0}发布图片错误,错误原因:{1}\"],", proTitle, itemImgUploadResponse.ErrMsg + ";" + itemImgUploadResponse.SubErrMsg); } } } if (builder2.Length > 0) { imgmsg = builder2.ToString().Substring(0, builder2.ToString().Length - 1); } } } } builder.Append(string.Concat(new object[] { "{\"pname\":\"", pname, "\",\"pimg\":\"", imgurl, "\",\"pmarkprice\":\"", markprice.ToString("F2"), "\",\"pstock\":\"", stock, "\",\"issuccess\":\"", issuccess, "\",\"msg\":\"", msg, "\",\"imgmsg\":[", imgmsg, "]}," })); } if (taobaoReturnProductIds.Count > 0) { SubSiteProducthelper.AddTaobaoReturnProductIds(taobaoReturnProductIds, 0); } if (builder.ToString().Length > 0) { builder.Remove(builder.Length - 1, 1); } context.Response.Write("{\"Status\":\"OK\",\"Result\":[" + builder.ToString() + "]}"); context.Response.Flush(); context.Response.End(); } else { context.Response.Write("{\"Status\":\"Error\",\"Result\":\"发布商品到淘宝出错!\"}"); context.Response.Flush(); context.Response.End(); } }
private void PublishProduct() { string authCode = null; if (!GetAuthorizeCode( out authCode)) { MessageBox.Show("没有找到相应的 authCode"); return; } context = TopUtils.GetTopContext(authCode); ITopClient client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", "21479233", "98dd6f00daf3f94322ec1a4ff72370b7"); #region 获取店铺类目 SellercatsListGetRequest reqCats = new SellercatsListGetRequest(); reqCats.Nick = context.UserNick; SellercatsListGetResponse responseCats = client.Execute(reqCats); sellerCats = responseCats.SellerCats; // var cats = responseCats.SellerCats.FirstOrDefault(f => f.Name == ""); //714827841 #endregion ItemAddRequest req = new ItemAddRequest(); req.Num = 30L; req.Price = "2000.07"; req.Type = "fixed"; req.StuffStatus = "new"; req.Title = "美邦男装"; req.Desc = "这是一个好商品"; req.LocationState = "浙江"; req.LocationCity = "杭州"; //req.ApproveStatus = "onsale"; req.Cid = 50000436; // req.Props = "20000:33564;21514:38489"; req.FreightPayer = "buyer"; //req.ValidThru = 7L; req.HasInvoice = false; req.HasWarranty = false; req.HasShowcase = false; req.SellerCids = GetCatsList("T恤 - 长袖T恤;T恤 - 短袖T恤;T恤 - 圆领T恤", "Metersbonwe - 女装"); req.HasDiscount = true; req.PostFee = "15.07"; req.ExpressFee = "15.07"; req.EmsFee = "25.07"; DateTime dateTime = DateTime.Parse("2000-01-01 00:00:00"); req.ListTime = dateTime; req.Increment = "2.50"; FileItem fItem = new FileItem(@"C:\Users\Administrator\Desktop\a.png"); req.Image = fItem; // req.PostageId = 775752L; //req.AuctionPoint = 5L; req.PropertyAlias = "pid:vid:别名;pid1:vid1:别名1"; req.InputPids = "20000"; req.SkuProperties = "pid:vid;pid:vid"; req.SkuQuantities = "2,3,4"; req.SkuPrices = "200.07"; req.SkuOuterIds = "1234,1342"; req.Lang = "zh_CN"; req.OuterId = "12345"; req.ProductId = 123456789L; req.PicPath = "i7/T1rfxpXcVhXXXH9QcZ_033150.jpg"; req.AutoFill = "time_card"; req.InputStr = "耐克;"; req.IsTaobao = true; req.IsEx = true; req.Is3D = true; req.SellPromise = true; req.AfterSaleId = 47758L; req.CodPostageId = 53899L; req.IsLightningConsignment = true; req.Weight = 100L; req.IsXinpin = false; req.SubStock = 1L; req.FoodSecurityPrdLicenseNo = "QS410006010388"; req.FoodSecurityDesignCode = "Q/DHL.001-2008"; req.FoodSecurityFactory = "远东恒天然乳品有限公司"; req.FoodSecurityFactorySite = "台北市仁爱路4段85号"; req.FoodSecurityContact = "00800-021216"; req.FoodSecurityMix = "有机乳糖、有机植物油"; req.FoodSecurityPlanStorage = "常温"; req.FoodSecurityPeriod = "2年"; req.FoodSecurityFoodAdditive = "磷脂 、膨松剂"; req.FoodSecuritySupplier = "深圳岸通商贸有限公司"; req.FoodSecurityProductDateStart = "2012-06-01"; req.FoodSecurityProductDateEnd = "2012-06-10"; req.FoodSecurityStockDateStart = "2012-06-20"; req.FoodSecurityStockDateEnd = "2012-06-30"; req.GlobalStockType = "1"; req.ScenicTicketPayWay = 1L; req.ScenicTicketBookCost = "5.99"; req.ItemSize = "bulk:8"; req.ItemWeight = "10"; req.ChangeProp = "162707:28335:28335,28338"; req.LocalityLifeChooseLogis = "0"; req.LocalityLifeExpirydate = "2012-08-06,2012-08-16"; req.LocalityLifeNetworkId = "5645746"; req.LocalityLifeMerchant = "56879:码商X"; req.LocalityLifeVerification = "101"; req.LocalityLifeRefundRatio = 50L; req.LocalityLifeOnsaleAutoRefundRatio = 80L; req.PaimaiInfoMode = 1L; req.PaimaiInfoDeposit = 20L; req.PaimaiInfoInterval = 5L; req.PaimaiInfoReserve = "11"; req.PaimaiInfoValidHour = 2L; req.PaimaiInfoValidMinute = 22L; ItemAddResponse response = client.Execute(req, context.SessionKey); }
public void ProcessRequest(HttpContext context) { string appkey = context.Request.Form["appkey"]; string appsecret = context.Request.Form["appsecret"]; string sessionkey = context.Request.Form["sessionkey"]; string productIds = context.Request.Form["productIds"]; string approve_status = context.Request.Form["approve_status"]; string morepic = context.Request.Form["morepic"]; string repub = context.Request.Form["repub"]; string chkdesc = context.Request.Form["chkdesc"]; string chknormal = context.Request.Form["chknormal"]; string chktitle = context.Request.Form["chktitle"]; if (!string.IsNullOrEmpty(appkey) && !string.IsNullOrEmpty(appsecret)) { this.client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", appkey, appsecret, "json"); } DataTable taobaoProducts = SubSiteProducthelper.GetTaobaoProducts(productIds); if (null != taobaoProducts && taobaoProducts.Rows.Count > 0) { Dictionary <int, long> taobaoReturnProductIds = new Dictionary <int, long>(); StringBuilder builder = new StringBuilder(); string pname = ""; int num = 0; string imgurl = ""; int stock = 0; decimal markprice = 0M; string issuccess = "true"; string msg = ""; string imgmsg = ""; string proTitle = "";// (string)row["ProTitle"]; foreach (DataRow row in taobaoProducts.Rows) { proTitle = (string)row["ProTitle"]; ResponseData(row, out imgurl, out stock, out markprice); if ((row["taobaoproductid"] != DBNull.Value) && (repub.ToLower() == "true")) { ItemUpdateRequest req = new ItemUpdateRequest(); req.NumIid = new long?(Convert.ToInt64(row["taobaoproductid"])); req.ApproveStatus = approve_status; if (!string.IsNullOrEmpty(chknormal) && (chknormal.ToLower() == "true")) { this.SetTaoBaoUpdateData(req, row); } if (!string.IsNullOrEmpty(chktitle) && (chktitle.ToLower() == "true")) { req.Title = (row["ProTitle"] == DBNull.Value) ? "请修改商品标题" : ((string)row["ProTitle"]); } if (!string.IsNullOrEmpty(chkdesc) && (chkdesc.ToLower() == "true")) { req.Desc = (row["Description"] == DBNull.Value) ? "暂无该商品的描述信息" : ((string)row["Description"]); } ItemUpdateResponse response = client.Execute <ItemUpdateResponse>(req, sessionkey); if (response.IsError) { num = (int)row["ProductId"]; pname = string.Format("<a href='{0}' target=_blank>{1} </a>", Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { num }), proTitle); imgurl = string.Format("<a href='{0}' target=_blank><img src={1} /></a>", Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { num }), imgurl); msg = string.Format("商品更新失败<br/>({0})", ":" + response.ErrMsg + ":" + response.SubErrMsg); issuccess = "false"; } else { imgurl = string.Format("<a href='http://item.taobao.com/item.htm?id={0}' target=_blank><img src={1} /></a>", response.Item.NumIid, imgurl); pname = string.Format("<a href='http://item.taobao.com/item.htm?id={0}'>{1}</a>", response.Item.NumIid, proTitle); msg = "商品更新成功"; issuccess = "true"; taobaoReturnProductIds.Add((int)row["ProductId"], response.Item.NumIid); } } else { ItemAddRequest req = new ItemAddRequest(); req.ApproveStatus = approve_status; SetTaoBaoAddData(req, row); ItemAddResponse response2 = client.Execute <ItemAddResponse>(req, sessionkey); if (response2.IsError) { num = (int)row["ProductId"]; pname = string.Format("<a href='{0}' target=_blank>{1} </a>", Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { num }), proTitle); imgurl = string.Format("<a href='{0}' target=_blank><img src={1} /></a>", Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { num }), imgurl); msg = string.Format("发布失败<br/>({0})", response2.ErrMsg + ":" + response2.SubErrMsg); issuccess = "false"; } else { imgurl = string.Format("<a href='http://item.taobao.com/item.htm?id={0}' target=_blank><img src={1} /></a>", response2.Item.NumIid, imgurl); pname = string.Format("<a href='http://item.taobao.com/item.htm?id={0}'>{1}</a>", response2.Item.NumIid, proTitle); msg = "商品发布成功"; issuccess = "true"; taobaoReturnProductIds.Add((int)row["ProductId"], response2.Item.NumIid); if (morepic == "true") { List <TbImage> productsImgs = this.GetProductsImgs(row, response2); StringBuilder builder2 = new StringBuilder(); foreach (TbImage image in productsImgs) { string path = Globals.ApplicationPath + image.Imgpath; if (File.Exists(Globals.MapPath(path))) { FileItem item = new FileItem(Globals.MapPath(path)); ItemImgUploadRequest request = new ItemImgUploadRequest(); request.Image = item; request.NumIid = new long?(image.TbProductId); request.IsMajor = false; ItemImgUploadResponse itemImgUploadResponse = this.client.Execute <ItemImgUploadResponse>(request, sessionkey); if (itemImgUploadResponse.IsError) { builder2.AppendFormat("[\"{0}发布图片错误,错误原因:{1}\"],", proTitle, itemImgUploadResponse.ErrMsg + ";" + itemImgUploadResponse.SubErrMsg); } } } if (builder2.Length > 0) { imgmsg = builder2.ToString().Substring(0, builder2.ToString().Length - 1); } } } } builder.Append(string.Concat(new object[] { "{\"pname\":\"", pname, "\",\"pimg\":\"", imgurl, "\",\"pmarkprice\":\"", markprice.ToString("F2"), "\",\"pstock\":\"", stock, "\",\"issuccess\":\"", issuccess, "\",\"msg\":\"", msg, "\",\"imgmsg\":[", imgmsg, "]}," })); } if (taobaoReturnProductIds.Count > 0) { SubSiteProducthelper.AddTaobaoReturnProductIds(taobaoReturnProductIds, 0); } if (builder.ToString().Length > 0) { builder.Remove(builder.Length - 1, 1); } context.Response.Write("{\"Status\":\"OK\",\"Result\":[" + builder.ToString() + "]}"); context.Response.Flush(); context.Response.End(); } else { context.Response.Write("{\"Status\":\"Error\",\"Result\":\"发布商品到淘宝出错!\"}"); context.Response.Flush(); context.Response.End(); } }
/// <summary> /// 添加商品数据 /// </summary> /// <param name="sessionKey"></param> /// <param name="goods"></param> /// <param name="ErrorMsg"></param> /// <returns></returns> internal string AddGoods(string sessionKey, ItemAdd goods, out string ErrorMsg) { ErrorMsg = null; ITopClient client = new DefaultTopClient(StaticSystemConfig.soft.ApiURL, StaticSystemConfig.soft.AppKey, StaticSystemConfig.soft.AppSecret, "json"); ItemAddRequest req = new ItemAddRequest(); #region 将页面数据填充到request中 if (goods.Type != null) { req.Type = goods.Type; } else { ErrorMsg += "发布商品类型不能为空;"; } if (goods.Cid != null) { req.Cid = goods.Cid; } else { ErrorMsg += "商品类目不能为空;"; return(null); } if (goods.Props != null) { req.Props = goods.Props; } if (goods.Num != null) { req.Num = goods.Num; } else { ErrorMsg += "商品数量不能为空;"; return(null); } if (goods.StuffStatus != null) { req.StuffStatus = goods.StuffStatus; } else { ErrorMsg += "商品新旧程度不能为空;"; return(null); } if (goods.Price != null) { req.Price = goods.Price; } else { ErrorMsg += "商品价格不能为空;"; return(null); } if (goods.Title != null) { req.Title = goods.Title; } else { ErrorMsg += "商品标题不能为空;"; return(null); } if (goods.Desc != null) { req.Desc = goods.Desc; } else { ErrorMsg += "商品描述不能为空;"; return(null); } if (goods.LocationState != null) { req.LocationState = goods.LocationState; } else { ErrorMsg += "商品所在地省份不能为空;"; return(null); } if (goods.LocationCity != null) { req.LocationCity = goods.LocationCity; } else { ErrorMsg += "商品所在地城市不能为空;"; return(null); } if (goods.PostFee != null) { req.PostFee = goods.PostFee; } if (goods.ExpressFee != null) { req.ExpressFee = goods.ExpressFee; } if (goods.EmsFee != null) { req.EmsFee = goods.EmsFee; } if (goods.ListTime != null) { req.ListTime = goods.ListTime; } if (goods.Cid != null) { req.Increment = goods.Increment; } if (goods.Image != null) { //括号中中填文件路径 FileItem fItem = new FileItem(goods.Image[0].ToString()); req.Image = fItem; } if (goods.StuffStatus != null) { req.StuffStatus = goods.StuffStatus; } if (goods.AuctionPoint != null) { req.AuctionPoint = goods.AuctionPoint; } if (goods.PropertyAlias != null) { req.PropertyAlias = goods.PropertyAlias; } if (goods.InputPids != null) { req.InputPids = goods.InputPids; } if (goods.SkuQuantities != null) { req.SkuQuantities = goods.SkuQuantities; } if (goods.SkuPrices != null) { req.SkuPrices = goods.SkuPrices; } if (goods.SkuProperties != null) { req.SkuProperties = "pid:vid;pid:vid"; } if (goods.SellerCids != null) { req.SellerCids = goods.SellerCids; } if (goods.PostageId != null) { req.PostageId = goods.PostageId; } if (goods.OuterId != null) { req.OuterId = goods.OuterId; } if (goods.ProductId != null) { req.ProductId = goods.ProductId; } if (goods.PicPath != null) { req.PicPath = goods.PicPath; } if (goods.AutoFill != null) { req.AutoFill = goods.AutoFill; } if (goods.SkuOuterIds != null) { req.SkuOuterIds = goods.SkuOuterIds; } if (goods.IsTaobao != null) { req.IsTaobao = goods.IsTaobao; } if (goods.IsEx != null) { req.IsEx = goods.IsEx; } if (goods.Is3D != null) { req.Is3D = goods.Is3D; } if (goods.InputStr != null) { req.InputStr = goods.InputStr; } if (goods.Lang != null) { req.Lang = goods.Lang; } if (goods.HasDiscount != null) { req.HasDiscount = goods.HasDiscount; } if (goods.HasShowcase != null) { req.HasShowcase = goods.HasShowcase; } if (goods.ApproveStatus != null) { req.ApproveStatus = goods.ApproveStatus; } if (goods.FreightPayer != null) { req.FreightPayer = goods.FreightPayer; } if (goods.ValidThru != null) { req.ValidThru = goods.ValidThru; } if (goods.HasInvoice != null) { req.HasInvoice = goods.HasInvoice; } if (goods.HasWarranty != null) { req.HasWarranty = goods.HasWarranty; } if (goods.AfterSaleId != null) { req.AfterSaleId = goods.AfterSaleId; } if (goods.SellPromise != null) { req.SellPromise = goods.SellPromise; } if (goods.CodPostageId != null) { req.CodPostageId = goods.CodPostageId; } if (goods.IsLightningConsignment != null) { req.IsLightningConsignment = goods.IsLightningConsignment; } if (goods.Weight != null) { req.Weight = goods.Weight; } if (goods.IsXinpin != null) { req.IsXinpin = goods.IsXinpin; } if (goods.SubStock != null) { req.SubStock = goods.SubStock; } if (goods.FoodSecurityPrdLicenseNo != null) { req.FoodSecurityPrdLicenseNo = goods.FoodSecurityPrdLicenseNo; } if (goods.FoodSecurityDesignCode != null) { req.FoodSecurityDesignCode = goods.FoodSecurityDesignCode; } if (goods.FoodSecurityFactory != null) { req.FoodSecurityFactory = goods.FoodSecurityFactory; } if (goods.FoodSecurityFactorySite != null) { req.FoodSecurityFactorySite = goods.FoodSecurityFactorySite; } if (goods.FoodSecurityContact != null) { req.FoodSecurityContact = goods.FoodSecurityContact; } if (goods.FoodSecurityMix != null) { req.FoodSecurityMix = goods.FoodSecurityMix; } if (goods.FoodSecurityPlanStorage != null) { req.FoodSecurityPlanStorage = goods.FoodSecurityPlanStorage; } if (goods.FoodSecurityPeriod != null) { req.FoodSecurityPeriod = goods.FoodSecurityPeriod; } if (goods.FoodSecurityFoodAdditive != null) { req.FoodSecurityFoodAdditive = goods.FoodSecurityFoodAdditive; } if (goods.FoodSecuritySupplier != null) { req.FoodSecuritySupplier = goods.FoodSecuritySupplier; } if (goods.FoodSecurityProductDateStart != null) { req.FoodSecurityProductDateStart = goods.FoodSecurityProductDateStart; } if (goods.FoodSecurityProductDateEnd != null) { req.FoodSecurityProductDateEnd = goods.FoodSecurityProductDateEnd; } if (goods.FoodSecurityStockDateStart != null) { req.FoodSecurityStockDateStart = goods.FoodSecurityStockDateStart; } if (goods.FoodSecurityStockDateEnd != null) { req.FoodSecurityStockDateEnd = goods.FoodSecurityStockDateEnd; } if (goods.SkuSpecIds != null) { req.SkuSpecIds = goods.SkuSpecIds; } if (goods.ItemSize != null) { req.ItemSize = goods.ItemSize; } if (goods.ItemWeight != null) { req.ItemWeight = goods.ItemWeight; } if (goods.ChangeProp != null) { req.ChangeProp = goods.ChangeProp; } if (goods.SellPoint != null) { req.SellPoint = goods.SellPoint; } if (goods.DescModules != null) { req.DescModules = goods.DescModules; } if (goods.FoodSecurityHealthProductNo != null) { req.FoodSecurityHealthProductNo = goods.FoodSecurityHealthProductNo; } if (goods.Barcode != null) { req.Barcode = goods.Barcode; } if (goods.SkuBarcode != null) { req.SkuBarcode = goods.SkuBarcode; } if (goods.Newprepay != null) { req.Newprepay = goods.Newprepay; } if (goods.IsOffline != null) { req.IsOffline = goods.IsOffline; } if (goods.SkuHdLength != null) { req.SkuHdLength = goods.SkuHdLength; } if (goods.SkuHdHeight != null) { req.SkuHdHeight = goods.SkuHdHeight; } if (goods.SkuHdLampQuantity != null) { req.SkuHdLampQuantity = goods.SkuHdLampQuantity; } if (goods.Qualification != null) { req.Qualification = goods.Qualification; } if (goods.O2oBindService != null) { req.O2oBindService = goods.O2oBindService; } if (goods.LocalityLifeExpirydate != null) { req.LocalityLifeExpirydate = goods.LocalityLifeExpirydate; } if (goods.LocalityLifeNetworkId != null) { req.LocalityLifeNetworkId = goods.LocalityLifeNetworkId; } if (goods.LocalityLifeMerchant != null) { req.LocalityLifeMerchant = goods.LocalityLifeMerchant; } if (goods.LocalityLifeVerification != null) { req.LocalityLifeVerification = goods.LocalityLifeVerification; } if (goods.LocalityLifeRefundRatio != null) { req.LocalityLifeRefundRatio = goods.LocalityLifeRefundRatio; } if (goods.LocalityLifeChooseLogis != null) { req.LocalityLifeChooseLogis = goods.LocalityLifeChooseLogis; } if (goods.LocalityLifeOnsaleAutoRefundRatio != null) { req.LocalityLifeOnsaleAutoRefundRatio = goods.LocalityLifeOnsaleAutoRefundRatio; } if (goods.LocalityLifeRefundmafee != null) { req.LocalityLifeRefundmafee = goods.LocalityLifeRefundmafee; } if (goods.ScenicTicketPayWay != null) { req.ScenicTicketPayWay = goods.ScenicTicketPayWay; } if (goods.ScenicTicketBookCost != null) { req.ScenicTicketBookCost = goods.ScenicTicketBookCost; } if (goods.PaimaiInfoMode != null) { req.PaimaiInfoMode = goods.PaimaiInfoMode; } if (goods.PaimaiInfoDeposit != null) { req.PaimaiInfoDeposit = goods.PaimaiInfoDeposit; } if (goods.PaimaiInfoInterval != null) { req.PaimaiInfoInterval = goods.PaimaiInfoInterval; } if (goods.PaimaiInfoReserve != null) { req.PaimaiInfoReserve = goods.PaimaiInfoReserve; } if (goods.PaimaiInfoValidHour != null) { req.PaimaiInfoValidHour = goods.PaimaiInfoValidHour; } if (goods.PaimaiInfoValidMinute != null) { req.PaimaiInfoValidMinute = goods.PaimaiInfoValidMinute; } if (goods.GlobalStockType != null) { req.GlobalStockType = goods.GlobalStockType; } if (goods.GlobalStockCountry != null) { req.GlobalStockCountry = goods.GlobalStockCountry; } #endregion ItemAddResponse response = client.Execute(req, sessionKey); if (!response.IsError) { string Result = response.Item.NumIid.ToString(); return(Result); } else { ErrorMsg = response.SubErrMsg; return(null); } }
/// <summary> /// 发布商品 /// taobao.item.add 添加一个商品 /// </summary> /// <param name="product">商品</param> /// <returns>商品编号</returns> public Item PublishGoods(Product product) { _log.LogInfo(Resource.Log_PublishGoodsing.StringFormat(product.Title)); var req = new ItemAddRequest(); Util.CopyModel(product, req); var tContext = InstanceLocator.Current.GetInstance<AuthorizedContext>(); ItemAddResponse response = _client.Execute(req, tContext.SessionKey); if (response.IsError) { var ex = new TopResponseException(response.ErrCode, response.ErrMsg, response.SubErrCode, response.SubErrMsg, response.TopForbiddenFields); _log.LogError(Resource.Log_PublishGoodsFailure, product.Title, ex); throw ex; } Item item = response.Item; _log.LogInfo(Resource.Log_PublishGoodsSuccess, product.Title, item.NumIid); return item; }