2020-06-05 日常问题: alipay 证书支付回调证书验签cert

头大,支付宝回调一直提示验证签名失败,这换了证书验签的方式怎么就不行了呢??

排查问题

 

  1. 签名方式是否正确
    1. sign = RSA or RSA2
  2. 证书地址是否正确
  3. 使用那种验签方式 rsaCheckV1 or rsaCheckV2  or  rsaCertCheckV1 or rsaCertCheckV2

 

我实际处理问题的方式,将支付宝返回给我们的数据拿出来直接跑main方法校验:

    public static void main(String[] args) {
        // aliPay 相关文档:https://opendocs.alipay.com/open/291/105974
        DefaultAlipayClient alipayClient = null;
        try {

            //应用公钥 文件路径
            String app_cert_path =  "/Users/.../cert/appCertPublicKey_2021001163642453.crt";
            //支付宝公钥证书文件路径
            String alipay_cert_path = "/Users/.../cert/2021001163642453_alipayCertPublicKey_RSA2.crt";
            //支付宝CA根证书文件路径
            String alipay_root_cert_path = "/Users/.../cert/alipayRootCert.crt";
            //支付宝回调信息
            String result = "{\"gmt_create\":\"2020-06-06 00:59:06\",\"charset\":\"UTF-8\",\"seller_email\":\"XXXXXXXXX.com\",\"subject\":\"【XX】-单*1; \",\"sign\":\"h8oCj+iKzQxBSz+bDOmT283yEpNkzrf7zfM4In4dKk145cEYn0WxOoytyIaywQa+bshTPgZyM9iuQeeXs8gxjD+oHVye6Q+Y8apu5zgWZqLM6DuW9DsxBFdxWSzZTjKzFbvKwiD2uh3Id3TdY7g4UCKQDjs3pgyAOPV0wwTuFAG+IYHoK88WmT06XtFjcfRbndBTs+xso+WkwPNb9b0IsvoBsIeGpeay2c+Dw6fo23f/2aOnMa/qjZM5/oydjfhJCMnQyq8wOkNEMQWghD6ttcaK4WR6DumkrX9FHaPUWuD5B9lGtuj/zsc7Pv/gDwoom21K+9xnGvsjpHX1RAhEgw==\",\"body\":\"【XX】-单*1; \",\"buyer_id\":\"20XXXXXXXXXXX0\",\"invoice_amount\":\"0.01\",\"notify_id\":\"20XXXXXXXXXXXXXXXXXXXXXXXXXXX30\",\"fund_bill_list\":\"[{\\\"amount\\\":\\\"0.01\\\",\\\"fundChannel\\\":\\\"PCREDIT\\\"}]\",\"notify_type\":\"trade_status_sync\",\"trade_status\":\"TRADE_SUCCESS\",\"receipt_amount\":\"0.01\",\"app_id\":\"2XXXXXXXXXXXX3\",\"buyer_pay_amount\":\"0.01\",\"sign_type\":\"RSA2\",\"seller_id\":\"20XXXXXXXXXXXX1\",\"gmt_payment\":\"2020-06-06 00:59:07\",\"notify_time\":\"2020-06-06 01:13:08\",\"passback_params\":\"1\",\"version\":\"1.0\",\"out_trade_no\":\"AXXXXXXXXXXXXXX07\",\"total_amount\":\"0.01\",\"trade_no\":\"20XXXXXXXXXXXXXXXXXXXXX14\",\"auth_app_id\":\"2021001163642453\",\"buyer_logon_id\":\"183****5211\",\"point_amount\":\"0.00\"}";

            //第一种方法尝试
//            boolean s = AlipaySignature.rsaCertCheck(result, sign, alipay_cert_path, AlipayConstants.CHARSET_UTF8, AlipayConstants.SIGN_TYPE_RSA2);
            Map rt = JSONObject.parseObject(result, Map.class);

            try {
                //第二种方法尝试
                boolean s = AlipaySignature.rsaCertCheckV1(rt, alipay_cert_path, AlipayConstants.CHARSET_UTF8, AlipayConstants.SIGN_TYPE_RSA2);
                System.out.println(s);

            } catch (AlipayApiException e) {
                System.out.println(e);
            }

        } catch (Exception e) {

            LoggerUtil.error(LoggerUtil.COMMON_ERROR, "支付宝支付对象生成失败", e);
            e.printStackTrace();
        }
    }

 

你可能感兴趣的:(日常,java,pay)