mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
pay:修复单元测试报错
This commit is contained in:
parent
7bff98b658
commit
fc2d30cfaf
@ -10,6 +10,8 @@ import javax.validation.constraints.NotNull;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 转账单创建 Request DTO
|
||||||
|
*
|
||||||
* @author jason
|
* @author jason
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@ -1 +0,0 @@
|
|||||||
package cn.iocoder.yudao.module.pay;
|
|
@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollectionUtil;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
||||||
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
|
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
|
||||||
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
||||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletPageReqVO;
|
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletPageReqVO;
|
||||||
@ -26,12 +25,10 @@ import javax.annotation.Resource;
|
|||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.enums.UserTypeEnum.MEMBER;
|
import static cn.iocoder.yudao.framework.common.enums.UserTypeEnum.MEMBER;
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
|
||||||
|
|
||||||
@Tag(name = "管理后台 - 用户钱包")
|
@Tag(name = "管理后台 - 用户钱包")
|
||||||
@RestController
|
@RestController
|
||||||
@ -50,6 +47,7 @@ public class PayWalletController {
|
|||||||
@Operation(summary = "获得用户钱包明细")
|
@Operation(summary = "获得用户钱包明细")
|
||||||
public CommonResult<PayWalletRespVO> getWallet(PayWalletUserReqVO reqVO) {
|
public CommonResult<PayWalletRespVO> getWallet(PayWalletUserReqVO reqVO) {
|
||||||
PayWalletDO wallet = payWalletService.getOrCreateWallet(reqVO.getUserId(), MEMBER.getValue());
|
PayWalletDO wallet = payWalletService.getOrCreateWallet(reqVO.getUserId(), MEMBER.getValue());
|
||||||
|
// TODO jason:如果为空,返回给前端只要 null 就可以了
|
||||||
MemberUserRespDTO memberUser = memberUserApi.getUser(reqVO.getUserId());
|
MemberUserRespDTO memberUser = memberUserApi.getUser(reqVO.getUserId());
|
||||||
String nickname = memberUser == null ? "" : memberUser.getNickname();
|
String nickname = memberUser == null ? "" : memberUser.getNickname();
|
||||||
String avatar = memberUser == null ? "" : memberUser.getAvatar();
|
String avatar = memberUser == null ? "" : memberUser.getAvatar();
|
||||||
@ -61,9 +59,8 @@ public class PayWalletController {
|
|||||||
@PreAuthorize("@ss.hasPermission('pay:wallet:query')")
|
@PreAuthorize("@ss.hasPermission('pay:wallet:query')")
|
||||||
public CommonResult<PageResult<PayWalletRespVO>> getWalletPage(@Valid PayWalletPageReqVO pageVO) {
|
public CommonResult<PageResult<PayWalletRespVO>> getWalletPage(@Valid PayWalletPageReqVO pageVO) {
|
||||||
if (StrUtil.isNotEmpty(pageVO.getNickname())) {
|
if (StrUtil.isNotEmpty(pageVO.getNickname())) {
|
||||||
Set<Long> userIds = CollectionUtils.convertSet(memberUserApi.getUserListByNickname(pageVO.getNickname()),
|
List<MemberUserRespDTO> users = memberUserApi.getUserListByNickname(pageVO.getNickname());
|
||||||
MemberUserRespDTO::getId);
|
pageVO.setUserIds(convertSet(users, MemberUserRespDTO::getId));
|
||||||
pageVO.setUserIds(userIds);
|
|
||||||
}
|
}
|
||||||
// TODO @jason:管理员也可以先查询下。。
|
// TODO @jason:管理员也可以先查询下。。
|
||||||
// 暂时支持查询 userType 会员类型。管理员类型还不知道使用场景
|
// 暂时支持查询 userType 会员类型。管理员类型还不知道使用场景
|
||||||
@ -71,8 +68,8 @@ public class PayWalletController {
|
|||||||
if (CollectionUtil.isEmpty(pageResult.getList())) {
|
if (CollectionUtil.isEmpty(pageResult.getList())) {
|
||||||
return success(new PageResult<>(pageResult.getTotal()));
|
return success(new PageResult<>(pageResult.getTotal()));
|
||||||
}
|
}
|
||||||
List<Long> userIds = convertList(pageResult.getList(), PayWalletDO::getUserId);
|
List<MemberUserRespDTO> users = memberUserApi.getUserList(convertList(pageResult.getList(), PayWalletDO::getUserId));
|
||||||
Map<Long, MemberUserRespDTO> userMap = convertMap(memberUserApi.getUserList(userIds),MemberUserRespDTO::getId);
|
Map<Long, MemberUserRespDTO> userMap = convertMap(users, MemberUserRespDTO::getId);
|
||||||
return success(PayWalletConvert.INSTANCE.convertPage(pageResult, userMap));
|
return success(PayWalletConvert.INSTANCE.convertPage(pageResult, userMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.pay.service.order;
|
|||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.PayClient;
|
import cn.iocoder.yudao.framework.pay.core.client.PayClient;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory;
|
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
|
import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
|
||||||
import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
|
import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
|
||||||
import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderDisplayModeEnum;
|
import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderDisplayModeEnum;
|
||||||
@ -67,8 +66,6 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
@Resource
|
@Resource
|
||||||
private PayOrderExtensionMapper orderExtensionMapper;
|
private PayOrderExtensionMapper orderExtensionMapper;
|
||||||
|
|
||||||
@MockBean
|
|
||||||
private PayClientFactory payClientFactory;
|
|
||||||
@MockBean
|
@MockBean
|
||||||
private PayProperties properties;
|
private PayProperties properties;
|
||||||
@MockBean
|
@MockBean
|
||||||
@ -351,7 +348,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
.thenReturn(channel);
|
.thenReturn(channel);
|
||||||
// mock 方法(client)
|
// mock 方法(client)
|
||||||
PayClient client = mock(PayClient.class);
|
PayClient client = mock(PayClient.class);
|
||||||
when(payClientFactory.getPayClient(eq(10L))).thenReturn(client);
|
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||||
// mock 方法()
|
// mock 方法()
|
||||||
PayOrderRespDTO unifiedOrderResp = randomPojo(PayOrderRespDTO.class, o ->
|
PayOrderRespDTO unifiedOrderResp = randomPojo(PayOrderRespDTO.class, o ->
|
||||||
o.setChannelErrorCode("001").setChannelErrorMsg("模拟异常"));
|
o.setChannelErrorCode("001").setChannelErrorMsg("模拟异常"));
|
||||||
@ -405,7 +402,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
.thenReturn(channel);
|
.thenReturn(channel);
|
||||||
// mock 方法(client)
|
// mock 方法(client)
|
||||||
PayClient client = mock(PayClient.class);
|
PayClient client = mock(PayClient.class);
|
||||||
when(payClientFactory.getPayClient(eq(10L))).thenReturn(client);
|
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||||
// mock 方法(支付渠道的调用)
|
// mock 方法(支付渠道的调用)
|
||||||
PayOrderRespDTO unifiedOrderResp = randomPojo(PayOrderRespDTO.class, o -> o.setChannelErrorCode(null).setChannelErrorMsg(null)
|
PayOrderRespDTO unifiedOrderResp = randomPojo(PayOrderRespDTO.class, o -> o.setChannelErrorCode(null).setChannelErrorMsg(null)
|
||||||
.setDisplayMode(PayOrderDisplayModeEnum.URL.getMode()).setDisplayContent("tudou"));
|
.setDisplayMode(PayOrderDisplayModeEnum.URL.getMode()).setDisplayContent("tudou"));
|
||||||
@ -463,7 +460,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
orderExtensionMapper.insert(orderExtension);
|
orderExtensionMapper.insert(orderExtension);
|
||||||
// mock 方法(PayClient 已支付)
|
// mock 方法(PayClient 已支付)
|
||||||
PayClient client = mock(PayClient.class);
|
PayClient client = mock(PayClient.class);
|
||||||
when(payClientFactory.getPayClient(eq(orderExtension.getChannelId()))).thenReturn(client);
|
when(channelService.getPayClient(eq(orderExtension.getChannelId()))).thenReturn(client);
|
||||||
when(client.getOrder(eq(orderExtension.getNo()))).thenReturn(randomPojo(PayOrderRespDTO.class,
|
when(client.getOrder(eq(orderExtension.getNo()))).thenReturn(randomPojo(PayOrderRespDTO.class,
|
||||||
o -> o.setStatus(PayOrderStatusEnum.SUCCESS.getStatus())));
|
o -> o.setStatus(PayOrderStatusEnum.SUCCESS.getStatus())));
|
||||||
|
|
||||||
@ -482,7 +479,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
orderExtensionMapper.insert(orderExtension);
|
orderExtensionMapper.insert(orderExtension);
|
||||||
// mock 方法(PayClient 已支付)
|
// mock 方法(PayClient 已支付)
|
||||||
PayClient client = mock(PayClient.class);
|
PayClient client = mock(PayClient.class);
|
||||||
when(payClientFactory.getPayClient(eq(orderExtension.getChannelId()))).thenReturn(client);
|
when(channelService.getPayClient(eq(orderExtension.getChannelId()))).thenReturn(client);
|
||||||
when(client.getOrder(eq(orderExtension.getNo()))).thenReturn(randomPojo(PayOrderRespDTO.class,
|
when(client.getOrder(eq(orderExtension.getNo()))).thenReturn(randomPojo(PayOrderRespDTO.class,
|
||||||
o -> o.setStatus(PayOrderStatusEnum.WAITING.getStatus())));
|
o -> o.setStatus(PayOrderStatusEnum.WAITING.getStatus())));
|
||||||
|
|
||||||
@ -639,7 +636,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
orderExtensionMapper.insert(orderExtension);
|
orderExtensionMapper.insert(orderExtension);
|
||||||
// 准备参数
|
// 准备参数
|
||||||
PayChannelDO channel = randomPojo(PayChannelDO.class, o -> o.setId(10L)
|
PayChannelDO channel = randomPojo(PayChannelDO.class, o -> o.setId(10L)
|
||||||
.setFeeRate(0.1D));
|
.setFeeRate(10D));
|
||||||
PayOrderRespDTO notify = randomPojo(PayOrderRespDTO.class,
|
PayOrderRespDTO notify = randomPojo(PayOrderRespDTO.class,
|
||||||
o -> o.setStatus(PayOrderStatusRespEnum.SUCCESS.getStatus())
|
o -> o.setStatus(PayOrderStatusRespEnum.SUCCESS.getStatus())
|
||||||
.setOutTradeNo("P110"));
|
.setOutTradeNo("P110"));
|
||||||
@ -656,7 +653,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
.setChannelId(10L).setChannelCode(channel.getCode())
|
.setChannelId(10L).setChannelCode(channel.getCode())
|
||||||
.setSuccessTime(notify.getSuccessTime()).setExtensionId(orderExtension.getId()).setNo(orderExtension.getNo())
|
.setSuccessTime(notify.getSuccessTime()).setExtensionId(orderExtension.getId()).setNo(orderExtension.getNo())
|
||||||
.setChannelOrderNo(notify.getChannelOrderNo()).setChannelUserId(notify.getChannelUserId())
|
.setChannelOrderNo(notify.getChannelOrderNo()).setChannelUserId(notify.getChannelUserId())
|
||||||
.setChannelFeeRate(0.1D).setChannelFeePrice(1);
|
.setChannelFeeRate(10D).setChannelFeePrice(1);
|
||||||
assertPojoEquals(order, orderMapper.selectOne(null),
|
assertPojoEquals(order, orderMapper.selectOne(null),
|
||||||
"updateTime", "updater");
|
"updateTime", "updater");
|
||||||
// 断言,调用
|
// 断言,调用
|
||||||
@ -874,7 +871,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
orderExtensionMapper.insert(orderExtension);
|
orderExtensionMapper.insert(orderExtension);
|
||||||
// mock 方法(PayClient)
|
// mock 方法(PayClient)
|
||||||
PayClient client = mock(PayClient.class);
|
PayClient client = mock(PayClient.class);
|
||||||
when(payClientFactory.getPayClient(eq(10L))).thenReturn(client);
|
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||||
// mock 方法(PayClient 异常)
|
// mock 方法(PayClient 异常)
|
||||||
when(client.getOrder(any())).thenThrow(new RuntimeException());
|
when(client.getOrder(any())).thenThrow(new RuntimeException());
|
||||||
|
|
||||||
@ -901,7 +898,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
orderExtensionMapper.insert(orderExtension);
|
orderExtensionMapper.insert(orderExtension);
|
||||||
// mock 方法(PayClient)
|
// mock 方法(PayClient)
|
||||||
PayClient client = mock(PayClient.class);
|
PayClient client = mock(PayClient.class);
|
||||||
when(payClientFactory.getPayClient(eq(10L))).thenReturn(client);
|
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||||
// mock 方法(PayClient 成功返回)
|
// mock 方法(PayClient 成功返回)
|
||||||
PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class,
|
PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class,
|
||||||
o -> o.setStatus(PayOrderStatusEnum.SUCCESS.getStatus()));
|
o -> o.setStatus(PayOrderStatusEnum.SUCCESS.getStatus()));
|
||||||
@ -935,7 +932,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
orderExtensionMapper.insert(orderExtension);
|
orderExtensionMapper.insert(orderExtension);
|
||||||
// mock 方法(PayClient)
|
// mock 方法(PayClient)
|
||||||
PayClient client = mock(PayClient.class);
|
PayClient client = mock(PayClient.class);
|
||||||
when(payClientFactory.getPayClient(eq(10L))).thenReturn(client);
|
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||||
// mock 方法(PayClient 成功返回)
|
// mock 方法(PayClient 成功返回)
|
||||||
PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class,
|
PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class,
|
||||||
o -> o.setStatus(PayOrderStatusEnum.CLOSED.getStatus()));
|
o -> o.setStatus(PayOrderStatusEnum.CLOSED.getStatus()));
|
||||||
@ -966,7 +963,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
orderExtensionMapper.insert(orderExtension);
|
orderExtensionMapper.insert(orderExtension);
|
||||||
// mock 方法(PayClient)
|
// mock 方法(PayClient)
|
||||||
PayClient client = mock(PayClient.class);
|
PayClient client = mock(PayClient.class);
|
||||||
when(payClientFactory.getPayClient(eq(10L))).thenReturn(client);
|
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
int count = orderService.expireOrder();
|
int count = orderService.expireOrder();
|
||||||
@ -1013,7 +1010,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
orderExtensionMapper.insert(orderExtension);
|
orderExtensionMapper.insert(orderExtension);
|
||||||
// mock 方法(PayClient)
|
// mock 方法(PayClient)
|
||||||
PayClient client = mock(PayClient.class);
|
PayClient client = mock(PayClient.class);
|
||||||
when(payClientFactory.getPayClient(eq(10L))).thenReturn(client);
|
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||||
// mock 方法(PayClient 退款返回)
|
// mock 方法(PayClient 退款返回)
|
||||||
PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class,
|
PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class,
|
||||||
o -> o.setStatus(PayOrderStatusEnum.REFUND.getStatus()));
|
o -> o.setStatus(PayOrderStatusEnum.REFUND.getStatus()));
|
||||||
@ -1047,7 +1044,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
orderExtensionMapper.insert(orderExtension);
|
orderExtensionMapper.insert(orderExtension);
|
||||||
// mock 方法(PayClient)
|
// mock 方法(PayClient)
|
||||||
PayClient client = mock(PayClient.class);
|
PayClient client = mock(PayClient.class);
|
||||||
when(payClientFactory.getPayClient(eq(10L))).thenReturn(client);
|
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||||
// mock 方法(PayClient 成功返回)
|
// mock 方法(PayClient 成功返回)
|
||||||
PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class,
|
PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class,
|
||||||
o -> o.setStatus(PayOrderStatusEnum.SUCCESS.getStatus()));
|
o -> o.setStatus(PayOrderStatusEnum.SUCCESS.getStatus()));
|
||||||
@ -1081,7 +1078,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
orderExtensionMapper.insert(orderExtension);
|
orderExtensionMapper.insert(orderExtension);
|
||||||
// mock 方法(PayClient)
|
// mock 方法(PayClient)
|
||||||
PayClient client = mock(PayClient.class);
|
PayClient client = mock(PayClient.class);
|
||||||
when(payClientFactory.getPayClient(eq(10L))).thenReturn(client);
|
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||||
// mock 方法(PayClient 关闭返回)
|
// mock 方法(PayClient 关闭返回)
|
||||||
PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class,
|
PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class,
|
||||||
o -> o.setStatus(PayOrderStatusEnum.CLOSED.getStatus()));
|
o -> o.setStatus(PayOrderStatusEnum.CLOSED.getStatus()));
|
||||||
|
@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.pay.service.refund;
|
|||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.PayClient;
|
import cn.iocoder.yudao.framework.pay.core.client.PayClient;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory;
|
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO;
|
import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO;
|
import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO;
|
||||||
import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
|
import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
|
||||||
@ -67,8 +66,6 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
@MockBean
|
@MockBean
|
||||||
private PayProperties payProperties;
|
private PayProperties payProperties;
|
||||||
@MockBean
|
@MockBean
|
||||||
private PayClientFactory payClientFactory;
|
|
||||||
@MockBean
|
|
||||||
private PayOrderService orderService;
|
private PayOrderService orderService;
|
||||||
@MockBean
|
@MockBean
|
||||||
private PayAppService appService;
|
private PayAppService appService;
|
||||||
@ -335,7 +332,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
when(channelService.validPayChannel(eq(1L))).thenReturn(channel);
|
when(channelService.validPayChannel(eq(1L))).thenReturn(channel);
|
||||||
// mock 方法(client)
|
// mock 方法(client)
|
||||||
PayClient client = mock(PayClient.class);
|
PayClient client = mock(PayClient.class);
|
||||||
when(payClientFactory.getPayClient(eq(10L))).thenReturn(client);
|
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||||
// mock 数据(refund 已存在)
|
// mock 数据(refund 已存在)
|
||||||
PayRefundDO refund = randomPojo(PayRefundDO.class, o ->
|
PayRefundDO refund = randomPojo(PayRefundDO.class, o ->
|
||||||
o.setAppId(1L).setMerchantRefundId("200"));
|
o.setAppId(1L).setMerchantRefundId("200"));
|
||||||
@ -367,7 +364,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
when(channelService.validPayChannel(eq(10L))).thenReturn(channel);
|
when(channelService.validPayChannel(eq(10L))).thenReturn(channel);
|
||||||
// mock 方法(client)
|
// mock 方法(client)
|
||||||
PayClient client = mock(PayClient.class);
|
PayClient client = mock(PayClient.class);
|
||||||
when(payClientFactory.getPayClient(eq(10L))).thenReturn(client);
|
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||||
// mock 方法(client 调用发生异常)
|
// mock 方法(client 调用发生异常)
|
||||||
when(client.unifiedRefund(any(PayRefundUnifiedReqDTO.class))).thenThrow(new RuntimeException());
|
when(client.unifiedRefund(any(PayRefundUnifiedReqDTO.class))).thenThrow(new RuntimeException());
|
||||||
|
|
||||||
@ -411,7 +408,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
when(channelService.validPayChannel(eq(10L))).thenReturn(channel);
|
when(channelService.validPayChannel(eq(10L))).thenReturn(channel);
|
||||||
// mock 方法(client)
|
// mock 方法(client)
|
||||||
PayClient client = mock(PayClient.class);
|
PayClient client = mock(PayClient.class);
|
||||||
when(payClientFactory.getPayClient(eq(10L))).thenReturn(client);
|
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||||
// mock 方法(client 成功)
|
// mock 方法(client 成功)
|
||||||
PayRefundRespDTO refundRespDTO = randomPojo(PayRefundRespDTO.class);
|
PayRefundRespDTO refundRespDTO = randomPojo(PayRefundRespDTO.class);
|
||||||
when(client.unifiedRefund(argThat(unifiedReqDTO -> {
|
when(client.unifiedRefund(argThat(unifiedReqDTO -> {
|
||||||
@ -668,7 +665,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
refundMapper.insert(refund);
|
refundMapper.insert(refund);
|
||||||
// mock 方法(client)
|
// mock 方法(client)
|
||||||
PayClient client = mock(PayClient.class);
|
PayClient client = mock(PayClient.class);
|
||||||
when(payClientFactory.getPayClient(eq(10L))).thenReturn(client);
|
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||||
// mock 方法(client 返回指定状态)
|
// mock 方法(client 返回指定状态)
|
||||||
PayRefundRespDTO respDTO = randomPojo(PayRefundRespDTO.class, o -> o.setStatus(status));
|
PayRefundRespDTO respDTO = randomPojo(PayRefundRespDTO.class, o -> o.setStatus(status));
|
||||||
when(client.getRefund(eq("P110"), eq("R220"))).thenReturn(respDTO);
|
when(client.getRefund(eq("P110"), eq("R220"))).thenReturn(respDTO);
|
||||||
@ -690,7 +687,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest {
|
|||||||
refundMapper.insert(refund);
|
refundMapper.insert(refund);
|
||||||
// mock 方法(client)
|
// mock 方法(client)
|
||||||
PayClient client = mock(PayClient.class);
|
PayClient client = mock(PayClient.class);
|
||||||
when(payClientFactory.getPayClient(eq(10L))).thenReturn(client);
|
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||||
// mock 方法(client 抛出异常)
|
// mock 方法(client 抛出异常)
|
||||||
when(client.getRefund(eq("P110"), eq("R220"))).thenThrow(new RuntimeException());
|
when(client.getRefund(eq("P110"), eq("R220"))).thenThrow(new RuntimeException());
|
||||||
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
DKOvVzFP7vPwwHx2
|
|
@ -1,13 +0,0 @@
|
|||||||
## 微信公众号
|
|
||||||
|
|
||||||
参考文章:https://www.yuque.com/docs/share/0e2966dd-89f8-4b69-980d-b876168725df
|
|
||||||
|
|
||||||
① 访问 social-login.html 选择【微信公众号】
|
|
||||||
|
|
||||||
② 微信公众号授权完成后,跳转回 social-login2.html,输入手机号 + 密码,进行绑定
|
|
||||||
|
|
||||||
## 微信小程序
|
|
||||||
|
|
||||||
参考文章:https://www.yuque.com/docs/share/88e3d30a-6830-45fc-8c25-dae485aef3aa
|
|
||||||
|
|
||||||
① 暂时使用 mini-program-test 项目
|
|
@ -1,120 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
|
|
||||||
<title>支付测试页</title>
|
|
||||||
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
|
|
||||||
<script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div>点击如下按钮,发起支付的测试</div>
|
|
||||||
<div>
|
|
||||||
<button id="wx_pub">微信公众号</button>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
<script>
|
|
||||||
let shopOrderId = undefined;
|
|
||||||
let payOrderId = undefined;
|
|
||||||
let server = 'http://127.0.0.1:48080';
|
|
||||||
// let server = 'http://niubi.natapp1.cc';
|
|
||||||
// TODO openid
|
|
||||||
let openid = "ockUAwIZ-0OeMZl9ogcZ4ILrGba0";
|
|
||||||
$(function() {
|
|
||||||
// 获得 JsapiTicket
|
|
||||||
// 参考 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html 文档
|
|
||||||
$.ajax({
|
|
||||||
url: server + "/app-api/wx/mp/create-jsapi-signature?url=" + document.location.href,
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'tenant-id': 1
|
|
||||||
},
|
|
||||||
success: function( result ) {
|
|
||||||
if (result.code !== 0) {
|
|
||||||
alert('获取 JsapiTicket 失败,原因:' + result.msg)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var jsapiTicket = result.data;
|
|
||||||
jsapiTicket.jsApiList = ['chooseWXPay'];
|
|
||||||
jsapiTicket.debug = false;
|
|
||||||
|
|
||||||
// 初始化 JS
|
|
||||||
wx.config(jsapiTicket);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 自动发起商城订单编号
|
|
||||||
$.ajax({
|
|
||||||
url: server + "/app-api/shop/order/create",
|
|
||||||
method: 'POST',
|
|
||||||
success: function( result ) {
|
|
||||||
if (result.code !== 0) {
|
|
||||||
alert('创建商城订单失败,原因:' + result.msg)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
shopOrderId = result.data.id;
|
|
||||||
payOrderId = result.data.payOrderId;
|
|
||||||
console.log("商城订单:" + shopOrderId)
|
|
||||||
console.log("支付订单:" + payOrderId)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
// 微信公众号
|
|
||||||
$( "#wx_pub").on( "click", function() {
|
|
||||||
if (typeof WeixinJSBridge == "undefined") {
|
|
||||||
// if (document.addEventListener) {
|
|
||||||
// document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
|
|
||||||
// } else if (document.attachEvent) {
|
|
||||||
// document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
|
|
||||||
// document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
|
|
||||||
// }
|
|
||||||
alert('微信支付,只支持在微信客户端中使用!');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (navigator.userAgent.indexOf('wechatdevtools') >= 0) {
|
|
||||||
alert('微信支付,无法在微信开发者工具中使用!请使用微信客户端!');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 提交支付
|
|
||||||
// 参考 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6 文档
|
|
||||||
// 参考 https://segmentfault.com/a/1190000020704650 文档
|
|
||||||
$.ajax({
|
|
||||||
url: server + "/app-api/pay/order/submit",
|
|
||||||
method: 'POST',
|
|
||||||
dataType: "json",
|
|
||||||
contentType: "application/json",
|
|
||||||
data: JSON.stringify({
|
|
||||||
"id": payOrderId,
|
|
||||||
"channelCode": 'wx_pub',
|
|
||||||
"channelExtras": {
|
|
||||||
"openid": openid
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
success: function( result ) {
|
|
||||||
if (result.code !== 0) {
|
|
||||||
alert('提交支付订单失败,原因:' + result.msg)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
alert('点击确定,开始微信支付');
|
|
||||||
// 开始调用微信支付
|
|
||||||
let data = result.data.invokeResponse;
|
|
||||||
wx.chooseWXPay({
|
|
||||||
timestamp: data.timeStamp,
|
|
||||||
nonceStr: data.nonceStr,
|
|
||||||
package: data.packageValue,
|
|
||||||
signType: data.signType,
|
|
||||||
paySign: data.paySign,
|
|
||||||
success: function (res) {
|
|
||||||
alert(JSON.stringify(res));
|
|
||||||
},
|
|
||||||
error: function(e) {
|
|
||||||
alert(JSON.stringify(e));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue
Block a user