liujie
2025-11-27 8e1187bffe5f9e4e94ff8b470735db03688b9150
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
package com.stylefeng.guns.modular.huifu.biz;
 
import com.alibaba.fastjson.JSONObject;
import com.huifu.bspay.sdk.opps.core.BasePay;
import com.huifu.bspay.sdk.opps.core.config.MerConfig;
import com.huifu.bspay.sdk.opps.core.net.BasePayRequest;
import com.stylefeng.guns.core.util.DateUtil;
import com.stylefeng.guns.modular.huifu.properties.HuiFuProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
 
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 斗拱提现业务
 * @author mitao
 * @date 2025/11/21
 */
@Slf4j
@Component
public class DouGongRefundBiz {
    @Autowired
    private HuiFuProperties huiFuProperties;
 
    @Value("${callbackPath}")
    private String callbackPath;
 
 
    /**
     * 交易退款接口
     *
     * @param reqSeqId 请求流水号,同一huifu_id下当天唯一
     * @param ordAmt 申请退款金额,单位元
     * @param orgReqDate 原交易请求日期,格式yyyyMMdd
     * @param orgReqSeqId 原交易请求流水号(三选一)
     * @param type 类型 1:小件物流;2:跨城出行
     * @return 请求结果
     */
    public Map<String, Object> refund(String reqSeqId, BigDecimal ordAmt, String orgReqDate, String orgReqSeqId, Integer type) throws Exception {
        log.info("开始调用斗拱退款接口, 退款金额: {}",  ordAmt);
        // 1. 数据初始化,填入对应的商户配置
        MerConfig merConfig = new MerConfig();
        merConfig.setProcutId(huiFuProperties.getProductId());
        merConfig.setSysId(huiFuProperties.getSysId());
        merConfig.setRsaPrivateKey(huiFuProperties.getRsaPrivateKey());
        merConfig.setRsaPublicKey(huiFuProperties.getRsaPublicKey());
        BasePay.initWithMerConfig(merConfig);
        // 构建业务参数data
        // 2.组装请求参数
        Map<String, Object> data = new HashMap<>();
        data.put("req_date", DateUtil.format(new Date(),"yyyyMMdd"));
        data.put("req_seq_id", reqSeqId);
        data.put("huifu_id", huiFuProperties.getSysId());
        data.put("ord_amt", ordAmt.setScale(2, RoundingMode.HALF_UP).toString());
        data.put("org_req_date", orgReqDate);
        // 三选一参数:org_hf_seq_id,org_party_order_id,org_req_seq_id
        data.put("org_req_seq_id", orgReqSeqId);
        String notifyUrl = type.equals(1) ? "/base/dougong/refund-logistics" : "/base/dougong/refund-crosscity";
        data.put("notify_url", callbackPath + notifyUrl);
 
        // 发送HTTP请求 - POST JSON格式
        Map<String, Object> response = BasePayRequest.requestBasePay("v4/trade/payment/scanpay/refund", data, null, false);
        log.info("斗拱退款接口响应内容: {}", JSONObject.toJSONString(response));
        return response;
    }
}