首页 > 代码库 > Deppon接口开发

Deppon接口开发

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

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

params 参数表的json格式

  /// <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;
        }

Post 信息 http:

     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();


异步操作:

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

      task.Start();

 

 (5)WCF 。。。