微信退款证书使用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         }

 

 

转载于:https://www.cnblogs.com/oneall/p/9566621.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值