1.需要去pay.weixin.com 下載證書
2.解壓 安裝apiclient_cert.p12
3.選擇本地計算機
4.下一步下一步 密碼默認為商戶號
5.存儲位置選個人
6.打開MMC.exe 或者運行中輸入MMC 點擊 文件→添加或刪除管理單元 →證書 選擇計算機賬戶 下一步 完成
7.點擊 個人 →證書 → 選擇微信支付證書 右鍵 管理私鑰 添加IIS賬戶權限
7.在請求API是添加證書文件
var certname="您公司的名字";
var certnotbefore="證書的有效期";//騰訊比較變態 有二維碼支付證書 app支付證書 公眾號支付證書 證書的名字且都一樣 為了能夠公用一個退款接口且成功調用退款 我在請求時傳入了證書名字 和 證書有效期 來區分是哪個支付的退款
HttpWebResponse webreponse;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
//系統必須已經導入cert指向的證書
string url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
X509Store store = new X509Store("My", StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2 cert = null;
if (certnotbefore != null)
foreach (X509Certificate2 certinfo in store.Certificates.Find(X509FindType.FindBySubjectName, certname, false))
{
if (certinfo.NotAfter == certnotbefore)
cert = certinfo;
}
else
cert = store.Certificates.Find(X509FindType.FindBySubjectName, certname, false)[0];
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
webrequest.ContentType = "application/x-www-form-urlencoded";
webrequest.ClientCertificates.Add(cert);
webrequest.Method = "post";
webrequest.KeepAlive = true;
8.趕緊測試一下吧
發現退款可以用了
原文:https://www.cnblogs.com/xiaoxiangpaou/p/9799527.html