public string TaobaoUpload(string picurl, string picname) { string appkey = "12159997"; string secret = "614e40bfdb96e9063031d1a9e56fbed5"; TopXmlRestClient clientaa = new TopXmlRestClient("http://gw.api.taobao.com/router/rest", appkey, secret); PictureUploadRequest request = new PictureUploadRequest(); string filepath = Server.MapPath("images/" + picurl); request.Img = new FileItem(filepath, File.ReadAllBytes(filepath)); request.ImageInputTitle = picurl; request.PictureCategoryId = 0; request.Title = picname; clientaa.PictureUpload(request, session); PictureGetRequest request1 = new PictureGetRequest(); request1.Title = picname; string path = string.Empty; path = clientaa.PictureGet(request1, session).Content[0].PicturePath; return(path); }
/// <summary> /// 图片上传 /// </summary> /// <param name="picurl"></param> /// <param name="picname"></param> /// <param name="CategoryId"></param> /// <returns></returns> public string TaobaoUpload(string picurl, string picname, long CategoryId) { Cookie cookie = new Cookie(); string session = cookie.getCookie("top_sessiongroupbuy"); TopXmlRestClient clientaa = new TopXmlRestClient("http://gw.api.taobao.com/router/rest", appkey, secret); PictureUploadRequest request = new PictureUploadRequest(); string filepath = Server.MapPath("images/" + picurl); request.Img = new FileItem(filepath, File.ReadAllBytes(filepath)); request.ImageInputTitle = picurl; request.PictureCategoryId = CategoryId; request.Title = picname; clientaa.PictureUpload(request, session); PictureGetRequest request1 = new PictureGetRequest(); request1.Title = picname; string path = string.Empty; path = clientaa.PictureGet(request1, session).Content[0].PicturePath; return(path); }
/// <summary> /// 提交事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button1_Click(object sender, EventArgs e) { string imgs = Request.Form["img1"].ToString(); //string imgs2 = Request.Form["img2"].ToString(); Common.Cookie cookie = new Common.Cookie(); string taobaoNick = cookie.getCookie("nick"); string session = cookie.getCookie("top_sessiongroupbuy"); string sql = string.Empty; Dictionary <string, string> di = new Dictionary <string, string>(); for (int i = 0; i < imgs.Split(',').Length; i++) { sql = "SELECT * FROM TopTaobaoShopImg WHERE nick='" + taobaoNick + "' AND name='" + imgs.Split(',')[i].ToString() + "'"; di.Add(imgs.Split(',')[i].ToString(), ""); FileStream stream = new FileStream("D:\\groupbuy.7fshop.com/wwwroot/top/groupbuy/images/" + imgs.Split(',')[i].ToString(), FileMode.Open); byte[] bytes = new byte[stream.Length]; stream.Read(bytes, 0, int.Parse(stream.Length.ToString())); stream.Close(); string appkey = "12287381"; string secret = "d3486dac8198ef01000e7bd4504601a4"; TopXmlRestClient client = new TopXmlRestClient("http://gw.api.taobao.com/router/rest", "12287381", "d3486dac8198ef01000e7bd4504601a4"); PictureUploadRequest req = new PictureUploadRequest(); req.PictureCategoryId = 0L; req.ImageInputTitle = imgs.Split(',')[i].ToString(); req.Title = imgs.Split(',')[i].ToString(); req.Img = new Taobao.Top.Api.Util.FileItem(imgs.Split(',')[i].ToString(), bytes); client.PictureUpload(req, session); PictureGetRequest pc = new PictureGetRequest(); pc.Title = imgs.Split(',')[i].ToString(); pc.PictureCategoryId = 0L; Taobao.Top.Api.Domain.PageList <Taobao.Top.Api.Domain.Picture> li = client.PictureGet(pc, session); for (int j = 0; j < li.Content.Count; j++) { sql = "INSERT INTO TopTaobaoShopImg ([nick],[imgSrc] ,[name]) VALUES ('" + taobaoNick + "','" + li.Content[j].PicturePath + "','" + imgs.Split(',')[i].ToString() + "')"; } } }