隐藏

微信支付退款证书服务器配置

发布:2020/10/26 15:25:21作者:管理员 来源:本站 浏览次数:1220


1.需要去pay.weixin.com 下载证书


2.解压 安装apiclient_cert.p12

3.选择本地计算机

4.下一步下一步  密码默认为商户号

 

5.存储位置选个人

 

 

6.打开MMC.exe  或者运行中输入MMC      点击  文件→添加或删除管理单元 →证书   选择计算机账户 下一步 完成

7.点击 个人 →证书 →  选择微信支付证书  右键 管理私钥  添加IIS账户权限

8、打开iIS7>应用程序池-->您的对应网站的应用程序池>右击 >高级设置>加载用户配置文件将此值设置为true。

9.在请求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;

10.赶紧测试一下吧 

发现退款可以用了