shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
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
package com.walker.pay.allinpaycloud;
 
import com.walker.infrastructure.utils.JsonUtils;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.pay.Convertor;
import com.walker.pay.NotifyValue;
import com.walker.pay.ServiceProvider;
import com.walker.pay.allinpaycloud.util.TextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
/**
 * 通商云订单通知转换器实现。
 * @date 2023-02-26
 */
public class NotifyOrderConvertor implements Convertor<NotifyValue<?>> {
 
    protected final transient Logger logger = LoggerFactory.getLogger(getClass());
 
    @Override
    public NotifyValue<Object> toGenericObject(Object data) {
        if(!(data instanceof RequestNotify)){
            throw new IllegalArgumentException("通知类型必须是'RequestNotify'");
        }
        RequestNotify requestNotify = (RequestNotify)data;
        if(StringUtils.isEmpty(requestNotify.getBizContent())){
            throw new IllegalArgumentException("通商云支付通知,未接收到 bizContent 业务数据:" + requestNotify, null);
        }
 
        String decodeBizContent = TextUtils.decodeFormUrlParameter(requestNotify.getBizContent());
        logger.debug(decodeBizContent);
 
        NotifyValue<Object> notifyValue = new NotifyValue<>();
        notifyValue.setId(requestNotify.getNotifyId());
        notifyValue.setSource(data);
        notifyValue.setCreateTime(requestNotify.getNotifyTime());
        notifyValue.setDataType(requestNotify.getNotifyType());
 
        try {
            NotifyOrder notifyOrder = JsonUtils.jsonStringToObject(decodeBizContent, NotifyOrder.class);
            notifyValue.setBuyerId(notifyOrder.getBuyerBizUserId());
            notifyValue.setOrderId(notifyOrder.getBizOrderNo());
            notifyValue.setTradeNo(notifyOrder.getOrderNo());
//            notifyValue.setVersion(orderNotifyInfo.get);
            notifyValue.setServiceProvider(ServiceProvider.AllinPayCloud);
            String payStatusValue = notifyOrder.getStatus();
            if(payStatusValue.equals(Constants.SUB_CODE_OK)){
                logger.debug("通知支付成功: " + notifyOrder);
                notifyValue.setStatus(true);
            }
            notifyValue.setData(notifyOrder);
            return notifyValue;
 
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}