1. 程式人生 > >微信退款證書使用c#

微信退款證書使用c#

ring ati bsp byte response word sender pub Coding

原文:微信退款證書使用c#

微信退款需要證書

data為已封裝好的xml數據

具體怎麽封裝>打開

 1     public string get(string data) 
 2        {
 3             string cert = @"D:\certificate\apiclient_cert.p12"; //證書位置
 4             string password = "11100011";//證書密碼
 5             string url = "https://api.mch.weixin.qq.com/secapi/pay/refund
";//請求地址 6 ServicePointManager.ServerCertificateValidationCallback=new 7 RemoteCertificateValidationCallback(CheckValidationResult); 8 X509Certificate cer = new X509Certificate(cert, password); 9 HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(url);
10 webrequest.ClientCertificates.Add(cer); 11 byte[] bs = Encoding.UTF8.GetBytes(data); 12 13 webrequest.Method = "POST"; 14 webrequest.ContentType = "application/x-www-form-urlencoded"; 15 webrequest.ContentLength = bs.Length; 16 //
提交請求數據 17 Stream reqStream = webrequest.GetRequestStream(); 18 reqStream.Write(bs, 0, bs.Length); 19 reqStream.Close(); 20 //接收返回的頁面,必須的,不能省略 21 WebResponse wr = webrequest.GetResponse(); 22 System.IO.Stream respStream = wr.GetResponseStream(); 23 System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("utf-8")); 24 string t = reader.ReadToEnd(); 25 System.Web.HttpContext.Current.Response.Write(t); 26 wr.Close(); 27 28 return t; 29 30 31 32 } 33 34 private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) 35 { 36 if (errors == SslPolicyErrors.None) 37 return true; 38 return false; 39 }

 

微信退款證書使用c#