当当网订单发货管理.net源码

warning: 这篇文章距离上次修改已过566天,其中的内容可能已经有所变动。

当当网订单发货.net源码

近日在做当当网的订单采集发货管理系统。很早就拿到了当当的api文档,以为很容易就解决订单管理问题,谁知当当网搞的api接口感觉像是三岁小孩玩的东西,太不成熟了。1.post和返回竟然用的是xml,难道你们服务器很好? 2.抓取订单要分两次获取,a。取得订单号,b .取得单号里的详细信息.再次证明了你们服务器很好? 3.未例用的是旧版本,还有错误。对于像我这种不懂php的人来说,翻译成.net肯定也错了。但是错错不得对,示例也不提供一个参考输入值,得出输出值,我只能猜,挑战我们的耐心?4.最麻烦的就是发货接口了,操作上:a要订单号b.要订单号里面的产品编码c.还要提供产品数量。牛c,牛x?  这里数落一下当当网的发货接口,浪费我一天的时间。提交参数明明是正确的,却提示我validatestring错。你们要提供准确点信息我就不用猜来猜去了。以为京东的接口是最差的了,想不到当当的接口还更差,后生可畏,呵呵。!

下面把个人觉得最麻烦的post发货源码发布出来,希望对大家有用! q:302777528 byError网络科技

public string ddDeliveryGoods(string url1, string poststr, string filepath, string desname)
     {
         ddClient client = new ddClient("", "y9965453");
         string url = string.Format("http://api.dangdang.com/v2/sendGoods.php?gShopID={0}"
            , "7800");//101待发货
         url = client.getMd5String(url);
         string pData = "";

         Random random = new Random();
     
         HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

         request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
     
        // request.Referer = this.reffer;
         request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:10.0.1) Gecko/20100101 Firefox/10.0.1";
         request.Method = "POST";
      //   request.Headers.Add("Cookie: " + this.cokie);
         StringBuilder builder = new StringBuilder();

         builder.Append(str + "\r\n");
         builder.Append("Content-Disposition: form-data; name=\"gShopID\"" + "\r\n");
         builder.Append(Environment.NewLine);
         builder.Append("7600" + "\r\n");

         builder.Append(str + "\r\n");
         builder.Append("Content-Disposition: form-data; name=\"validateString\"" + "\r\n");
         builder.Append(Environment.NewLine);
         string sKey = url.Split('?')[1].Split('&')[1].Split('=')[1].Trim();
         builder.Append(sKey + "\r\n");

         builder.Append(str);
         builder.Append("\r\n");
       builder.Append(" form-data;  \"sendGoods\";" + " filename = \"delivery.xml\"" +
       
      
         builder.Append("Content-Type: ");
         builder.Append("text/xml");
         builder.Append("\r\n\r\n");
         string s = builder.ToString();
         byte[] bytes = Encoding.UTF8.GetBytes(s);
         byte[] buffer = Encoding.ASCII.GetBytes("\r\n" + str + "--\r\n");
         try
         {
             FileStream stream = new FileStream(filepath, FileMode.Open, FileAccess.Read);
        
             byte[] buffer3 = myReader.ReadBytes((int)stream.Length);
            

             requestStream.Write(buffer, 0, buffer.Length);
             WebResponse response = request.GetResponse();
             StreamReader reader = new StreamReader(response.GetResponseStream(),Encoding.GetEncoding("gb2312"));
             //this.moveurl = response.ResponseUri.ToString();
             string tmpStr= reader.ReadToEnd();
             return tmpStr;
         }
         catch (Exception e)
         {
             System.Diagnostics.Debug.Print(e.Message.ToString());
             return "";
         }
     }

none
最后修改于:2023年05月08日 07:55

评论已关闭