CA证书出错,请登录微信支付商户平台下载证书

.Net技术 码拜 8年前 (2016-02-22) 2251次浏览
问题如标题
1、证书已经下载和安装到服务器
CA证书出错,请登录微信支付商户平台下载证书
2、证书代码如下:

                    string strHtml = "";
                    HttpWebResponse webreponse;
                    try
                    {
                        //系统必须已经导入cert指向的证书
                        string url = "https://api.mch.weixin.qq.com/secapi/pay/refund";  
                        X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
                        store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
                        System.Security.Cryptography.X509Certificates.X509Certificate2 cert =
                          store.Certificates.Find(X509FindType.FindBySubjectName, "证书名称就不写出来了", false)[0];
                        HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(url);
                        webrequest.ClientCertificates.Add(cert);
                        webrequest.Method = "post";
                        webrequest.KeepAlive = true;
                        webreponse = (HttpWebResponse)webrequest.GetResponse();
                        Stream stream = webreponse.GetResponseStream();
                        string resp = string.Empty;
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            resp = reader.ReadToEnd();
                        }
                        strHtml = resp;
                    }
                    catch (Exception exp)
                    {
                        strHtml = exp.ToString();
                    }

经调试运行错误地方为:

System.Security.Cryptography.X509Certificates.X509Certificate2 cert = store.Certificates.Find(X509FindType.FindBySubjectName, "证书名称就不写出来了", false)[0];

上面这句代码是通过名称查找证书,但是这个数组返回空,找不到对应证书。
至此问题描述完毕,请求各位高手帮忙!

解决方案

5

多半是证书名写错了,把Certificates里的证书名全输出来看看叫啥名称吧

25

那个例子里面不是有么

//能否使用证书
if (isUseCert)
{
    string path = HttpContext.Current.Request.PhysicalApplicationPath;
    X509Certificate2 cert = new X509Certificate2(path + WxPayConfig.SSLCERT_PATH, WxPayConfig.SSLCERT_PASSWORD);
    
    request.ClientCertificates.Add(cert);
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明CA证书出错,请登录微信支付商户平台下载证书
喜欢 (0)
[1034331897@qq.com]
分享 (0)