请求参数!
返回
使用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;
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。