支付宝h5支付同步回调报错问题处理

This commit is contained in:
Chopper 2021-10-12 15:53:07 +08:00
parent 0d5be1372c
commit b03fdd3bbe
2 changed files with 26 additions and 14 deletions

View File

@ -131,18 +131,6 @@ public interface Payment {
default String callbackUrl(String api, PaymentMethodEnum paymentMethodEnum) {
return api + "/buyer/cashier/callback/" + paymentMethodEnum.name();
}
/**
* 支付回调地址
*
* @param api api地址
* @param paymentMethodEnum 支付类型
* @return 回调地址
*/
default String aliCallback(String api, PaymentMethodEnum paymentMethodEnum,String params) {
return api + "/buyer/cashier/callback/" + paymentMethodEnum.name()+"?passback_params="+params;
}
/**
* 支付异步通知地址
*

View File

@ -93,7 +93,7 @@ public class AliPayPlugin implements Payment {
payModel.setProductCode("QUICK_WAP_PAY");
try {
log.info("支付宝H5支付{}", JSONUtil.toJsonStr(payModel));
AliPayRequest.wapPay(response, payModel, aliCallback(apiProperties.getBuyer(), PaymentMethodEnum.ALIPAY, URLEncoder.createAll().encode(BeanUtil.formatKeyValuePair(payParam), StandardCharsets.UTF_8)),
AliPayRequest.wapPay(response, payModel, callbackUrl(apiProperties.getBuyer(), PaymentMethodEnum.ALIPAY),
notifyUrl(apiProperties.getBuyer(), PaymentMethodEnum.ALIPAY));
} catch (Exception e) {
log.error("H5支付异常", e);
@ -236,8 +236,8 @@ public class AliPayPlugin implements Payment {
@Override
public void callBack(HttpServletRequest request) {
verifyNotify(request);
log.info("支付同步回调:");
callback(request);
}
@Override
@ -246,6 +246,30 @@ public class AliPayPlugin implements Payment {
log.info("支付异步通知:");
}
/**
* 验证支付结果
*
* @param request
*/
private void callback(HttpServletRequest request) {
try {
AlipayPaymentSetting alipayPaymentSetting = alipayPaymentSetting();
//获取支付宝反馈信息
Map<String, String> map = AliPayApi.toMap(request);
log.info("同步回调:{}", JSONUtil.toJsonStr(map));
boolean verifyResult = AlipaySignature.rsaCertCheckV1(map, alipayPaymentSetting.getAlipayPublicCertPath(), "UTF-8",
"RSA2");
if (verifyResult) {
log.info("支付回调通知:支付成功-参数:{}", map);
} else {
log.info("支付回调通知:支付失败-参数:{}", map);
}
} catch (AlipayApiException e) {
log.error("支付回调同步通知异常", e);
}
}
/**
* 验证支付结果
*