zoukankan      html  css  js  c++  java
  • D365 调用快递鸟API

    
    
    class VyaKDApi
    {
        //电商ID
        private str EBusinessID = "";//注册快递鸟后可以申请
        //电商加密私钥,快递鸟提供,注意保管,不要泄漏
        private str AppKey = "";//注册快递鸟后可以申请
        //请求url
        private str ReqURL = "https://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";
    
        /// <summary>
        /// Json方式 查询订单物流轨迹
        /// </summary>
        /// <returns></returns>
        public str getOrderTracesByJson(str _url,str _eBusinessID, str _appKey, str _requestData,str _requestType)
        {
            Map     param;
            param = new Map(Types::String, Types::String);
            param.Add("RequestData", System.Web.HttpUtility::UrlEncode(_requestData, System.Text.Encoding::UTF8));
            param.Add("EBusinessID", _eBusinessID);
            param.Add("RequestType", _requestType);
            str dataSign = this.encrypt(_requestData, AppKey, "UTF-8");
            param.Add("DataSign", System.Web.HttpUtility::UrlEncode(dataSign, System.Text.Encoding::UTF8));
            param.Add("DataType", "2");
    
            str result = this.sendPost(_url, param);
    
            //根据公司业务处理返回的信息......
    
            return result;
        }
    
        ///<summary>
        ///电商Sign签名
        ///</summary>
        ///<param name="content">内容</param>
        ///<param name="keyValue">Appkey</param>
        ///<param name="charset">URL编码 </param>
        ///<returns>DataSign签名</returns>
        private str encrypt(str _content, str _keyValue, str _charset)
        {
            if (_keyValue != null)
            {
                return this.base64(this.MD5(_content + _keyValue, _charset), _charset);
            }
            return this.base64(this.MD5(_content, _charset), _charset);
        }
    
        ///<summary>
        /// 字符串MD5加密
        ///</summary>
        ///<param name="str">要加密的字符串</param>
        ///<param name="charset">编码方式</param>
        ///<returns>密文</returns>
        private str MD5(str _strValue, str _charset)
        {
            System.Byte[] buffer = System.Text.Encoding::GetEncoding(_charset).GetBytes(_strValue);
            
            try
            {
                System.Security.Cryptography.MD5CryptoServiceProvider check;
                check = new System.Security.Cryptography.MD5CryptoServiceProvider();
                System.Byte[] somme = check.ComputeHash(buffer);
                str ret = "";
                System.Byte a;
                int length;
                int i;
                length = somme.Length;
                for (i = 0; i < length; i++)
                {
                    a = somme.GetValue(i);
                    //a = somme
                    if (a < 16)
                        ret += "0" + a.ToString("X");
                    else
                        ret += a.ToString("X");
                }
                
                return strLwr(ret);
            }
            catch
            {
                throw;
            }
        }
    
        /// <summary>
        /// base64编码
        /// </summary>
        /// <param name="str">内容</param>
        /// <param name="charset">编码方式</param>
        /// <returns></returns>
        private str base64(str _strValue, str _charset)
        {
            return System.Convert::ToBase64String(System.Text.Encoding::GetEncoding(_charset).GetBytes(_strValue));
        }
    
        /// <summary>
        /// Post方式提交数据,返回网页的源代码
        /// </summary>
        /// <param name="url">发送请求的 URL</param>
        /// <param name="param">请求的参数集合</param>
        /// <returns>远程资源的响应结果</returns>
        public str sendPost(str _url, Map _param)
        {
            System.Net.HttpWebRequest           request;
            System.Net.HttpWebResponse          response;
            MapEnumerator                       paramList;
            CLRObject                           objCLR;
            str                                 result = "";
            System.Text.StringBuilder postData = new System.Text.StringBuilder();
            paramList  = _param.getEnumerator();
            while (paramList.moveNext())
            {
                if (postData.Length > 0)
                {
                    postData.Append("&");
                }
                postData.Append(paramList.currentKey());
                postData.Append("=");
                postData.Append(paramList.currentValue());
            }
            System.Byte[] byteData = System.Text.Encoding::GetEncoding("UTF-8").GetBytes(postData.ToString());
            try
            {
                objCLR  = System.Net.WebRequest::Create(_url);
                request = objCLR;
                request.ContentType = "application/x-www-form-urlencoded";
                request.Referer = _url;
                request.Accept = "*/*";
                request.Timeout = 30 * 1000;
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
                request.Method = "POST";
                request.ContentLength = byteData.Length;
                System.IO.Stream stream = request.GetRequestStream();
                stream.Write(byteData, 0, byteData.Length);
                stream.Flush();
                stream.Close();
                response = request.GetResponse();
                System.IO.Stream backStream = response.GetResponseStream();
                System.IO.StreamReader sr = new System.IO.StreamReader(backStream, System.Text.Encoding::GetEncoding("UTF-8"));
                result = sr.ReadToEnd();
                sr.Close();
                backStream.Close();
                response.Close();
                request.Abort();
            }
            catch (Exception::CLRError)
            {
                str clrError = AifUtil::getClrErrorMessage();
                throw error(clrError);
            }
            return result;
        }
    
    }
    
    
    
     

    效果

  • 相关阅读:
    KM匹配模板
    BestCoder 1st Anniversary 1002-1005
    SGU 106 The equation
    sgu 104 Little shop of flowers
    SGU Magic Pairs
    关于 “'sqlite3' 不是内部或外部命令.....”问题
    通过django 速成 blog
    windows 通过appache链接cgi程序
    A Lot of Games(Trie树 + 博弈)
    树的点分治 (poj 1741, 1655(树形dp))
  • 原文地址:https://www.cnblogs.com/dingkui/p/14519157.html
Copyright © 2011-2022 走看看