VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • C#教程之微信退款证书使用c#

基于Dapper二次封装了微信退款需要证书

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         }
复制代码

 


相关教程