c#阿里CSB接口对接--

在接到公司有业务要接入对方CSB接口后,去阿里的git上找了csb的sdk,但是下载回来后怎么使用都是错的,不是加密校验错误就是500,但是通过java的代码能正常的运行,所以分析java 的csb sdk包后通过以下方法正常接入

  var url = "";
            var post = "json字符串数据";
            var ak = "ak";
            var sk = "sk";
            var request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "post";
            request.Timeout = 5000;
            ServicePointManager.ServerCertificateValidationCallback +=
                       CheckValidationResultp;
            DateTime time = new DateTime(0x7b2, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            TimeSpan span = (TimeSpan)(DateTime.UtcNow - time);
            var ltm = ((long)span.TotalMilliseconds).ToString();
            var dict = new Dictionary();
            dict.Add("_api_timestamp", ltm);
            dict.Add("_api_access_key", ak);
            dict.Add("_api_name", "sign_info");
            dict.Add("_api_version", "1.0.0");
            request.Headers.Set("Accept-Language", "gzip,deflate");
            request.ContentType = "application/json";           
            SetHeaderValue(request.Headers, "_api_version", "1.0.0");
            SetHeaderValue(request.Headers, "_api_name", "sign_info");
            SetHeaderValue(request.Headers, "_api_access_key", ak);
            SetHeaderValue(request.Headers, "_api_timestamp", ltm);
             //组织加密字符串
            var strr = "_api_access_key="+ak+"&_api_name=sign_info&_api_timestamp="+ ltm + "&_api_version=1.0.0";
            //加密的方法
            HMACSHA1 hmacsha1 = new HMACSHA1
            {
                Key = Encoding.UTF8.GetBytes(sk)
            };
            var sig= Convert.ToBase64String(hmacsha1.ComputeHash(Encoding.UTF8.GetBytes(strr)));
            SetHeaderValue(request.Headers, "_api_signature", sig);
            request.UserAgent = "Apache-HttpClient/4.4.1 (Java/10.0.2)";
            var buff = Encoding.UTF8.GetBytes(post);
            request.ContentLength = buff.Length;
            var outim = request.GetRequestStream();
            outim.Write(buff,0, buff.Length);
            outim.Close();
            var response =request.GetResponse() as HttpWebResponse;
            var str = new StreamReader(response.GetResponseStream(),Encoding.UTF8);
            var html = str.ReadToEnd();

作者QQ:403648571  c#阿里CSB接口对接--_第1张图片

你可能感兴趣的:(框架设计,c#,asp-net-mvc,CSB,阿里接口,CSB接口,阿里csb服务接口)