Пример #1
0
 /// <summary>
 /// 验证上传文件的最大字节长度。
 /// </summary>
 /// <param name="name">参数名</param>
 /// <param name="value">参数值</param>
 /// <param name="maxLength">最大长度</param>
 public static void ValidateMaxLength(string name, FileItem value, int maxLength)
 {
     if (value != null && value.GetContent() != null && value.GetContent().Length > maxLength)
     {
         throw new TopException(ERR_CODE_PARAM_INVALID, string.Format(ERR_MSG_PARAM_INVALID, name));
     }
 }
Пример #2
0
        public static bool reUploadImage(Picture picture, string AppKey, string AppSecret, string SessionKey, StreamWriter MovePicLogWriter)
        {
            int tryCount = 0;
            while (true)
            {
                if (tryCount < 3)
                {
                    tryCount++;
                }
                else
                {
                    break;
                }
                try
                {
                    ITopClient client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", AppKey, AppSecret);
                    Console.WriteLine("重新上传图片:" + picture.PicturePath);
                    MovePicLogWriter.WriteLine("重新上传图片:" + picture.PicturePath);
                    HttpWebResponse resp = (HttpWebResponse)WebRequest.Create(picture.PicturePath).GetResponse();
                    if (resp.StatusCode == HttpStatusCode.OK)
                    {
                        Stream sm = resp.GetResponseStream();
                        MemoryStream ms = new MemoryStream();
                        byte[] buffer = new byte[4096];
                        int len;
                        len = sm.Read(buffer, 0, 4096);
                        while (len > 0)
                        {
                            ms.Write(buffer, 0, len);
                            len = sm.Read(buffer, 0, 4096);
                        }
                        byte[] imageBuffer = ms.GetBuffer();

                        PictureReplaceRequest pictureReplaceRequest = new PictureReplaceRequest();
                        pictureReplaceRequest.PictureId = picture.PictureId;
                        string fileName = System.DateTime.Now.ToString("yyyyMMddHH:mm:ss");
                        FileItem fItem = new FileItem(fileName, imageBuffer);
                        pictureReplaceRequest.ImageData = fItem;
                        PictureReplaceResponse pictureReplaceResponse = client.Execute(pictureReplaceRequest, SessionKey);
                        if (pictureReplaceResponse != null)
                        {
                            return pictureReplaceResponse.Done;
                        }
                        Console.WriteLine("已重新上传");
                        MovePicLogWriter.WriteLine("已重新上传");
                        break;
                    }
                }
                catch (System.Net.WebException e)
                {
                    Console.WriteLine("异常:" + e.Status + " " + e.Message);
                    MovePicLogWriter.WriteLine("异常:" + e.Status + " " + e.Message);
                }
                Thread.Sleep(5000);
            }
            return false;
        }
Пример #3
0
        /// <summary>
        /// 更新和添加销售商品图片
        /// </summary>
        /// <param name="numId">商品编号</param>
        /// <param name="properties">销售属性</param>
        /// <param name="imgPath">本地图片路径</param>
        /// <returns></returns>
        public PropImg UploadItemPropimg(long numId, string properties,string imgPath)
        {
            #region validation

            if (numId <= 0 || string.IsNullOrEmpty(properties) || string.IsNullOrEmpty(imgPath))
                throw new Exception(string.Format(Resource.ExceptionTemplate_MethedParameterIsNullorEmpty, new System.Diagnostics.StackTrace().ToString()));

            #endregion

            ItemPropimgUploadRequest req = new ItemPropimgUploadRequest();
            req.NumIid = numId;
            FileItem fItem = new FileItem(imgPath);
            req.Image = fItem;
            req.Properties = properties;
            TopContext tContext = InstanceLocator.Current.GetInstance<TopContext>();
            ItemPropimgUploadResponse response = client.Execute(req, tContext.SessionKey);

            if (response.IsError)
                throw new TopResponseException(response.ErrCode, response.ErrMsg, response.SubErrCode, response.SubErrMsg, response.TopForbiddenFields);

            return response.PropImg;
        }
