解决微信支付退款接口:基础连接已经关闭: 连接被意外关闭

    微信退款接口需要添加证书, 特别注意:有些情况下即使在post请求时添加了证书依然报同样的错误,在添加证书时注意,

   如果使用: X509Certificate cer = new X509Certificate(path, configInfo.mch_id);  也报错的话

   改用:X509Certificate2 cer = new X509Certificate2(path, configInfo.mch_id); 

private string requestWxRefundApi(WeixinPromotionChannelConfigInfo configInfo, string param)
        {

            string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"bin\" + configInfo.cert_path;

            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            X509Certificate2 cer = new X509Certificate2(path, configInfo.mch_id);
            HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(configInfo.refund_url);
            webrequest.ClientCertificates.Add(cer);
            webrequest.Method = "post";
            //webrequest.KeepAlive = true;
            //webrequest.Timeout = 60 * 1000;

            Encoding encoding = Encoding.UTF8;
            byte[] data = encoding.GetBytes(param);
            using (Stream inputStream = webrequest.GetRequestStream())
            {
                inputStream.Write(data, 0, data.Length);
            }

            string resp = string.Empty;
            using (HttpWebResponse webreponse = (HttpWebResponse)webrequest.GetResponse())
            {
                Stream stream = webreponse.GetResponseStream();
                using (StreamReader reader = new StreamReader(stream))
                {
                    resp = reader.ReadToEnd();
                }
            }

            return resp;
        }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值