Commit aa77eb029f355f576d96fe148d689e6314f49779
1 parent
696e94a1
增加支付宝 QR 支付的回调
Showing
3 changed files
with
21 additions
and
2 deletions
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayQrPayClient.java
| ... | ... | @@ -53,6 +53,7 @@ public class AlipayQrPayClient extends AbstractPayClient<AlipayPayClientConfig> |
| 53 | 53 | // 构建 AlipayTradePrecreateRequest |
| 54 | 54 | AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest(); |
| 55 | 55 | request.setBizModel(model); |
| 56 | + request.setNotifyUrl(reqDTO.getNotifyUrl()); | |
| 56 | 57 | |
| 57 | 58 | // 执行请求 |
| 58 | 59 | AlipayTradePrecreateResponse response; | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/test-integration/java/cn/iocoder/yudao/framework/core/client/impl/PayClientFactoryImplTest.java
| ... | ... | @@ -13,6 +13,7 @@ import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayWapPayClient |
| 13 | 13 | import cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXPayClientConfig; |
| 14 | 14 | import cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXPubPayClient; |
| 15 | 15 | import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; |
| 16 | +import com.alipay.api.response.AlipayTradePrecreateResponse; | |
| 16 | 17 | import org.junit.jupiter.api.Test; |
| 17 | 18 | |
| 18 | 19 | import java.io.FileInputStream; |
| ... | ... | @@ -75,6 +76,7 @@ public class PayClientFactoryImplTest { |
| 75 | 76 | * {@link AlipayQrPayClient} |
| 76 | 77 | */ |
| 77 | 78 | @Test |
| 79 | + @SuppressWarnings("unchecked") | |
| 78 | 80 | public void testCreatePayClient_ALIPAY_QR() { |
| 79 | 81 | // 创建配置 |
| 80 | 82 | AlipayPayClientConfig config = new AlipayPayClientConfig(); |
| ... | ... | @@ -89,8 +91,10 @@ public class PayClientFactoryImplTest { |
| 89 | 91 | PayClient client = payClientFactory.getPayClient(channelId); |
| 90 | 92 | // 发起支付 |
| 91 | 93 | PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO(); |
| 92 | - CommonResult<?> result = client.unifiedOrder(reqDTO); | |
| 94 | + reqDTO.setNotifyUrl("http://niubi.natapp1.cc/api/pay/order/notify/alipay-qr/1"); // TODO @tina: 这里改成你的 natapp 回调地址 | |
| 95 | + CommonResult<AlipayTradePrecreateResponse> result = (CommonResult<AlipayTradePrecreateResponse>) client.unifiedOrder(reqDTO); | |
| 93 | 96 | System.out.println(JsonUtils.toJsonString(result)); |
| 97 | + System.out.println(result.getData().getQrCode()); | |
| 94 | 98 | } |
| 95 | 99 | |
| 96 | 100 | /** | ... | ... |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/pay/controller/order/PayOrderController.java
| ... | ... | @@ -51,11 +51,25 @@ public class PayOrderController { |
| 51 | 51 | // ========== 支付渠道的回调 ========== |
| 52 | 52 | |
| 53 | 53 | @PostMapping("/notify/wx-pub/{channelId}") |
| 54 | - @ApiOperation("通知微信公众号的结果") | |
| 54 | + @ApiOperation("通知微信公众号支付的结果") | |
| 55 | 55 | public String notifyWxPayOrder(@PathVariable("channelId") Long channelId, |
| 56 | 56 | @RequestBody String xmlData) throws Exception { |
| 57 | 57 | payOrderCoreService.notifyPayOrder(channelId, PayChannelEnum.WX_PUB.getCode(), xmlData); |
| 58 | 58 | return "success"; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | + @PostMapping("/notify/alipay-qr/{channelId}") | |
| 62 | + @ApiOperation("通知支付宝扫码支付的结果") | |
| 63 | + public String notifyAlipayQrPayOrder(@PathVariable("channelId") Long channelId, | |
| 64 | + @RequestBody String data) { | |
| 65 | + return "success"; | |
| 66 | + } | |
| 67 | + | |
| 68 | + @RequestMapping("/notify/test") | |
| 69 | + @ApiOperation("通知的测试接口") | |
| 70 | + public String notifyTest() { | |
| 71 | +// System.out.println(data); | |
| 72 | + return "success"; | |
| 73 | + } | |
| 74 | + | |
| 61 | 75 | } | ... | ... |