Пример #4
0
        public static string uploadImage(string image, string AppKey, string AppSecret, string SessionKey, StreamWriter MovePicLogWriter)
        {
            Console.WriteLine("上传网络图片:" + image);
            MovePicLogWriter.WriteLine("上传网络图片:" + image);
            int tryCount = 0;
            while (true)
            {
                if (tryCount < 3)
                {
                    tryCount++;
                    if (tryCount > 1)
                    {
                        Console.WriteLine("重试上传图片");
                        MovePicLogWriter.WriteLine("重试上传图片");
                    }
                }
                else
                {
                    break;
                }
                try
                {
                    ITopClient client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", AppKey, AppSecret);
                    HttpWebResponse resp = (HttpWebResponse)WebRequest.Create(image).GetResponse();
                    Console.WriteLine("获取图片返回状态码:" + resp.StatusCode);
                    MovePicLogWriter.WriteLine("获取图片返回状态码:" + resp.StatusCode);
                    if (resp.StatusCode == HttpStatusCode.OK)
                    {
                        Stream sm = resp.GetResponseStream();
                        MemoryStream ms = new MemoryStream();
                        byte[] buffer = new byte[4096];
                        int len;
                        len = sm.Read(buffer, 0, 4096);
                        while (len > 0)
                        {
                            ms.Write(buffer, 0, len);
                            len = sm.Read(buffer, 0, 4096);
                        }
                        byte[] imageBuffer = ms.GetBuffer();

                        ms.Close();
                        sm.Close();

                        PictureUploadRequest req = new PictureUploadRequest();
                        req.PictureCategoryId = 0L;
                        string fileName = System.DateTime.Now.ToString("yyyyMMddHH:mm:ss");
                        FileItem fItem = new FileItem(fileName, imageBuffer);
                        req.Img = fItem;
                        req.ImageInputTitle = fileName;
                        PictureUploadResponse response = client.Execute(req, SessionKey);
                        if (response != null && response.Picture != null)
                        {
                            Console.WriteLine("上传完成 " + response.Picture.PicturePath);
                            MovePicLogWriter.WriteLine("上传完成 " + response.Picture.PicturePath);
                            return response.Picture.PicturePath;
                        }
                    }
                }
                catch (System.Net.WebException e)
                {
                    Console.WriteLine("异常:" + e.Status + " " + e.Message);
                    MovePicLogWriter.WriteLine("异常:" + e.Status + " " + e.Message);
                }
                Thread.Sleep(5000);
            }
            return "";
        }
 /// <summary>
 /// taobao.item.img.upload
 /// 添加商品图片
 /// </summary>
 /// <param name="id">商品图片id(如果是更新图片,则需要传该参数) </param>
 /// <param name="numiid">必填 商品数字ID,该参数必须 </param>
 /// <param name="position">图片序号 </param>
 /// <param name="imgfilepath">上传的图片路径 支持的文件类型:gif,jpg,jpeg,png </param>
 /// <param name="ismajor">是否将该图片设为主图,可选值:true,false;默认值:false</param>
 /// <returns></returns>
 public static ItemImg UploadProductImg(long? id, long? numiid, long? position, string imgfilepath, bool? ismajor)
 {
     ITopClient client = TopClientService.GetTopClient();
     ItemImgUploadRequest req = new ItemImgUploadRequest();
     req.Id = id;
     req.NumIid = numiid;
     req.Position = position;
     FileItem fItem = new FileItem(imgfilepath);
     req.Image = fItem;
     req.IsMajor = ismajor;
     ItemImgUploadResponse response = client.Execute(req, SessionKey);
     return response.ItemImg;
 }
 /// <summary>
 /// taobao.item.update
 /// 更新商品信息
 /// </summary>
 /// <param name="item">参考DataContract.ProductItem</param>
 /// <returns></returns>
 public static Item UpdateItem(ProductItem item)
 {
     ITopClient client = TopClientService.GetTopClient();
     ItemUpdateRequest req = new ItemUpdateRequest();
     req.NumIid = item.NumIid;
     req.Cid = item.Cid;
     req.Props = item.Props;
     req.Num = item.Num;
     req.Price = item.Price;
     req.Title = item.Title;
     req.Desc = item.Desc;
     req.LocationState = item.LocationState;
     req.LocationCity = item.LocationCity;
     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.StuffStatus = item.StuffStatus;
     req.AuctionPoint = item.AuctionPoint;
     req.PropertyAlias = item.PropertyAlias;
     req.InputPids = item.InputPids;
     req.SkuQuantities = item.SkuQuantities;
     req.SkuPrices = item.SkuPrices;
     req.SkuProperties = item.SkuProperties;
     req.SellerCids = item.SellerCids;
     req.PostageId = item.PostageId;
     req.OuterId = item.OuterId;
     req.ProductId = item.ProductId;
     req.PicPath = item.PicPath;
     req.AutoFill = item.AutoFill;
     req.SkuOuterIds = item.SkuOuterIds;
     req.IsTaobao = item.IsTaobao;
     req.IsEx = item.IsEx;
     req.Is3D = item.Is3D;
     req.IsReplaceSku = item.IsReplaceSku;
     req.InputStr = item.InputStr;
     req.Lang = item.Lang;
     req.HasDiscount = item.HasDiscount;
     req.HasShowcase = item.HasShowcase;
     req.ApproveStatus = item.ApproveStatus;
     req.FreightPayer = item.FreightPayer;
     req.ValidThru = item.ValidThru;
     req.HasInvoice = item.HasInvoice;
     req.HasWarranty = item.HasWarranty;
     req.AfterSaleId = item.AfterSaleId;
     req.SellPromise = item.SellPromise;
     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.ItemSize = item.ItemSize;
     req.ItemWeight = item.ItemWeight;
     req.ChangeProp = item.ChangeProp;
     req.SellPoint = item.SellPoint;
     req.DescModules = item.DescModules;
     req.FoodSecurityHealthProductNo = item.FoodSecurityHealthProductNo;
     req.EmptyFields = item.EmptyFields;
     req.LocalityLifeExpirydate = item.LocalityLifeExpirydate;
     req.LocalityLifeNetworkId = item.LocalityLifeNetworkId;
     req.LocalityLifeMerchant = item.LocalityLifeMerchant;
     req.LocalityLifeVerification = item.LocalityLifeVerification;
     req.LocalityLifeRefundRatio = item.LocalityLifeRefundRatio;
     req.LocalityLifeChooseLogis = item.LocalityLifeChooseLogis;
     req.LocalityLifeOnsaleAutoRefundRatio = item.LocalityLifeOnsaleAutoRefundRatio;
     req.LocalityLifeRefundmafee = item.LocalityLifeRefundmafee;
     req.ScenicTicketPayWay = item.ScenicTicketPayWay;
     req.ScenicTicketBookCost = item.ScenicTicketBookCost;
     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;
     ItemUpdateResponse response = client.Execute(req, SessionKey);
     return response.Item;
 }
 /// <summary>
 /// taobao.product.add
 /// 上传一个产品,不包括产品非主图和属性图片(B商家专用)
 /// </summary>
 /// <param name="cid">必填 商品类目ID.调用taobao.itemcats.get获取;注意:必须是叶子类目 id. </param>
 /// <param name="imagefilepath">必填 产品主图片,本地文件路径 支持的文件类型:gif,jpg,png,jpeg</param>
 /// <param name="outerid">外部产品ID </param>
 /// <param name="props">属性,属性值的组合.格式:pid:vid;pid:vid;</param>
 /// <param name="binds">非关键属性结构:pid:vid;pid:vid. 最大支持512字节</param>
 /// <param name="saleprops">销售属性结构:pid:vid;pid:vid</param>
 /// <param name="customerprops">用户自定义属性,结构:pid1:value1;pid2:value2</param>
 /// <param name="price">产品市场价.精确到2位小数;单位为元.如:200.07</param>
 /// <param name="name">产品名称,最大30个字符</param>
 /// <param name="desc">产品描述.最大不超过25000个字符 </param>
 /// <param name="major">是不是主图 默认true</param>
 /// <param name="markettime">上市时间。目前只支持鞋城类目传入此参数</param>
 /// <param name="propertyalias"销售属性值别名。格式为pid1:vid1:alias1;pid1:vid2:alia2。只有少数销售属性值支持传入别名,比如颜色和尺寸></param>
 /// <param name="pakinglist">包装清单。注意,在管控类目下,包装清单不能为空,同时保证清单的格式为: 名称:数字;名称:数字; 其中,名称不能违禁、不能超过60字符,数字不能超过999 </param>
 /// <param name="extraingo">存放产品扩展信息,由List(ProductExtraInfo)转化成jsonArray存入. </param>
 /// <param name="markid">市场ID,1为新增C2C市场的产品信息, 2为新增B2C市场的产品信息。 不填写此值则C用户新增B2C市场的产品信息,B用户新增B2C市场的产品信息。</param>
 /// <param name="sellpt">商品卖点描述,长度限制为20个汉字 </param>
 /// <returns></returns>
 public static Product AddProduct(long? cid, string imagefilepath, string outerid, string props, string binds, string saleprops, string customerprops,
     string price, string name, string desc, bool? major, DateTime markettime, string propertyalias,
     string pakinglist, string extraingo, string markid, string sellpt)
 {
     ITopClient client = TopClientService.GetTopClient();
     ProductAddRequest req = new ProductAddRequest();
     req.Cid = cid;
     FileItem fItem = new FileItem(imagefilepath);
     req.Image = fItem;
     req.OuterId = outerid;
     req.Props = props;
     req.Binds = binds;
     req.SaleProps = saleprops;
     req.CustomerProps = customerprops;
     req.Price = price;
     req.Name = name;
     req.Desc = desc;
     req.Major = major;
     req.MarketTime = markettime;
     req.PropertyAlias = propertyalias;
     req.PackingList = pakinglist;
     req.ExtraInfo = extraingo;
     req.MarketId = markid;
     req.SellPt = sellpt;
     ProductAddResponse response = client.Execute(req, SessionKey);
     return response.Product;
 }
 /// <summary>
 /// 上传产品颜色分类图片
 /// </summary>
 /// <param name="productID">产品id</param>
 /// <param name="imgPath">图片路径</param>
 /// <param name="fields">属性名:属性值</param>
 public static void UploadProductProImg(long productID, string imgPath, string fields)
 {
     ITopClient client = TopClientService.GetTopClient();
     ProductPropimgUploadRequest req = new ProductPropimgUploadRequest();
     req.ProductId = productID;
     req.Props = fields;
     FileItem fItem = new FileItem(imgPath);
     req.Image = fItem;
     req.Position = 1L;
     ProductPropimgUploadResponse response = client.Execute(req, SessionKey);
 }
 public static PropImg UploadItemPropImg(long numiid, string sku, string imgPath)
 {
     ITopClient client = TopClientService.GetTopClient();
     ItemPropimgUploadRequest req = new ItemPropimgUploadRequest();
     req.NumIid = numiid;
     req.Properties = sku;
     FileItem fItem = new FileItem(imgPath);
     req.Image = fItem;
     ItemPropimgUploadResponse response = client.Execute(req, SessionKey);
     return response.PropImg;
 }
