问题描述
用asp.netc#写的用vs运行可以正常发红包发布到iis就不行了提示“CA证书出错,请登录微信支付商户平台下载证书”///<summary>///XmlForHongBao的摘要说明///</summary>publicclassXmlForHongBao{//随机字符串stringnonce_str="";//签名stringsign="";//商户订单号stringmch_billno="";//商户号stringmch_id="";//公众账号appidstringwxappid="";//商户名称publicstringsend_name="";//用户openidpublicstringre_openid="";//付款金额publicinttotal_amount=0;//红包发放总人数publicinttotal_num=0;//红包祝福语publicstringwishing="";//Ip地址stringclient_ip="";//活动名称publicstringact_name="";//备注publicstringremark="";publicXmlForHongBao(){nonce_str=HttpMethods.getString(32);mch_id=ConfigurationManager.AppSettings["mch_id"];Randomrd=newRandom();mch_billno=mch_id+DateTime.Now.ToString("yyyyMMddHHmmss")+DateTime.Now.Millisecond.ToString()+rd.Next(10);wxappid=ConfigurationManager.AppSettings["AppID"];client_ip=HttpMethods.GetAddressIP();}privatestringMakeSign(){stringparas="";paras+="act_name="+act_name+"&";paras+="client_ip="+client_ip+"&";paras+="mch_billno="+mch_billno+"&";paras+="mch_id="+mch_id+"&";paras+="nonce_str="+nonce_str+"&";paras+="re_openid="+re_openid+"&";paras+="remark="+remark+"&";paras+="send_name="+send_name+"&";paras+="total_amount="+total_amount+"&";paras+="total_num="+total_num+"&";paras+="wishing="+wishing+"&";paras+="wxappid="+wxappid+"&";paras+="key="+ConfigurationManager.AppSettings["pay_pwd"];returnSystem.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(paras.ToString(),"MD5").ToUpper();}stringtoXml(){StringBuildersb=newStringBuilder();sb.Append("<xml>n");sb.Append("<sign><![CDATA[");sb.Append(MakeSign());sb.Append("]]></sign>n");sb.Append("<mch_billno><![CDATA[");sb.Append(mch_billno);sb.Append("]]></mch_billno>n");sb.Append("<mch_id><![CDATA[");sb.Append(mch_id);sb.Append("]]></mch_id>n");sb.Append("<wxappid><![CDATA[");sb.Append(wxappid);sb.Append("]]></wxappid>n");sb.Append("<send_name><![CDATA[");sb.Append(send_name);sb.Append("]]></send_name>n");sb.Append("<re_openid><![CDATA[");sb.Append(re_openid);sb.Append("]]></re_openid>n");sb.Append("<total_amount><![CDATA[");sb.Append(total_amount);sb.Append("]]></total_amount>n");sb.Append("<total_num><![CDATA[");sb.Append(total_num);sb.Append("]]></total_num>n");sb.Append("<wishing><![CDATA[");sb.Append(wishing);sb.Append("]]></wishing>n");sb.Append("<client_ip><![CDATA[");sb.Append(client_ip);sb.Append("]]></client_ip>n");sb.Append("<act_name><![CDATA[");sb.Append(act_name);sb.Append("]]></act_name>n");sb.Append("<remark><![CDATA[");sb.Append(remark);sb.Append("]]></remark>n");sb.Append("<nonce_str><![CDATA[");sb.Append(nonce_str);sb.Append("]]></nonce_str>n");sb.Append("</xml>n");returnsb.ToString();}publicstringGetResult(){stringcertPath=System.Web.HttpContext.Current.Server.MapPath(@"~/cert/apiclient_cert.p12").Trim();//证书已上传到对应目录stringpassword=ConfigurationManager.AppSettings["cert_pwd"].Trim();X509Certificatecert=newX509Certificate(certPath,password);returnHttpMethods.return_from_post_method(@"https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack",toXml(),cert);}}
解决方案
解决方案二:
证书是在你指定的目录下面吗?
解决方案三:
是呀我放在这儿了System.Web.HttpContext.Current.Server.MapPath(@"~/cert/apiclient_cert.p12")用vs运行代码可以正常发红包应该没有错
解决方案四:
找到问题了吧X509Certificate改成X509Certificate2就好了