微信退款 The remote server returned an error: (400) Bad Request. 微信支付退款接口:基礎連接已經關閉: 連接被意外關閉


微信退款接口需要添加證書, 特別注意:有些情況下即使在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;
}

  

————————————————
版權聲明:本文為CSDN博主「Eric.chen1」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/m0_37693130/article/details/100563820


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM