收藏
回答

运营工具商家转账,调用APIv3接口提示平台证书序列号Wechatpay-Serial错误,怎么解?

微信支付运营工具商家转账功能接口/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);
            }
        }


回答关注问题邀请回答
收藏

3 个回答

  • 支付社区运营
    支付社区运营
    04-28

    平台证书序列号需要通过接口获取的,可以把你下载的平台证书文件放到证书查看工具https://myssl.com/cert_decode.html中查看,目前平台证书五年过期后,不再发新的平台证书了。推荐提前使用【微信支付公钥】代替平台证书进行加密敏感信息和验签https://pay.weixin.qq.com/doc/v3/merchant/4012153196

    04-28
    有用
    回复
  • Memory (私信不回复)
    Memory (私信不回复)
    04-28

    你为什么要对Wechatpay-Serial进行加密?

    04-28
    有用 1
    回复 1
    • 昵称太长这里写不下
      昵称太长这里写不下
      04-28
      在社区里,看到一个一样的问题,已经修改了!官方的文档描述有歧义, 就描述序列号就行,后面还一句加密推荐!
      04-28
      回复
  • 昵称太长这里写不下
    昵称太长这里写不下
    04-28

    平台证书文件:wechatpay_xxxxxxxxxxxx.pem

    序列号:40位的一个字符串,从API安全里的 微信支付平台中的国际RSA证书 下的那个序列号

    未开通微信支付公钥,只开通了平台证书,代码中使用的证书都是昨天刚申请的证书

    04-28
    有用
    回复
登录 后发表内容