liujie
2026-09-17 819124be8f16794d409a67f58d5257aef37d9b64
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package com.tourguide.common.huifu.biz;
 
import com.alibaba.fastjson.JSONObject;
import com.huifu.bspay.sdk.opps.core.net.BasePayRequest;
import com.tourguide.common.huifu.properties.HuiFuProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
 
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;
 
/** 斗拱主动取现和出金交易查询。 */
@Component
public class DouGongWithdrawBiz {
    private static final Logger log = LoggerFactory.getLogger(DouGongWithdrawBiz.class);
 
    private final HuiFuProperties huiFuProperties;
 
    public DouGongWithdrawBiz(HuiFuProperties huiFuProperties) {
        this.huiFuProperties = huiFuProperties;
    }
 
    public JSONObject encashment(BigDecimal cashAmt, String huifuId, String tokenNo,
                                  String requestSequence, String requestDate) {
        try {
            DouGongRequestSupport.initBasePay(huiFuProperties);
            Map<String, Object> params = new HashMap<>();
            params.put("req_date", requestDate);
            params.put("req_seq_id", requestSequence);
            params.put("cash_amt", cashAmt.setScale(2, RoundingMode.HALF_UP).toString());
            params.put("huifu_id", huifuId);
            params.put("into_acct_date_type", "D1");
            params.put("token_no", tokenNo);
            params.put("enchashment_channel", "00");
            params.put("notify_url", callbackBaseUrl() + "/base/dougong/encashment");
            log.info("调用斗拱取现接口,reqSeqId={},huifuId={},cashAmt={}",
                    requestSequence, huifuId, cashAmt);
            return json(BasePayRequest.requestBasePay(
                    "v2/trade/settlement/encashment", params, null, false));
        } catch (Exception exception) {
            log.error("调用斗拱取现接口异常,reqSeqId={},原因={}",
                    requestSequence, exception.getMessage(), exception);
            return error(exception.getMessage());
        }
    }
 
    public JSONObject query(String huifuId, String requestDate, String requestSequence) {
        return query(huifuId, requestDate, requestSequence, null);
    }
 
    /** 取现查询同时支持原请求流水号和汇付全局流水号,便于补偿对账。 */
    public JSONObject query(String huifuId, String requestDate, String requestSequence,
                            String hfSequence) {
        try {
            DouGongRequestSupport.initBasePay(huiFuProperties);
            Map<String, Object> params = new HashMap<>();
            params.put("huifu_id", huifuId);
            params.put("org_req_date", requestDate);
            params.put("org_req_seq_id", requestSequence);
            if (StringUtils.hasText(hfSequence)) {
                params.put("org_hf_seq_id", hfSequence.trim());
            }
            return json(BasePayRequest.requestBasePay(
                    "v2/trade/settlement/query", params, null, false));
        } catch (Exception exception) {
            log.warn("查询斗拱取现状态异常,reqSeqId={},原因={}", requestSequence, exception.getMessage());
            return error(exception.getMessage());
        }
    }
 
    private JSONObject json(Map<String, Object> response) {
        return response == null ? null : JSONObject.parseObject(JSONObject.toJSONString(response));
    }
 
    private JSONObject error(String message) {
        JSONObject result = new JSONObject();
        result.put("code", "9999");
        result.put("msg", message == null ? "斗拱服务调用异常" : message);
        result.put("success", false);
        return result;
    }
 
    private String callbackBaseUrl() {
        String value = huiFuProperties.getCallbackPath().trim();
        while (value.endsWith("/")) value = value.substring(0, value.length() - 1);
        return value;
    }
}