开发者社区> 问答> 正文

验签出错,请确认charset参数放在了URL查询字符串中且各参数值使用charset参数指示的字符

请求参数!image.png

返回image.png

展开
收起
游客qp6iinyrxjcgi 2020-10-12 14:24:39 945 0
1 条回答
写回答
取消 提交回答
  • 使用AlipayClient的sdkExecute和execute都不好使,改为certificateExecute,问题解决。

    以下是我的代码:

        AlipayTradeRefundRequest refundRequest = new AlipayTradeRefundRequest();
        AlipayTradeRefundModel model = new AlipayTradeRefundModel();
        model.setOutTradeNo(paySn);
        model.setRefundAmount(payAmount);
        model.setRefundReason("商品退款");
        refundRequest.setBizModel(model);
    
        try {
            AlipayTradeRefundResponse response = alipayClient.certificateExecute(refundRequest);
            if (response.isSuccess() && response.getFundChange().equalsIgnoreCase("Y")) {
                // 退款成功
            } else {
                // 退款失败
            }
        } catch (AlipayApiException e) {
            e.printStackTrace();
            log.error(" - aliRefund - ", e);
        }
    

    @Configuration public class AliPayConfig {

    private final AliPayProperties properties;
    
    public AliPayConfig(AliPayProperties properties) {
        this.properties = properties;
    }
    
    @Bean
    public AlipayClient alipayClient() throws AlipayApiException, FileNotFoundException {
        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
        certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");
        certAlipayRequest.setAppId(properties.getAppId());
        certAlipayRequest.setPrivateKey(properties.getPrivateKey());
        certAlipayRequest.setFormat("json");
        certAlipayRequest.setCharset(AlipayConstants.CHARSET_UTF8);
        certAlipayRequest.setSignType(AlipayConstants.SIGN_TYPE_RSA2);
        certAlipayRequest.setCertPath(ResourceUtils.getFile(properties.getAppCertPath()).getAbsolutePath());
        certAlipayRequest.setAlipayPublicCertPath(ResourceUtils.getFile(properties.getAlipayCertPath()).getAbsolutePath());
        certAlipayRequest.setRootCertPath(ResourceUtils.getFile(properties.getAlipayRootCertPath()).getAbsolutePath());
        return new DefaultAlipayClient(certAlipayRequest);
    }
    

    } @Configuration @ConfigurationProperties(prefix = "alipay") @Data public class AliPayProperties {

    private String appId;
    
    private String privateKey;
    
    private String notifyUrl;
    
    private String appCertPath;
    
    private String alipayCertPath;
    
    private String alipayRootCertPath;
    

    }

    2021-02-24 09:14:32
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载