微信支付运营工具商家转账功能接口/v3/fund-app/mch-transfer/transfer-bills对接,Wechatpay-Serial 使用RSA方式从平台证书中提取公钥对平台证书的序列号进行加密,提示:{"code":"PARAM_ERROR","message":"平台证书序列号Wechatpay-Serial错误"} ,按照常见问题:https://pay.weixin.qq.com/doc/v3/merchant/4013053279 确认了,都没有问题,还是一直显示那个错误!
下面代码是加密方法:、
public static string EncryptWithPlatformCertificate(string plainText, string platformCertificatePath)
{
try
{
string certificateText = File.ReadAllText(platformCertificatePath);
certificateText = certificateText.Replace("-----BEGIN CERTIFICATE-----", "").
Replace("-----END CERTIFICATE-----", "").
Replace("\n", "").
Replace("\r", "");
byte[] certificateBytes = Convert.FromBase64String(certificateText);
X509Certificate2 certificate = new X509Certificate2(certificateBytes);
RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)certificate.PublicKey.Key;
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
byte[] encryptedBytes = rsa.Encrypt(plainTextBytes, true);
return Convert.ToBase64String(encryptedBytes);
}
catch (Exception ex)
{
throw new Exception("加密失败: " + ex.Message);
}
}
平台证书序列号需要通过接口获取的,可以把你下载的平台证书文件放到证书查看工具https://myssl.com/cert_decode.html中查看
,目前平台证书五年过期后,不再发新的平台证书了。推荐提前使用【微信支付公钥】代替平台证书进行加密敏感信息和验签https://pay.weixin.qq.com/doc/v3/merchant/4012153196
你为什么要对Wechatpay-Serial进行加密?
平台证书文件:wechatpay_xxxxxxxxxxxx.pem
序列号:40位的一个字符串,从API安全里的 微信支付平台中的国际RSA证书 下的那个序列号
未开通微信支付公钥,只开通了平台证书,代码中使用的证书都是昨天刚申请的证书