完成 pingxx 支付回调接口
This commit is contained in:
@@ -2,10 +2,7 @@ package cn.iocoder.mall.shopweb.client.pay;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.PayTransactionRpc;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionGetReqDTO;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionRespDTO;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionSubmitReqDTO;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionSubmitRespDTO;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.*;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -35,4 +32,10 @@ public class PayTransactionClient {
|
||||
return submitPayTransactionResult.getData();
|
||||
}
|
||||
|
||||
public void updatePayTransactionSuccess(Integer payChannel, String params) {
|
||||
CommonResult<Boolean> updatePayTransactionSuccessResult = payTransactionRpc.updatePayTransactionSuccess(
|
||||
new PayTransactionSuccessReqDTO().setPayChannel(payChannel).setParams(params));
|
||||
updatePayTransactionSuccessResult.checkError();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.iocoder.mall.shopweb.controller.pay;
|
||||
|
||||
import cn.iocoder.common.framework.util.HttpUtil;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.payservice.enums.PayChannelEnum;
|
||||
import cn.iocoder.mall.security.user.core.context.UserSecurityContextHolder;
|
||||
import cn.iocoder.mall.shopweb.controller.pay.vo.transaction.PayTransactionRespVO;
|
||||
import cn.iocoder.mall.shopweb.controller.pay.vo.transaction.PayTransactionSubmitReqVO;
|
||||
@@ -14,10 +15,13 @@ import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@@ -31,6 +35,7 @@ public class PayTransactionController {
|
||||
@Autowired
|
||||
private PayTransactionService payTransactionService;
|
||||
|
||||
// TODO 芋艿:这个 API 定义可能不太太合适,应该改成支付交易单号
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得支付交易")
|
||||
@ApiImplicitParams({
|
||||
@@ -43,6 +48,7 @@ public class PayTransactionController {
|
||||
return success(payTransactionService.getPayTransaction(UserSecurityContextHolder.getUserId(), appId, orderId));
|
||||
}
|
||||
|
||||
// TODO 芋艿:这个 API 定义可能不太太合适,应该改成支付交易单号
|
||||
@PostMapping("/submit")
|
||||
@ApiOperation("提交支付交易")
|
||||
@RequiresAuthenticate
|
||||
@@ -51,24 +57,25 @@ public class PayTransactionController {
|
||||
return success(payTransactionService.submitPayTransaction(submitReqVO, HttpUtil.getIp(request)));
|
||||
}
|
||||
|
||||
// @PostMapping(value = "pingxx_pay_success", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
//// @GetMapping(value = "pingxx_pay_success")
|
||||
// public String pingxxPaySuccess(HttpServletRequest request) throws IOException {
|
||||
// logger.info("[pingxxPaySuccess][被回调]");
|
||||
// // 读取 webhook
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// try (BufferedReader reader = request.getReader()) {
|
||||
// String line;
|
||||
// while ((line = reader.readLine()) != null) {
|
||||
// sb.append(line);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//// JSONObject bodyObj = JSON.parseObject(sb.toString());
|
||||
//// bodyObj.put("webhookId", bodyObj.remove("id"));
|
||||
//// String body = bodyObj.toString();
|
||||
// payTransactionService.updateTransactionPaySuccess(PayChannelEnum.PINGXX.getId(), sb.toString());
|
||||
// return "success";
|
||||
// }
|
||||
@PostMapping(value = "pingxx_pay_success", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ApiOperation("Pingxx 支付成功回调")
|
||||
// @GetMapping(value = "pingxx_pay_success")
|
||||
public String updatePayTransactionSuccess(HttpServletRequest request) throws IOException {
|
||||
log.info("[pingxxPaySuccess][被回调]");
|
||||
// 读取 webhook
|
||||
StringBuilder sb = new StringBuilder();
|
||||
try (BufferedReader reader = request.getReader()) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
}
|
||||
|
||||
// JSONObject bodyObj = JSON.parseObject(sb.toString());
|
||||
// bodyObj.put("webhookId", bodyObj.remove("id"));
|
||||
// String body = bodyObj.toString();
|
||||
payTransactionService.updatePayTransactionSuccess(PayChannelEnum.PINGXX.getId(), sb.toString());
|
||||
return "success";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class PayTransactionService {
|
||||
|
||||
public PayTransactionSubmitRespVO submitPayTransaction(PayTransactionSubmitReqVO submitReqVO, String ip) {
|
||||
PayTransactionSubmitRespDTO submitPayTransaction = payTransactionClient.submitPayTransaction(
|
||||
PayTransactionConvert.INSTANCE.convert(submitReqVO));
|
||||
PayTransactionConvert.INSTANCE.convert(submitReqVO).setCreateIp(ip));
|
||||
return PayTransactionConvert.INSTANCE.convert(submitPayTransaction);
|
||||
}
|
||||
|
||||
@@ -25,4 +25,8 @@ public class PayTransactionService {
|
||||
return PayTransactionConvert.INSTANCE.convert(payTransactionClient.getPayTransaction(userId, appId, orderId));
|
||||
}
|
||||
|
||||
public void updatePayTransactionSuccess(Integer payChannel, String params) {
|
||||
payTransactionClient.updatePayTransactionSuccess(payChannel, params);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user