Пример #10
0
        /// <summary>
        ///     更新和添加销售商品图片
        /// taobao.item.propimg.upload 添加或修改属性图片 
        /// </summary>
        /// <param name="numId">商品编号</param>
        /// <param name="properties">销售属性</param>
        /// <param name="urlImg">网上的图片地址</param>
        /// <returns></returns>
        public PropImg UploadItemPropimg(long numId, string properties, Uri urlImg)
        {
            int len = urlImg.Segments.Length;
            string fileName = len > 0
                                  ? urlImg.Segments[len - 1]
                                  : "{0}-{1}.jpg".StringFormat(numId.ToString(CultureInfo.InvariantCulture), properties);

              /*  Bitmap watermark = imageWatermark.CreateWatermark(
               (Bitmap)imageWatermark.SetByteToImage(SysUtils.GetImgByte(urlImg.ToString())),
               SysConst.TextWatermark,
               ImageWatermark.WatermarkPosition.RigthBottom,
               3);*/
            Bitmap watermark = SetTextAndIconWatermark(urlImg.ToString(), false);

            var fItem = new FileItem(fileName, ImageHelper.SetBitmapToBytes(watermark, ImageFormat.Jpeg));

            //            var fItem = new FileItem(fileName, SysUtils.GetImgByte(urlImg.ToString()));
            return UploadItemPropimgInternal(numId, properties, fItem);
        }
