mitao
2025-11-20 cac9cdf5a3d095e7ed6a77bbd263e3b401d1147b
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package com.stylefeng.guns.modular.huifu.biz;
 
import cn.hutool.core.date.DateUtil;
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.RequestSeqUtil;
import com.stylefeng.guns.modular.account.req.UserWithdrawalReq;
import com.stylefeng.guns.modular.huifu.properties.HuiFuProperties;
import com.stylefeng.guns.modular.system.model.UserWithdrawal;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 斗拱进件业务
 * @author mitao
 * @date 2025/11/14
 */
@Slf4j
@Component
public class DouGongBasicDataBiz {
    @Autowired
    private HuiFuProperties huiFuProperties;
 
    /**
     * 个人用户基本信息开户
     * @return
     * @throws Exception
     */
    public Map<String, Object> userBasicDataIndv(UserWithdrawal userWithdrawal) throws Exception {
        // 1. 数据初始化,填入对应的商户配置
        MerConfig merConfig = new MerConfig();
        merConfig.setProcutId(huiFuProperties.getProductId());
        merConfig.setSysId(huiFuProperties.getSysId());
        merConfig.setRsaPrivateKey(huiFuProperties.getRsaPrivateKey());
        merConfig.setRsaPublicKey(huiFuProperties.getRsaPublicKey());
        BasePay.initWithMerConfig(merConfig);
        // 2.组装请求参数
        Map<String, Object> paramsInfo = new HashMap<>();
        // 请求流水号(动态生成,确保唯一性)
        paramsInfo.put("req_seq_id", RequestSeqUtil.generateForHuiFu());
        // 请求日期
        paramsInfo.put("req_date", DateUtil.format(new Date(),"yyyyMMdd"));
        // 个人证件类型
        paramsInfo.put("cert_type", "00");
        String[] certificateExpireDateArr = userWithdrawal.getCertificateExpireTime().split(",");
        String startDateStr = certificateExpireDateArr[0];
        // 个人证件有效期开始日期
        paramsInfo.put("cert_begin_date", startDateStr.replace("-", ""));
        // 个人证件有效期截止日期
        String endDateStr = certificateExpireDateArr[1];
        if (!"长期".equals(endDateStr)) {
            String formatEndDate = endDateStr.replace("-", "");
            paramsInfo.put("cert_end_date", formatEndDate);
            // 个人证件有效期类型
            paramsInfo.put("cert_validity_type", "0");
        }else {
            // 个人证件有效期类型
            paramsInfo.put("cert_validity_type", "1");
        }
        // 手机号
        paramsInfo.put("mobile_no", userWithdrawal.getPhone());
        // 个人姓名
        paramsInfo.put("name", userWithdrawal.getOpenAccountName());
        // 个人证件号码
        paramsInfo.put("cert_no", userWithdrawal.getCertificateCode());
        // 管理员账号
        paramsInfo.put("login_name", userWithdrawal.getPhone());
        // 是否发送短信标识
        paramsInfo.put("sms_send_flag", "Y");
        // 3. 发起API调用
        log.info("个人用户基本信息开户请求参数:{}", paramsInfo);
        Map<String, Object> response = BasePayRequest.requestBasePay("v2/user/basicdata/indv", paramsInfo, null, false);
        log.info("个人用户基本信息开户返回参数:{}", response);
        return response;
    }
    /**
     * 个人用户基本信息修改
     * @return
     * @throws Exception
     */
    public Map<String, Object> userBasicDataIndvModify(UserWithdrawal userWithdrawal) throws Exception {
        // 1. 数据初始化,填入对应的商户配置
        MerConfig merConfig = new MerConfig();
        merConfig.setProcutId(huiFuProperties.getProductId());
        merConfig.setSysId(huiFuProperties.getSysId());
        merConfig.setRsaPrivateKey(huiFuProperties.getRsaPrivateKey());
        merConfig.setRsaPublicKey(huiFuProperties.getRsaPublicKey());
        BasePay.initWithMerConfig(merConfig);
        // 2.组装请求参数
        Map<String, Object> paramsInfo = new HashMap<>();
        // 请求流水号
        paramsInfo.put("req_seq_id", RequestSeqUtil.generateForHuiFu());
        // 请求日期
        paramsInfo.put("req_date", DateUtil.format(new Date(),"yyyyMMdd"));
        // 汇付客户Id
        paramsInfo.put("huifu_id", userWithdrawal.getHuifuId());
        String[] certificateExpireDateArr = userWithdrawal.getCertificateExpireTime().split(",");
        String startDateStr = certificateExpireDateArr[0];
        // 个人证件有效期开始日期
        paramsInfo.put("cert_begin_date", startDateStr.replace("-", ""));
        // 个人证件有效期截止日期
        String endDateStr = certificateExpireDateArr[1];
        if (!"长期".equals(endDateStr)) {
            String formatEndDate = endDateStr.replace("-", "");
            paramsInfo.put("cert_end_date", formatEndDate);
            // 个人证件有效期类型
            paramsInfo.put("cert_validity_type", "0");
        }else {
            // 个人证件有效期类型
            paramsInfo.put("cert_validity_type", "1");
        }
        // 手机号
        paramsInfo.put("mobile_no", userWithdrawal.getPhone());
        log.info("个人用户基本信息修改返回参数:{}", paramsInfo);
        // 3. 发起API调用
        Map<String, Object> response = BasePayRequest.requestBasePay("v2/user/basicdata/indv/modify", paramsInfo, null, false);
        log.info("个人用户基本信息修改返回参数:{}", response);
        return response;
    }
    /**
     * 用户业务入驻
     * @return
     * @throws Exception
     */
    public Map<String, Object> userBusinessOpen(UserWithdrawal userWithdrawal) throws Exception {
        // 1. 数据初始化,填入对应的商户配置
        MerConfig merConfig = new MerConfig();
        merConfig.setProcutId(huiFuProperties.getProductId());
        merConfig.setSysId(huiFuProperties.getSysId());
        merConfig.setRsaPrivateKey(huiFuProperties.getRsaPrivateKey());
        merConfig.setRsaPublicKey(huiFuProperties.getRsaPublicKey());
        BasePay.initWithMerConfig(merConfig);
        // 2.组装请求参数
        Map<String, Object> paramsInfo = new HashMap<>();
        // 汇付ID
        paramsInfo.put("huifu_id", userWithdrawal.getHuifuId());
        // 请求流水号
        paramsInfo.put("req_seq_id", RequestSeqUtil.generateForHuiFu());
        // 请求日期
        paramsInfo.put("req_date", DateUtil.format(new Date(),"yyyyMMdd"));
        // 渠道商/商户汇付Id
        paramsInfo.put("upper_huifu_id", huiFuProperties.getUpperHuifuId());
        //// 结算信息配置
        //paramsInfo.put("settle_config", "{\"settle_cycle\":\"D1\",\"min_amt\":\"0.01\",\"remained_amt\":\"10.00\",\"settle_abstract\":\"结算摘要\",\"out_settle_flag\":\"2\",\"settle_batch_no\":\"300\",\"fixed_ratio\":\"2\"}");
        // 结算卡信息
        JSONObject cardInfo = new JSONObject();
        cardInfo.put("card_type", "1");
        cardInfo.put("card_name", userWithdrawal.getOpenAccountName());
        cardInfo.put("card_no", userWithdrawal.getBankCardCode());
        cardInfo.put("prov_id", userWithdrawal.getBankCardProvinceCode());
        cardInfo.put("area_id", userWithdrawal.getBankCardCityCode());
        cardInfo.put("cert_type", "00");
        cardInfo.put("cert_no", userWithdrawal.getCertificateCode());
        String[] certificateExpireDateArr = userWithdrawal.getCertificateExpireTime().split(",");
        String startDateStr = certificateExpireDateArr[0];
        // 个人证件有效期开始日期
        cardInfo.put("cert_begin_date", startDateStr.replace("-", ""));
        // 个人证件有效期截止日期
        String endDateStr = certificateExpireDateArr[1];
        if (!"长期".equals(endDateStr)) {
            String formatEndDate = endDateStr.replace("-", "");
            cardInfo.put("cert_end_date", formatEndDate);
            // 个人证件有效期类型
            cardInfo.put("cert_validity_type", "0");
        }else {
            // 个人证件有效期类型
            cardInfo.put("cert_validity_type", "1");
        }
        paramsInfo.put("card_info", cardInfo.toJSONString());
        log.info("用户业务入驻返回参数:{}", paramsInfo);
        // 3. 发起API调用
        Map<String, Object> response = BasePayRequest.requestBasePay("v2/user/busi/open", paramsInfo, null, false);;
        log.info("用户业务入驻返回参数:{}", response);
        return response;
    }
    /**
     * 用户业务入驻
     * @return
     * @throws Exception
     */
    public Map<String, Object> userBusinessOpenModify(UserWithdrawal userWithdrawal) throws Exception {
        // 1. 数据初始化,填入对应的商户配置
        MerConfig merConfig = new MerConfig();
        merConfig.setProcutId(huiFuProperties.getProductId());
        merConfig.setSysId(huiFuProperties.getSysId());
        merConfig.setRsaPrivateKey(huiFuProperties.getRsaPrivateKey());
        merConfig.setRsaPublicKey(huiFuProperties.getRsaPublicKey());
        BasePay.initWithMerConfig(merConfig);
        // 2.组装请求参数
        Map<String, Object> paramsInfo = new HashMap<>();
        // 汇付ID
        paramsInfo.put("huifu_id", userWithdrawal.getHuifuId());
        // 请求流水号
        paramsInfo.put("req_seq_id", RequestSeqUtil.generateForHuiFu());
        // 请求日期
        paramsInfo.put("req_date", DateUtil.format(new Date(),"yyyyMMdd"));
        // 渠道商/商户汇付Id
        paramsInfo.put("upper_huifu_id", huiFuProperties.getUpperHuifuId());
        // 结算卡信息
        JSONObject cardInfo = new JSONObject();
        cardInfo.put("card_type", "1");
        cardInfo.put("card_name", userWithdrawal.getBindAcctName());
        cardInfo.put("card_no", userWithdrawal.getBankCardCode());
        cardInfo.put("prov_id", userWithdrawal.getBankCardProvinceCode());
        cardInfo.put("area_id", userWithdrawal.getBankCardCityCode());
        cardInfo.put("cert_type", "00");
        cardInfo.put("cert_no", userWithdrawal.getCertificateCode());
        String[] certificateExpireDateArr = userWithdrawal.getCertificateExpireTime().split(",");
        String startDateStr = certificateExpireDateArr[0];
        // 个人证件有效期开始日期
        cardInfo.put("cert_begin_date", startDateStr.replace("-", ""));
        // 个人证件有效期截止日期
        String endDateStr = certificateExpireDateArr[1];
        if (!"长期".equals(endDateStr)) {
            String formatEndDate = endDateStr.replace("-", "");
            cardInfo.put("cert_end_date", formatEndDate);
            // 个人证件有效期类型
            cardInfo.put("cert_validity_type", "0");
        }else {
            // 个人证件有效期类型
            cardInfo.put("cert_validity_type", "1");
        }
        paramsInfo.put("card_info", cardInfo.toJSONString());
        log.info("用户业务入驻修改返回参数:{}", paramsInfo);
        // 3. 发起API调用
        Map<String, Object> response = BasePayRequest.requestBasePay("v2/user/busi/modify", paramsInfo, null, false);;
        log.info("用户业务入驻修改返回参数:{}", response);
        return response;
    }
}