您的位置:威尼斯官方网站 > 威尼斯正规官网 > Wechat退款证书应用c#

Wechat退款证书应用c#

发布时间:2019-11-12 15:39编辑:威尼斯正规官网浏览(102)

    微信退款需要证书

    威尼斯官方网站,data为已封装好的xml数据

    具体怎么封装>打开

     1     public string get(string data) 
     2        {
     3             string cert = @"D:certificateapiclient_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         }
    

     

    本文由威尼斯官方网站发布于威尼斯正规官网,转载请注明出处:Wechat退款证书应用c#

    关键词:

上一篇:Python中级 —— 05访谈数据库

下一篇:没有了