Пример #11
0
        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();
            }
        }
Пример #12
0
 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";
 }
Пример #13
0
        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);
        }
Пример #14
0
        /// <summary>
        ///     更新和添加销售商品图片
        /// taobao.item.propimg.upload 添加或修改属性图片 
        /// </summary>
        /// <param name="numId">商品编号</param>
        /// <param name="properties">销售属性</param>
        /// <param name="imgPath">本地图片路径</param>
        /// <returns></returns>
        public PropImg UploadItemPropimg(long numId, string properties, string imgPath)
        {
            #region validation

            if (numId <= 0 || string.IsNullOrEmpty(properties) || string.IsNullOrEmpty(imgPath))
                throw new Exception((Resource.ExceptionTemplate_MethedParameterIsNullorEmpty.StringFormat(
                    new StackTrace())));

            #endregion

             Bitmap watermark = imageWatermark.CreateWatermark(
               (Bitmap)ImageHelper.SetByteToImage(FileHelper.ReadFile(imgPath)),
               SysConst.TextWatermark,
               ImageWatermark.WatermarkPosition.RigthBottom,
               3);

            var fItem = new FileItem("{0}-{1}.jpg".StringFormat(numId.ToString(CultureInfo.InvariantCulture), properties),ImageHelper.SetBitmapToBytes(watermark,ImageFormat.Jpeg));

            return UploadItemPropimgInternal(numId, properties, fItem);
        }
