add
yj
2024-12-05 b9900893177c78fc559223521fe839aa21000017
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.iotechn.unimall.biz.util;
 
import com.dobbinsoft.fw.core.exception.BizServiceException;
import com.dobbinsoft.fw.core.exception.ServiceException;
import com.dobbinsoft.fw.core.util.SessionUtil;
import com.dobbinsoft.fw.pay.enums.PayChannelType;
import com.dobbinsoft.fw.pay.enums.PayPlatformType;
import com.dobbinsoft.fw.pay.model.request.MatrixPayUnifiedOrderRequest;
import com.dobbinsoft.fw.support.properties.FwAliAppProperties;
import com.dobbinsoft.fw.support.properties.FwWxAppProperties;
import com.iotechn.unimall.data.dto.AdminDTO;
import com.iotechn.unimall.data.dto.UserDTO;
import com.iotechn.unimall.data.exception.ExceptionDefinition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
@Component
public class PaySelector {
 
    @Autowired
    private FwWxAppProperties fwWxAppProperties;
 
    @Autowired
    private FwAliAppProperties fwAliAppProperties;
 
    @Autowired
    private SessionUtil<UserDTO, AdminDTO> sessionUtil;
 
    public void packPayChannel(MatrixPayUnifiedOrderRequest orderRequest, int payPlatform, String payChannel) throws ServiceException {
// 设置支付请求基本信息
        orderRequest.setPayPlatform(PayPlatformType.getByCode(payPlatform));
        if (PayPlatformType.MP.getCode() == payPlatform) {
            if (PayChannelType.WX.getCode().equals(payChannel)) {
                orderRequest.setPayChannel(PayChannelType.WX);
                orderRequest.setAppid(fwWxAppProperties.getMiniAppId());
                orderRequest.setOpenid(sessionUtil.getUser().getWxMpOpenId());
            } else if (PayChannelType.ALI.getCode().equals(payChannel)) {
                orderRequest.setPayChannel(PayChannelType.ALI);
                orderRequest.setAppid(fwAliAppProperties.getMiniAppId());
                orderRequest.setOpenid(sessionUtil.getUser().getAliMpOpenId());
            }
        } else if (PayPlatformType.APP.getCode() == payPlatform) {
            if (PayChannelType.WX.getCode().equals(payChannel)) {
                orderRequest.setPayChannel(PayChannelType.WX);
                orderRequest.setAppid(fwWxAppProperties.getAppId());
                orderRequest.setOpenid(sessionUtil.getUser().getWxAppOpenId());
            } else if (PayChannelType.ALI.getCode().equals(payChannel)) {
                orderRequest.setPayChannel(PayChannelType.ALI);
                orderRequest.setAppid(fwAliAppProperties.getAppId());
            }
        } else if (PayPlatformType.WAP.getCode() == payPlatform) {
            if (PayChannelType.WX.getCode().equals(payChannel)) {
                orderRequest.setAppid(fwWxAppProperties.getH5AppId());
                orderRequest.setPayChannel(PayChannelType.WX);
                orderRequest.setOpenid(sessionUtil.getUser().getWxH5OpenId());
            } else if (PayChannelType.ALI.getCode().equals(payChannel)) {
                orderRequest.setAppid(fwAliAppProperties.getWapAppId());
                orderRequest.setPayChannel(PayChannelType.ALI);
            }
        } else {
            throw new BizServiceException(ExceptionDefinition.ORDER_LOGIN_TYPE_NOT_SUPPORT_WXPAY);
        }
    }
 
}