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