首页 > 其他 > 详细

Deppon接口开发

时间:2014-05-26 10:58:48      阅读:423      评论:0      收藏:0      [点我收藏+]

一。1)  支持的传输协议 
http ,暂时只支持HTTP协议进行通信。
(2) 支持的数据传输格式 
Json  ,所有接口暂只支持json消息格式。
(3) 编码格式:UTF-8  
交互编码格式统一用 UTF-8,避免传递中文数据出现乱码。

(4) 安全验证
在数据传输过程中,为避免数据被篡改,需要对数据进行加密。
a.  在传输的参数中,既要传递原始的json字符串params,又要传输加密后的摘要digest.
摘要的生成规则是  base64(MD5(params+apikey+timestamp)).    

params 参数表的json格式

bubuko.com,布布扣
  /// <summary>
        /// 德邦密文生成器
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static string createdigest(string param)
        {
            byte[] buffer = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(param);
            System.Security.Cryptography.MD5CryptoServiceProvider check;
            check = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] somme = check.ComputeHash(buffer);
            string ret = "";
            foreach (byte a in somme)
            {
                if (a < 16)
                    ret += "0" + a.ToString("X");
                else
                    ret += a.ToString("X");
            }
            string re = Convert.ToBase64String(System.Text.Encoding.GetEncoding("UTF-8").GetBytes(ret.ToLower()));
            return re;
        }

        /// <summary>
        /// 德邦时间差生成
        /// </summary>
        /// <returns></returns>
        public static string createTimestamp()
        {
            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            string time = Convert.ToInt64(ts.TotalMilliseconds).ToString();
            return time;
        }
bubuko.com,布布扣

Post 信息 http:

bubuko.com,布布扣
     Uri myUri = new Uri("http://58.40.17.67/dop/order/alterOrder.action");
                            Encoding myEncoding = Encoding.GetEncoding("gb2312");
                            UTF8Encoding encoding2 = new UTF8Encoding();
                            string sendPrams2 = System.Web.HttpUtility.UrlEncode("companyCode", myEncoding) + "=" + System.Web.HttpUtility.UrlEncode(COMPARNY, myEncoding) + "&" + System.Web.HttpUtility.UrlEncode("params", myEncoding) + "=" + System.Web.HttpUtility.UrlEncode(jsonSaveOrder, encoding2) + "&" + System.Web.HttpUtility.UrlEncode("digest", myEncoding) + "=" + System.Web.HttpUtility.UrlEncode(digest, myEncoding) + "&" + System.Web.HttpUtility.UrlEncode("timestamp", myEncoding) + "=" + System.Web.HttpUtility.UrlEncode(time, myEncoding);
                            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(myUri);
                            webRequest.Method = "POST";
                            webRequest.ContentType = "application/x-www-form-urlencoded";
                            byte[] setStr = System.Text.Encoding.UTF8.GetBytes(sendPrams2);
                            webRequest.ContentLength = setStr.Length;
                            using (System.IO.Stream s = webRequest.GetRequestStream())
                            {
                                s.Write(setStr, 0, setStr.Length);
                                s.Close();
                            }
                            try
                            {
                                HttpWebResponse httpWebResponse = (HttpWebResponse)webRequest.GetResponse();
                                using (System.IO.StreamReader sr = new System.IO.StreamReader(httpWebResponse.GetResponseStream(), System.Text.Encoding.UTF8))
                                {
                                    string returnMessage = sr.ReadToEnd();
bubuko.com,布布扣


异步操作:

   Task task = new Task(() =>
                    {});

      task.Start();

 

 (5)WCF 。。。

Deppon接口开发,布布扣,bubuko.com

Deppon接口开发

原文:http://www.cnblogs.com/liboen/p/3747128.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!