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
59
60
61
62
63
64
65
66
67
package com.walker.pay.wechat.v2;
 
import com.walker.infrastructure.utils.StringUtils;
import com.walker.pay.Convertor;
import com.walker.pay.NotifyValue;
import com.walker.pay.PayChannel;
import com.walker.pay.wechat.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import java.util.Map;
 
public class NotifyOrderConvertor
//        extends AbstractJsonConvertor<NotifyValue<NotifyOrder>>
        implements Convertor<NotifyValue<NotifyOrder>> {
 
    protected final transient Logger logger = LoggerFactory.getLogger(getClass());
 
    @Override
    public NotifyValue<NotifyOrder> toGenericObject(Object data) {
        Map<String, String> paramMap = SignUtils.decodeXml(data.toString());
        String return_code = paramMap.get("return_code");
        if (StringUtils.isEmpty(return_code)) {
            throw new IllegalArgumentException("[wxPayNotify]调用参数错误:return_code不存在");
        }
 
        NotifyValue<NotifyOrder> notifyValue = new NotifyValue<>();
 
        String resultCode = paramMap.get("result_code");
        if(return_code.equals(Constants.CODE_SUCCESS) && resultCode != null && resultCode.equals(Constants.CODE_SUCCESS)){
            logger.debug("...........接收到微信通知:" + paramMap);
            notifyValue.setStatus(true);
            notifyValue.setSource(data);
            notifyValue.setOrderId(paramMap.get("out_trade_no"));
            notifyValue.setCreateTime(paramMap.get("time_end"));
            notifyValue.setTradeNo(paramMap.get("transaction_id"));
            notifyValue.setBuyerId(paramMap.get("openid"));
            notifyValue.setDataType("test");
            // 通知id就是微信订单ID,暂时这样。
            notifyValue.setId(notifyValue.getTradeNo());
            notifyValue.setPayChannel(PayChannel.WechatPay);
 
            // 支付类型,2023-08-30
            if(paramMap.containsKey("trade_type")){
                String tradeType = paramMap.get("trade_type");
//                if(tradeType.equals(Constants.PAY_TYPE_H5)){
//                    notifyValue.setPayChannel(PayC);
//                }
                notifyValue.setTradeType(tradeType);
            }
 
            NotifyOrder notifyOrder = new NotifyOrder();
            notifyOrder.setTotalMoney(Long.parseLong(paramMap.get("total_fee")));
            notifyOrder.setOpenId(notifyValue.getBuyerId());
            notifyOrder.setDeviceInfo(paramMap.get("device_info"));
            notifyOrder.setAttach(paramMap.get("attach"));
 
            notifyValue.setData(notifyOrder);
        }
        return notifyValue;
    }
 
//    @Override
//    protected NotifyValue<NotifyOrder> transferTo(ObjectNode objectNode) {
//        return null;
//    }
}