liujie
2026-07-30 fc767bf18e262b724c78b5f860b6d908d4993dcb
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
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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 斗拱退款业务。
 *
 * 备注:该类只发起斗拱退款请求,退款成功后的本地订单退款状态应由退款回调验签后幂等更新。
 */
@Component
public class DouGongRefundBiz {
    private static final Logger log = LoggerFactory.getLogger(DouGongRefundBiz.class);
 
    @Autowired
    private HuiFuProperties huiFuProperties;
 
    /**
     * 交易退款接口
     *
     * @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);
        DouGongRequestSupport.initBasePay(huiFuProperties);
        Map<String, Object> data = new HashMap<>();
        data.put("req_date", DouGongRequestSupport.todayForHuiFu());
        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_req_seq_id。
        data.put("org_req_seq_id", orgReqSeqId);
        String notifyUrl = Integer.valueOf(1).equals(type) ? "/base/dougong/refund-logistics" : "/base/dougong/refund-crosscity";
        data.put("notify_url", huiFuProperties.getCallbackPath() + notifyUrl);
 
        Map<String, Object> response = BasePayRequest.requestBasePay("v4/trade/payment/scanpay/refund", data, null, false);
        log.info("斗拱退款接口响应内容: {}", JSONObject.toJSONString(response));
        return response;
    }
}