Commit fc2d30cfaf64ee886bc84547494951036a175d45
1 parent
7bff98b6
pay:修复单元测试报错
Showing
8 changed files
with
26 additions
and
168 deletions
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/transfer/dto/PayTransferCreateReqDTO.java
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/package-info.java deleted
| 1 | -package cn.iocoder.yudao.module.pay; |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/wallet/PayWalletController.java
| @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollectionUtil; | @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollectionUtil; | ||
| 4 | import cn.hutool.core.util.StrUtil; | 4 | import cn.hutool.core.util.StrUtil; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 8 | import cn.iocoder.yudao.module.member.api.user.MemberUserApi; | 7 | import cn.iocoder.yudao.module.member.api.user.MemberUserApi; |
| 9 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; | 8 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| 10 | import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletPageReqVO; | 9 | import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletPageReqVO; |
| @@ -26,12 +25,10 @@ import javax.annotation.Resource; | @@ -26,12 +25,10 @@ import javax.annotation.Resource; | ||
| 26 | import javax.validation.Valid; | 25 | import javax.validation.Valid; |
| 27 | import java.util.List; | 26 | import java.util.List; |
| 28 | import java.util.Map; | 27 | import java.util.Map; |
| 29 | -import java.util.Set; | ||
| 30 | 28 | ||
| 31 | import static cn.iocoder.yudao.framework.common.enums.UserTypeEnum.MEMBER; | 29 | import static cn.iocoder.yudao.framework.common.enums.UserTypeEnum.MEMBER; |
| 32 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 30 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 33 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | ||
| 34 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | 31 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; |
| 35 | 32 | ||
| 36 | @Tag(name = "管理后台 - 用户钱包") | 33 | @Tag(name = "管理后台 - 用户钱包") |
| 37 | @RestController | 34 | @RestController |
| @@ -50,6 +47,7 @@ public class PayWalletController { | @@ -50,6 +47,7 @@ public class PayWalletController { | ||
| 50 | @Operation(summary = "获得用户钱包明细") | 47 | @Operation(summary = "获得用户钱包明细") |
| 51 | public CommonResult<PayWalletRespVO> getWallet(PayWalletUserReqVO reqVO) { | 48 | public CommonResult<PayWalletRespVO> getWallet(PayWalletUserReqVO reqVO) { |
| 52 | PayWalletDO wallet = payWalletService.getOrCreateWallet(reqVO.getUserId(), MEMBER.getValue()); | 49 | PayWalletDO wallet = payWalletService.getOrCreateWallet(reqVO.getUserId(), MEMBER.getValue()); |
| 50 | + // TODO jason:如果为空,返回给前端只要 null 就可以了 | ||
| 53 | MemberUserRespDTO memberUser = memberUserApi.getUser(reqVO.getUserId()); | 51 | MemberUserRespDTO memberUser = memberUserApi.getUser(reqVO.getUserId()); |
| 54 | String nickname = memberUser == null ? "" : memberUser.getNickname(); | 52 | String nickname = memberUser == null ? "" : memberUser.getNickname(); |
| 55 | String avatar = memberUser == null ? "" : memberUser.getAvatar(); | 53 | String avatar = memberUser == null ? "" : memberUser.getAvatar(); |
| @@ -61,9 +59,8 @@ public class PayWalletController { | @@ -61,9 +59,8 @@ public class PayWalletController { | ||
| 61 | @PreAuthorize("@ss.hasPermission('pay:wallet:query')") | 59 | @PreAuthorize("@ss.hasPermission('pay:wallet:query')") |
| 62 | public CommonResult<PageResult<PayWalletRespVO>> getWalletPage(@Valid PayWalletPageReqVO pageVO) { | 60 | public CommonResult<PageResult<PayWalletRespVO>> getWalletPage(@Valid PayWalletPageReqVO pageVO) { |
| 63 | if (StrUtil.isNotEmpty(pageVO.getNickname())) { | 61 | if (StrUtil.isNotEmpty(pageVO.getNickname())) { |
| 64 | - Set<Long> userIds = CollectionUtils.convertSet(memberUserApi.getUserListByNickname(pageVO.getNickname()), | ||
| 65 | - MemberUserRespDTO::getId); | ||
| 66 | - pageVO.setUserIds(userIds); | 62 | + List<MemberUserRespDTO> users = memberUserApi.getUserListByNickname(pageVO.getNickname()); |
| 63 | + pageVO.setUserIds(convertSet(users, MemberUserRespDTO::getId)); | ||
| 67 | } | 64 | } |
| 68 | // TODO @jason:管理员也可以先查询下。。 | 65 | // TODO @jason:管理员也可以先查询下。。 |
| 69 | // 暂时支持查询 userType 会员类型。管理员类型还不知道使用场景 | 66 | // 暂时支持查询 userType 会员类型。管理员类型还不知道使用场景 |
| @@ -71,8 +68,8 @@ public class PayWalletController { | @@ -71,8 +68,8 @@ public class PayWalletController { | ||
| 71 | if (CollectionUtil.isEmpty(pageResult.getList())) { | 68 | if (CollectionUtil.isEmpty(pageResult.getList())) { |
| 72 | return success(new PageResult<>(pageResult.getTotal())); | 69 | return success(new PageResult<>(pageResult.getTotal())); |
| 73 | } | 70 | } |
| 74 | - List<Long> userIds = convertList(pageResult.getList(), PayWalletDO::getUserId); | ||
| 75 | - Map<Long, MemberUserRespDTO> userMap = convertMap(memberUserApi.getUserList(userIds),MemberUserRespDTO::getId); | 71 | + List<MemberUserRespDTO> users = memberUserApi.getUserList(convertList(pageResult.getList(), PayWalletDO::getUserId)); |
| 72 | + Map<Long, MemberUserRespDTO> userMap = convertMap(users, MemberUserRespDTO::getId); | ||
| 76 | return success(PayWalletConvert.INSTANCE.convertPage(pageResult, userMap)); | 73 | return success(PayWalletConvert.INSTANCE.convertPage(pageResult, userMap)); |
| 77 | } | 74 | } |
| 78 | 75 |
yudao-module-pay/yudao-module-pay-biz/src/test/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceTest.java
| @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.pay.service.order; | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.pay.service.order; | ||
| 3 | import cn.hutool.extra.spring.SpringUtil; | 3 | import cn.hutool.extra.spring.SpringUtil; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.pay.core.client.PayClient; | 5 | import cn.iocoder.yudao.framework.pay.core.client.PayClient; |
| 6 | -import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; | ||
| 7 | import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; | 6 | import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; |
| 8 | import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; | 7 | import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; |
| 9 | import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderDisplayModeEnum; | 8 | import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderDisplayModeEnum; |
| @@ -68,8 +67,6 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | @@ -68,8 +67,6 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | ||
| 68 | private PayOrderExtensionMapper orderExtensionMapper; | 67 | private PayOrderExtensionMapper orderExtensionMapper; |
| 69 | 68 | ||
| 70 | @MockBean | 69 | @MockBean |
| 71 | - private PayClientFactory payClientFactory; | ||
| 72 | - @MockBean | ||
| 73 | private PayProperties properties; | 70 | private PayProperties properties; |
| 74 | @MockBean | 71 | @MockBean |
| 75 | private PayAppService appService; | 72 | private PayAppService appService; |
| @@ -351,7 +348,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | @@ -351,7 +348,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | ||
| 351 | .thenReturn(channel); | 348 | .thenReturn(channel); |
| 352 | // mock 方法(client) | 349 | // mock 方法(client) |
| 353 | PayClient client = mock(PayClient.class); | 350 | PayClient client = mock(PayClient.class); |
| 354 | - when(payClientFactory.getPayClient(eq(10L))).thenReturn(client); | 351 | + when(channelService.getPayClient(eq(10L))).thenReturn(client); |
| 355 | // mock 方法() | 352 | // mock 方法() |
| 356 | PayOrderRespDTO unifiedOrderResp = randomPojo(PayOrderRespDTO.class, o -> | 353 | PayOrderRespDTO unifiedOrderResp = randomPojo(PayOrderRespDTO.class, o -> |
| 357 | o.setChannelErrorCode("001").setChannelErrorMsg("模拟异常")); | 354 | o.setChannelErrorCode("001").setChannelErrorMsg("模拟异常")); |
| @@ -405,7 +402,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | @@ -405,7 +402,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | ||
| 405 | .thenReturn(channel); | 402 | .thenReturn(channel); |
| 406 | // mock 方法(client) | 403 | // mock 方法(client) |
| 407 | PayClient client = mock(PayClient.class); | 404 | PayClient client = mock(PayClient.class); |
| 408 | - when(payClientFactory.getPayClient(eq(10L))).thenReturn(client); | 405 | + when(channelService.getPayClient(eq(10L))).thenReturn(client); |
| 409 | // mock 方法(支付渠道的调用) | 406 | // mock 方法(支付渠道的调用) |
| 410 | PayOrderRespDTO unifiedOrderResp = randomPojo(PayOrderRespDTO.class, o -> o.setChannelErrorCode(null).setChannelErrorMsg(null) | 407 | PayOrderRespDTO unifiedOrderResp = randomPojo(PayOrderRespDTO.class, o -> o.setChannelErrorCode(null).setChannelErrorMsg(null) |
| 411 | .setDisplayMode(PayOrderDisplayModeEnum.URL.getMode()).setDisplayContent("tudou")); | 408 | .setDisplayMode(PayOrderDisplayModeEnum.URL.getMode()).setDisplayContent("tudou")); |
| @@ -463,7 +460,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | @@ -463,7 +460,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | ||
| 463 | orderExtensionMapper.insert(orderExtension); | 460 | orderExtensionMapper.insert(orderExtension); |
| 464 | // mock 方法(PayClient 已支付) | 461 | // mock 方法(PayClient 已支付) |
| 465 | PayClient client = mock(PayClient.class); | 462 | PayClient client = mock(PayClient.class); |
| 466 | - when(payClientFactory.getPayClient(eq(orderExtension.getChannelId()))).thenReturn(client); | 463 | + when(channelService.getPayClient(eq(orderExtension.getChannelId()))).thenReturn(client); |
| 467 | when(client.getOrder(eq(orderExtension.getNo()))).thenReturn(randomPojo(PayOrderRespDTO.class, | 464 | when(client.getOrder(eq(orderExtension.getNo()))).thenReturn(randomPojo(PayOrderRespDTO.class, |
| 468 | o -> o.setStatus(PayOrderStatusEnum.SUCCESS.getStatus()))); | 465 | o -> o.setStatus(PayOrderStatusEnum.SUCCESS.getStatus()))); |
| 469 | 466 | ||
| @@ -482,7 +479,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | @@ -482,7 +479,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | ||
| 482 | orderExtensionMapper.insert(orderExtension); | 479 | orderExtensionMapper.insert(orderExtension); |
| 483 | // mock 方法(PayClient 已支付) | 480 | // mock 方法(PayClient 已支付) |
| 484 | PayClient client = mock(PayClient.class); | 481 | PayClient client = mock(PayClient.class); |
| 485 | - when(payClientFactory.getPayClient(eq(orderExtension.getChannelId()))).thenReturn(client); | 482 | + when(channelService.getPayClient(eq(orderExtension.getChannelId()))).thenReturn(client); |
| 486 | when(client.getOrder(eq(orderExtension.getNo()))).thenReturn(randomPojo(PayOrderRespDTO.class, | 483 | when(client.getOrder(eq(orderExtension.getNo()))).thenReturn(randomPojo(PayOrderRespDTO.class, |
| 487 | o -> o.setStatus(PayOrderStatusEnum.WAITING.getStatus()))); | 484 | o -> o.setStatus(PayOrderStatusEnum.WAITING.getStatus()))); |
| 488 | 485 | ||
| @@ -639,7 +636,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | @@ -639,7 +636,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | ||
| 639 | orderExtensionMapper.insert(orderExtension); | 636 | orderExtensionMapper.insert(orderExtension); |
| 640 | // 准备参数 | 637 | // 准备参数 |
| 641 | PayChannelDO channel = randomPojo(PayChannelDO.class, o -> o.setId(10L) | 638 | PayChannelDO channel = randomPojo(PayChannelDO.class, o -> o.setId(10L) |
| 642 | - .setFeeRate(0.1D)); | 639 | + .setFeeRate(10D)); |
| 643 | PayOrderRespDTO notify = randomPojo(PayOrderRespDTO.class, | 640 | PayOrderRespDTO notify = randomPojo(PayOrderRespDTO.class, |
| 644 | o -> o.setStatus(PayOrderStatusRespEnum.SUCCESS.getStatus()) | 641 | o -> o.setStatus(PayOrderStatusRespEnum.SUCCESS.getStatus()) |
| 645 | .setOutTradeNo("P110")); | 642 | .setOutTradeNo("P110")); |
| @@ -656,7 +653,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | @@ -656,7 +653,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | ||
| 656 | .setChannelId(10L).setChannelCode(channel.getCode()) | 653 | .setChannelId(10L).setChannelCode(channel.getCode()) |
| 657 | .setSuccessTime(notify.getSuccessTime()).setExtensionId(orderExtension.getId()).setNo(orderExtension.getNo()) | 654 | .setSuccessTime(notify.getSuccessTime()).setExtensionId(orderExtension.getId()).setNo(orderExtension.getNo()) |
| 658 | .setChannelOrderNo(notify.getChannelOrderNo()).setChannelUserId(notify.getChannelUserId()) | 655 | .setChannelOrderNo(notify.getChannelOrderNo()).setChannelUserId(notify.getChannelUserId()) |
| 659 | - .setChannelFeeRate(0.1D).setChannelFeePrice(1); | 656 | + .setChannelFeeRate(10D).setChannelFeePrice(1); |
| 660 | assertPojoEquals(order, orderMapper.selectOne(null), | 657 | assertPojoEquals(order, orderMapper.selectOne(null), |
| 661 | "updateTime", "updater"); | 658 | "updateTime", "updater"); |
| 662 | // 断言,调用 | 659 | // 断言,调用 |
| @@ -874,7 +871,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | @@ -874,7 +871,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | ||
| 874 | orderExtensionMapper.insert(orderExtension); | 871 | orderExtensionMapper.insert(orderExtension); |
| 875 | // mock 方法(PayClient) | 872 | // mock 方法(PayClient) |
| 876 | PayClient client = mock(PayClient.class); | 873 | PayClient client = mock(PayClient.class); |
| 877 | - when(payClientFactory.getPayClient(eq(10L))).thenReturn(client); | 874 | + when(channelService.getPayClient(eq(10L))).thenReturn(client); |
| 878 | // mock 方法(PayClient 异常) | 875 | // mock 方法(PayClient 异常) |
| 879 | when(client.getOrder(any())).thenThrow(new RuntimeException()); | 876 | when(client.getOrder(any())).thenThrow(new RuntimeException()); |
| 880 | 877 | ||
| @@ -901,7 +898,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | @@ -901,7 +898,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | ||
| 901 | orderExtensionMapper.insert(orderExtension); | 898 | orderExtensionMapper.insert(orderExtension); |
| 902 | // mock 方法(PayClient) | 899 | // mock 方法(PayClient) |
| 903 | PayClient client = mock(PayClient.class); | 900 | PayClient client = mock(PayClient.class); |
| 904 | - when(payClientFactory.getPayClient(eq(10L))).thenReturn(client); | 901 | + when(channelService.getPayClient(eq(10L))).thenReturn(client); |
| 905 | // mock 方法(PayClient 成功返回) | 902 | // mock 方法(PayClient 成功返回) |
| 906 | PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class, | 903 | PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class, |
| 907 | o -> o.setStatus(PayOrderStatusEnum.SUCCESS.getStatus())); | 904 | o -> o.setStatus(PayOrderStatusEnum.SUCCESS.getStatus())); |
| @@ -935,7 +932,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | @@ -935,7 +932,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | ||
| 935 | orderExtensionMapper.insert(orderExtension); | 932 | orderExtensionMapper.insert(orderExtension); |
| 936 | // mock 方法(PayClient) | 933 | // mock 方法(PayClient) |
| 937 | PayClient client = mock(PayClient.class); | 934 | PayClient client = mock(PayClient.class); |
| 938 | - when(payClientFactory.getPayClient(eq(10L))).thenReturn(client); | 935 | + when(channelService.getPayClient(eq(10L))).thenReturn(client); |
| 939 | // mock 方法(PayClient 成功返回) | 936 | // mock 方法(PayClient 成功返回) |
| 940 | PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class, | 937 | PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class, |
| 941 | o -> o.setStatus(PayOrderStatusEnum.CLOSED.getStatus())); | 938 | o -> o.setStatus(PayOrderStatusEnum.CLOSED.getStatus())); |
| @@ -966,7 +963,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | @@ -966,7 +963,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | ||
| 966 | orderExtensionMapper.insert(orderExtension); | 963 | orderExtensionMapper.insert(orderExtension); |
| 967 | // mock 方法(PayClient) | 964 | // mock 方法(PayClient) |
| 968 | PayClient client = mock(PayClient.class); | 965 | PayClient client = mock(PayClient.class); |
| 969 | - when(payClientFactory.getPayClient(eq(10L))).thenReturn(client); | 966 | + when(channelService.getPayClient(eq(10L))).thenReturn(client); |
| 970 | 967 | ||
| 971 | // 调用 | 968 | // 调用 |
| 972 | int count = orderService.expireOrder(); | 969 | int count = orderService.expireOrder(); |
| @@ -1013,7 +1010,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | @@ -1013,7 +1010,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | ||
| 1013 | orderExtensionMapper.insert(orderExtension); | 1010 | orderExtensionMapper.insert(orderExtension); |
| 1014 | // mock 方法(PayClient) | 1011 | // mock 方法(PayClient) |
| 1015 | PayClient client = mock(PayClient.class); | 1012 | PayClient client = mock(PayClient.class); |
| 1016 | - when(payClientFactory.getPayClient(eq(10L))).thenReturn(client); | 1013 | + when(channelService.getPayClient(eq(10L))).thenReturn(client); |
| 1017 | // mock 方法(PayClient 退款返回) | 1014 | // mock 方法(PayClient 退款返回) |
| 1018 | PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class, | 1015 | PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class, |
| 1019 | o -> o.setStatus(PayOrderStatusEnum.REFUND.getStatus())); | 1016 | o -> o.setStatus(PayOrderStatusEnum.REFUND.getStatus())); |
| @@ -1047,7 +1044,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | @@ -1047,7 +1044,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | ||
| 1047 | orderExtensionMapper.insert(orderExtension); | 1044 | orderExtensionMapper.insert(orderExtension); |
| 1048 | // mock 方法(PayClient) | 1045 | // mock 方法(PayClient) |
| 1049 | PayClient client = mock(PayClient.class); | 1046 | PayClient client = mock(PayClient.class); |
| 1050 | - when(payClientFactory.getPayClient(eq(10L))).thenReturn(client); | 1047 | + when(channelService.getPayClient(eq(10L))).thenReturn(client); |
| 1051 | // mock 方法(PayClient 成功返回) | 1048 | // mock 方法(PayClient 成功返回) |
| 1052 | PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class, | 1049 | PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class, |
| 1053 | o -> o.setStatus(PayOrderStatusEnum.SUCCESS.getStatus())); | 1050 | o -> o.setStatus(PayOrderStatusEnum.SUCCESS.getStatus())); |
| @@ -1081,7 +1078,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | @@ -1081,7 +1078,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { | ||
| 1081 | orderExtensionMapper.insert(orderExtension); | 1078 | orderExtensionMapper.insert(orderExtension); |
| 1082 | // mock 方法(PayClient) | 1079 | // mock 方法(PayClient) |
| 1083 | PayClient client = mock(PayClient.class); | 1080 | PayClient client = mock(PayClient.class); |
| 1084 | - when(payClientFactory.getPayClient(eq(10L))).thenReturn(client); | 1081 | + when(channelService.getPayClient(eq(10L))).thenReturn(client); |
| 1085 | // mock 方法(PayClient 关闭返回) | 1082 | // mock 方法(PayClient 关闭返回) |
| 1086 | PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class, | 1083 | PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class, |
| 1087 | o -> o.setStatus(PayOrderStatusEnum.CLOSED.getStatus())); | 1084 | o -> o.setStatus(PayOrderStatusEnum.CLOSED.getStatus())); |
yudao-module-pay/yudao-module-pay-biz/src/test/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundServiceTest.java
| @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.pay.service.refund; | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.pay.service.refund; | ||
| 3 | import cn.hutool.extra.spring.SpringUtil; | 3 | import cn.hutool.extra.spring.SpringUtil; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.pay.core.client.PayClient; | 5 | import cn.iocoder.yudao.framework.pay.core.client.PayClient; |
| 6 | -import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; | ||
| 7 | import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; | 6 | import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; |
| 8 | import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; | 7 | import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; |
| 9 | import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; | 8 | import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; |
| @@ -67,8 +66,6 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest { | @@ -67,8 +66,6 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest { | ||
| 67 | @MockBean | 66 | @MockBean |
| 68 | private PayProperties payProperties; | 67 | private PayProperties payProperties; |
| 69 | @MockBean | 68 | @MockBean |
| 70 | - private PayClientFactory payClientFactory; | ||
| 71 | - @MockBean | ||
| 72 | private PayOrderService orderService; | 69 | private PayOrderService orderService; |
| 73 | @MockBean | 70 | @MockBean |
| 74 | private PayAppService appService; | 71 | private PayAppService appService; |
| @@ -335,7 +332,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest { | @@ -335,7 +332,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest { | ||
| 335 | when(channelService.validPayChannel(eq(1L))).thenReturn(channel); | 332 | when(channelService.validPayChannel(eq(1L))).thenReturn(channel); |
| 336 | // mock 方法(client) | 333 | // mock 方法(client) |
| 337 | PayClient client = mock(PayClient.class); | 334 | PayClient client = mock(PayClient.class); |
| 338 | - when(payClientFactory.getPayClient(eq(10L))).thenReturn(client); | 335 | + when(channelService.getPayClient(eq(10L))).thenReturn(client); |
| 339 | // mock 数据(refund 已存在) | 336 | // mock 数据(refund 已存在) |
| 340 | PayRefundDO refund = randomPojo(PayRefundDO.class, o -> | 337 | PayRefundDO refund = randomPojo(PayRefundDO.class, o -> |
| 341 | o.setAppId(1L).setMerchantRefundId("200")); | 338 | o.setAppId(1L).setMerchantRefundId("200")); |
| @@ -367,7 +364,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest { | @@ -367,7 +364,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest { | ||
| 367 | when(channelService.validPayChannel(eq(10L))).thenReturn(channel); | 364 | when(channelService.validPayChannel(eq(10L))).thenReturn(channel); |
| 368 | // mock 方法(client) | 365 | // mock 方法(client) |
| 369 | PayClient client = mock(PayClient.class); | 366 | PayClient client = mock(PayClient.class); |
| 370 | - when(payClientFactory.getPayClient(eq(10L))).thenReturn(client); | 367 | + when(channelService.getPayClient(eq(10L))).thenReturn(client); |
| 371 | // mock 方法(client 调用发生异常) | 368 | // mock 方法(client 调用发生异常) |
| 372 | when(client.unifiedRefund(any(PayRefundUnifiedReqDTO.class))).thenThrow(new RuntimeException()); | 369 | when(client.unifiedRefund(any(PayRefundUnifiedReqDTO.class))).thenThrow(new RuntimeException()); |
| 373 | 370 | ||
| @@ -411,7 +408,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest { | @@ -411,7 +408,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest { | ||
| 411 | when(channelService.validPayChannel(eq(10L))).thenReturn(channel); | 408 | when(channelService.validPayChannel(eq(10L))).thenReturn(channel); |
| 412 | // mock 方法(client) | 409 | // mock 方法(client) |
| 413 | PayClient client = mock(PayClient.class); | 410 | PayClient client = mock(PayClient.class); |
| 414 | - when(payClientFactory.getPayClient(eq(10L))).thenReturn(client); | 411 | + when(channelService.getPayClient(eq(10L))).thenReturn(client); |
| 415 | // mock 方法(client 成功) | 412 | // mock 方法(client 成功) |
| 416 | PayRefundRespDTO refundRespDTO = randomPojo(PayRefundRespDTO.class); | 413 | PayRefundRespDTO refundRespDTO = randomPojo(PayRefundRespDTO.class); |
| 417 | when(client.unifiedRefund(argThat(unifiedReqDTO -> { | 414 | when(client.unifiedRefund(argThat(unifiedReqDTO -> { |
| @@ -668,7 +665,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest { | @@ -668,7 +665,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest { | ||
| 668 | refundMapper.insert(refund); | 665 | refundMapper.insert(refund); |
| 669 | // mock 方法(client) | 666 | // mock 方法(client) |
| 670 | PayClient client = mock(PayClient.class); | 667 | PayClient client = mock(PayClient.class); |
| 671 | - when(payClientFactory.getPayClient(eq(10L))).thenReturn(client); | 668 | + when(channelService.getPayClient(eq(10L))).thenReturn(client); |
| 672 | // mock 方法(client 返回指定状态) | 669 | // mock 方法(client 返回指定状态) |
| 673 | PayRefundRespDTO respDTO = randomPojo(PayRefundRespDTO.class, o -> o.setStatus(status)); | 670 | PayRefundRespDTO respDTO = randomPojo(PayRefundRespDTO.class, o -> o.setStatus(status)); |
| 674 | when(client.getRefund(eq("P110"), eq("R220"))).thenReturn(respDTO); | 671 | when(client.getRefund(eq("P110"), eq("R220"))).thenReturn(respDTO); |
| @@ -690,7 +687,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest { | @@ -690,7 +687,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest { | ||
| 690 | refundMapper.insert(refund); | 687 | refundMapper.insert(refund); |
| 691 | // mock 方法(client) | 688 | // mock 方法(client) |
| 692 | PayClient client = mock(PayClient.class); | 689 | PayClient client = mock(PayClient.class); |
| 693 | - when(payClientFactory.getPayClient(eq(10L))).thenReturn(client); | 690 | + when(channelService.getPayClient(eq(10L))).thenReturn(client); |
| 694 | // mock 方法(client 抛出异常) | 691 | // mock 方法(client 抛出异常) |
| 695 | when(client.getRefund(eq("P110"), eq("R220"))).thenThrow(new RuntimeException()); | 692 | when(client.getRefund(eq("P110"), eq("R220"))).thenThrow(new RuntimeException()); |
| 696 | 693 |
yudao-server/src/main/resources/static/MP_verify_DKOvVzFP7vPwwHx2.txt deleted
yudao-server/src/main/resources/static/READMD.md deleted
| 1 | -## 微信公众号 | ||
| 2 | - | ||
| 3 | -参考文章:https://www.yuque.com/docs/share/0e2966dd-89f8-4b69-980d-b876168725df | ||
| 4 | - | ||
| 5 | -① 访问 social-login.html 选择【微信公众号】 | ||
| 6 | - | ||
| 7 | -② 微信公众号授权完成后,跳转回 social-login2.html,输入手机号 + 密码,进行绑定 | ||
| 8 | - | ||
| 9 | -## 微信小程序 | ||
| 10 | - | ||
| 11 | -参考文章:https://www.yuque.com/docs/share/88e3d30a-6830-45fc-8c25-dae485aef3aa | ||
| 12 | - | ||
| 13 | -① 暂时使用 mini-program-test 项目 |
yudao-server/src/main/resources/static/pay_wx_pub.html deleted
| 1 | -<!DOCTYPE html> | ||
| 2 | -<html> | ||
| 3 | -<head> | ||
| 4 | - <meta charset="UTF-8"> | ||
| 5 | - <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/> | ||
| 6 | - <title>支付测试页</title> | ||
| 7 | - <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script> | ||
| 8 | - <script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script> | ||
| 9 | -</head> | ||
| 10 | -<body> | ||
| 11 | -<div>点击如下按钮,发起支付的测试</div> | ||
| 12 | -<div> | ||
| 13 | - <button id="wx_pub">微信公众号</button> | ||
| 14 | -</div> | ||
| 15 | -</body> | ||
| 16 | -<script> | ||
| 17 | - let shopOrderId = undefined; | ||
| 18 | - let payOrderId = undefined; | ||
| 19 | - let server = 'http://127.0.0.1:48080'; | ||
| 20 | - // let server = 'http://niubi.natapp1.cc'; | ||
| 21 | - // TODO openid | ||
| 22 | - let openid = "ockUAwIZ-0OeMZl9ogcZ4ILrGba0"; | ||
| 23 | - $(function() { | ||
| 24 | - // 获得 JsapiTicket | ||
| 25 | - // 参考 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html 文档 | ||
| 26 | - $.ajax({ | ||
| 27 | - url: server + "/app-api/wx/mp/create-jsapi-signature?url=" + document.location.href, | ||
| 28 | - method: 'POST', | ||
| 29 | - headers: { | ||
| 30 | - 'tenant-id': 1 | ||
| 31 | - }, | ||
| 32 | - success: function( result ) { | ||
| 33 | - if (result.code !== 0) { | ||
| 34 | - alert('获取 JsapiTicket 失败,原因:' + result.msg) | ||
| 35 | - return; | ||
| 36 | - } | ||
| 37 | - var jsapiTicket = result.data; | ||
| 38 | - jsapiTicket.jsApiList = ['chooseWXPay']; | ||
| 39 | - jsapiTicket.debug = false; | ||
| 40 | - | ||
| 41 | - // 初始化 JS | ||
| 42 | - wx.config(jsapiTicket); | ||
| 43 | - } | ||
| 44 | - }); | ||
| 45 | - | ||
| 46 | - // 自动发起商城订单编号 | ||
| 47 | - $.ajax({ | ||
| 48 | - url: server + "/app-api/shop/order/create", | ||
| 49 | - method: 'POST', | ||
| 50 | - success: function( result ) { | ||
| 51 | - if (result.code !== 0) { | ||
| 52 | - alert('创建商城订单失败,原因:' + result.msg) | ||
| 53 | - return; | ||
| 54 | - } | ||
| 55 | - shopOrderId = result.data.id; | ||
| 56 | - payOrderId = result.data.payOrderId; | ||
| 57 | - console.log("商城订单:" + shopOrderId) | ||
| 58 | - console.log("支付订单:" + payOrderId) | ||
| 59 | - } | ||
| 60 | - }) | ||
| 61 | - }) | ||
| 62 | - | ||
| 63 | - // 微信公众号 | ||
| 64 | - $( "#wx_pub").on( "click", function() { | ||
| 65 | - if (typeof WeixinJSBridge == "undefined") { | ||
| 66 | - // if (document.addEventListener) { | ||
| 67 | - // document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false); | ||
| 68 | - // } else if (document.attachEvent) { | ||
| 69 | - // document.attachEvent('WeixinJSBridgeReady', onBridgeReady); | ||
| 70 | - // document.attachEvent('onWeixinJSBridgeReady', onBridgeReady); | ||
| 71 | - // } | ||
| 72 | - alert('微信支付,只支持在微信客户端中使用!'); | ||
| 73 | - return; | ||
| 74 | - } | ||
| 75 | - if (navigator.userAgent.indexOf('wechatdevtools') >= 0) { | ||
| 76 | - alert('微信支付,无法在微信开发者工具中使用!请使用微信客户端!'); | ||
| 77 | - return; | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - // 提交支付 | ||
| 81 | - // 参考 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6 文档 | ||
| 82 | - // 参考 https://segmentfault.com/a/1190000020704650 文档 | ||
| 83 | - $.ajax({ | ||
| 84 | - url: server + "/app-api/pay/order/submit", | ||
| 85 | - method: 'POST', | ||
| 86 | - dataType: "json", | ||
| 87 | - contentType: "application/json", | ||
| 88 | - data: JSON.stringify({ | ||
| 89 | - "id": payOrderId, | ||
| 90 | - "channelCode": 'wx_pub', | ||
| 91 | - "channelExtras": { | ||
| 92 | - "openid": openid | ||
| 93 | - } | ||
| 94 | - }), | ||
| 95 | - success: function( result ) { | ||
| 96 | - if (result.code !== 0) { | ||
| 97 | - alert('提交支付订单失败,原因:' + result.msg) | ||
| 98 | - return; | ||
| 99 | - } | ||
| 100 | - alert('点击确定,开始微信支付'); | ||
| 101 | - // 开始调用微信支付 | ||
| 102 | - let data = result.data.invokeResponse; | ||
| 103 | - wx.chooseWXPay({ | ||
| 104 | - timestamp: data.timeStamp, | ||
| 105 | - nonceStr: data.nonceStr, | ||
| 106 | - package: data.packageValue, | ||
| 107 | - signType: data.signType, | ||
| 108 | - paySign: data.paySign, | ||
| 109 | - success: function (res) { | ||
| 110 | - alert(JSON.stringify(res)); | ||
| 111 | - }, | ||
| 112 | - error: function(e) { | ||
| 113 | - alert(JSON.stringify(e)); | ||
| 114 | - } | ||
| 115 | - }); | ||
| 116 | - } | ||
| 117 | - }) | ||
| 118 | - }); | ||
| 119 | -</script> | ||
| 120 | -</html> |