Пример #15
0
 public static string uploadLocalImage(string image, string AppKey, string AppSecret, string SessionKey, StreamWriter MovePicLogWriter)
 {
     int tryCount = 0;
     while (true)
     {
         if (tryCount < 3)
         {
             tryCount++;
             if (tryCount > 1)
             {
                 Console.WriteLine("重试上传图片");
                 MovePicLogWriter.WriteLine("重试上传图片");
             }
         }
         else
         {
             break;
         }
         try
         {
             ITopClient client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", AppKey, AppSecret);
             PictureUploadRequest req = new PictureUploadRequest();
             req.PictureCategoryId = 0L;
             FileItem fItem = new FileItem(image);
             req.Img = fItem;
             req.ImageInputTitle = Path.GetFileName(image);
             PictureUploadResponse response = client.Execute(req, SessionKey);
             if (response != null && response.Picture != null)
             {
                 Console.WriteLine("上传完成 " + response.Picture.PicturePath);
                 MovePicLogWriter.WriteLine("上传完成 " + response.Picture.PicturePath);
                 return response.Picture.PicturePath;
             }
         }
         catch (System.Net.WebException e)
         {
             Console.WriteLine("异常:" + e.Status + " " + e.Message);
             MovePicLogWriter.WriteLine("异常:" + e.Status + " " + e.Message);
         }
         Thread.Sleep(5000);
     }
     return "";
 }
        /// <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;
        }
Пример #17
0
        //taobao.item.propimg.upload 添加或修改属性图片
        private PropImg UploadItemPropimgInternal(long numId, string properties, FileItem fItem)
        {
            _log.LogInfo(Resource.Log_PublishSaleImging, numId);

            var req = new ItemPropimgUploadRequest {NumIid = numId, Image = fItem, Properties = properties};

            var tContext = InstanceLocator.Current.GetInstance<AuthorizedContext>();
            ItemPropimgUploadResponse 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_PublishSaleImgFailure, ex);
                throw ex;
            }

            _log.LogInfo(Resource.Log_PublishSaleImgSuccess, response.PropImg.Id, response.PropImg.Url);
            return response.PropImg;
        }