package com.stylefeng.guns.modular.huifu.biz;
|
|
import com.alibaba.fastjson.JSONArray;
|
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.core.util.RequestSeqUtil;
|
import com.stylefeng.guns.modular.huifu.properties.HuiFuProperties;
|
import com.stylefeng.guns.modular.system.model.TEnterpriseWithdrawal;
|
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.math.BigDecimal;
|
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("sms_send_flag", "1");
|
// 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> userBasicDataEnt(TEnterpriseWithdrawal tEnterpriseWithdrawal) 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("reg_name", tEnterpriseWithdrawal.getBusinessLicenseCompanyName());
|
// 营业执照编号
|
paramsInfo.put("license_code", tEnterpriseWithdrawal.getBusinessLicenseCode());
|
String[] businessExpireTimeArr = tEnterpriseWithdrawal.getBusinessExpireTime().split(",");
|
String startDateStr = businessExpireTimeArr[0];
|
// 证照有效期起始日期
|
paramsInfo.put("license_begin_date", startDateStr.replace("-", ""));
|
// 照有效期结束日期日期格式:yyyyMMdd; 非长期有效时必填;<font color="green">示例值:20320905</font>
|
String endDateStr = businessExpireTimeArr[1];
|
if (!"长期".equals(endDateStr)) {
|
String formatEndDate = endDateStr.replace("-", "");
|
paramsInfo.put("license_end_date", formatEndDate);
|
// 证照有效期类型
|
paramsInfo.put("license_validity_type", "0");
|
} else {
|
// 证照有效期类型
|
paramsInfo.put("license_validity_type", "1");
|
}
|
// 注册地址(省)
|
paramsInfo.put("reg_prov_id", tEnterpriseWithdrawal.getBusinessLicenseProvinceCode());
|
// 注册地址(市)
|
paramsInfo.put("reg_area_id", tEnterpriseWithdrawal.getBusinessLicenseCityCode());
|
// 注册地址(区)
|
paramsInfo.put("reg_district_id", tEnterpriseWithdrawal.getBusinessLicenseDistrictCode());
|
// 注册地址(详细信息)
|
paramsInfo.put("reg_detail", tEnterpriseWithdrawal.getBusinessLicenseAddress());
|
// 法人姓名
|
paramsInfo.put("legal_name", tEnterpriseWithdrawal.getCorporateIdCardReversePicture());
|
// 法人证件类型
|
paramsInfo.put("legal_cert_type", tEnterpriseWithdrawal.getCorporateCertificateType().equals(1) ? "00" : "11");
|
// 法人证件号码
|
paramsInfo.put("legal_cert_no", tEnterpriseWithdrawal.getCertificateCode());
|
String[] certificateExpireTimeArr = tEnterpriseWithdrawal.getCertificateExpireTime().split(",");
|
String expireStartDateStr = certificateExpireTimeArr[0];
|
// 法人证件有效期开始日期
|
paramsInfo.put("legal_cert_begin_date", expireStartDateStr.replace("-", ""));
|
// 法人证件有效期截止日期日期格式:yyyyMMdd; 非长期有效时必填,长期有效为空;<font color="green">示例值:20320905</font>
|
String expireEndDateStr = certificateExpireTimeArr[1];
|
if (!"长期".equals(endDateStr)) {
|
String formatEndDate = expireEndDateStr.replace("-", "");
|
paramsInfo.put("legal_cert_end_date", formatEndDate);
|
// 法人证件有效期类型
|
paramsInfo.put("legal_cert_validity_type", "0");
|
} else {
|
// 法人证件有效期类型
|
paramsInfo.put("legal_cert_validity_type", "1");
|
}
|
// 联系人姓名
|
paramsInfo.put("contact_name", tEnterpriseWithdrawal.getCorporateName());
|
// 联系人手机号
|
paramsInfo.put("contact_mobile", tEnterpriseWithdrawal.getCorporatePhone());
|
// 管理员账号如需短信通知则必填;<font color="green">示例值:Lg20220222013747</font>
|
paramsInfo.put("login_name", tEnterpriseWithdrawal.getCorporatePhone());
|
// 经营简称
|
paramsInfo.put("short_name", tEnterpriseWithdrawal.getMerchantAbbreviation());
|
// 是否发送短信标识
|
paramsInfo.put("sms_send_flag", "Y");
|
// 3. 发起API调用
|
Map<String, Object> response = BasePayRequest.requestBasePay("v2/user/basicdata/ent", paramsInfo, null, false);
|
log.info("企业用户基本信息开户返回参数:{}", JSONObject.toJSONString(response));
|
return response;
|
}
|
|
/**
|
* 企业用户基本信息修改
|
*
|
* @return
|
* @throws Exception
|
*/
|
public Map<String, Object> userBasicDataEntModify(TEnterpriseWithdrawal tEnterpriseWithdrawal) 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("huifu_id", tEnterpriseWithdrawal.getHuifuId());
|
// 企业用户名称
|
paramsInfo.put("reg_name", tEnterpriseWithdrawal.getBusinessLicenseCompanyName());
|
// 经营简称
|
paramsInfo.put("short_name", tEnterpriseWithdrawal.getMerchantAbbreviation());
|
// 营业执照编号
|
paramsInfo.put("license_code", tEnterpriseWithdrawal.getBusinessLicenseCode());
|
String[] businessExpireTimeArr = tEnterpriseWithdrawal.getBusinessExpireTime().split(",");
|
String startDateStr = businessExpireTimeArr[0];
|
// 证照有效期起始日期
|
paramsInfo.put("license_begin_date", startDateStr.replace("-", ""));
|
// 照有效期结束日期日期格式:yyyyMMdd; 非长期有效时必填;<font color="green">示例值:20320905</font>
|
String endDateStr = businessExpireTimeArr[1];
|
if (!"长期".equals(endDateStr)) {
|
String formatEndDate = endDateStr.replace("-", "");
|
paramsInfo.put("license_end_date", formatEndDate);
|
// 证照有效期类型
|
paramsInfo.put("license_validity_type", "0");
|
} else {
|
// 证照有效期类型
|
paramsInfo.put("license_validity_type", "1");
|
}
|
// 注册地址(省)
|
paramsInfo.put("reg_prov_id", tEnterpriseWithdrawal.getBusinessLicenseProvinceCode());
|
// 注册地址(市)
|
paramsInfo.put("reg_area_id", tEnterpriseWithdrawal.getBusinessLicenseCityCode());
|
// 注册地址(区)
|
paramsInfo.put("reg_district_id", tEnterpriseWithdrawal.getBusinessLicenseDistrictCode());
|
// 注册地址(详细信息)
|
paramsInfo.put("reg_detail", tEnterpriseWithdrawal.getBusinessLicenseAddress());
|
// 法人姓名
|
paramsInfo.put("legal_name", tEnterpriseWithdrawal.getCorporateIdCardReversePicture());
|
// 法人证件类型
|
paramsInfo.put("legal_cert_type", tEnterpriseWithdrawal.getCorporateCertificateType().equals(1) ? "00" : "11");
|
// 法人证件号码
|
paramsInfo.put("legal_cert_no", tEnterpriseWithdrawal.getCertificateCode());
|
String[] certificateExpireTimeArr = tEnterpriseWithdrawal.getCertificateExpireTime().split(",");
|
String expireStartDateStr = certificateExpireTimeArr[0];
|
// 法人证件有效期开始日期
|
paramsInfo.put("legal_cert_begin_date", expireStartDateStr.replace("-", ""));
|
// 法人证件有效期截止日期日期格式:yyyyMMdd; 非长期有效时必填,长期有效为空;<font color="green">示例值:20320905</font>
|
String expireEndDateStr = certificateExpireTimeArr[1];
|
if (!"长期".equals(endDateStr)) {
|
String formatEndDate = expireEndDateStr.replace("-", "");
|
paramsInfo.put("legal_cert_end_date", formatEndDate);
|
// 法人证件有效期类型
|
paramsInfo.put("legal_cert_validity_type", "0");
|
} else {
|
// 法人证件有效期类型
|
paramsInfo.put("legal_cert_validity_type", "1");
|
}
|
// 联系人姓名
|
paramsInfo.put("contact_name", tEnterpriseWithdrawal.getCorporateName());
|
// 联系人手机号
|
paramsInfo.put("contact_mobile", tEnterpriseWithdrawal.getCorporatePhone());
|
// 管理员账号如需短信通知则必填;<font color="green">示例值:Lg20220222013747</font>
|
paramsInfo.put("login_name", tEnterpriseWithdrawal.getCorporatePhone());
|
// 是否发送短信标识
|
paramsInfo.put("sms_send_flag", "Y");
|
// 3. 发起API调用
|
Map<String, Object> response = BasePayRequest.requestBasePay("v2/user/basicdata/ent", paramsInfo, null, false);
|
log.info("企业用户基本信息修改返回参数:{}", JSONObject.toJSONString(response));
|
return response;
|
}
|
|
/**
|
* 用户业务入驻
|
*
|
* @return
|
* @throws Exception
|
*/
|
public Map<String, Object> entBusinessOpen(TEnterpriseWithdrawal enterpriseWithdrawal) 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", enterpriseWithdrawal.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", "0");
|
cardInfo.put("card_name", enterpriseWithdrawal.getDepositName());
|
cardInfo.put("card_no", enterpriseWithdrawal.getBankAccount());
|
cardInfo.put("prov_id", enterpriseWithdrawal.getBankCardProvinceCode());
|
cardInfo.put("area_id", enterpriseWithdrawal.getBankCardCityCode());
|
cardInfo.put("branch_code", enterpriseWithdrawal.getBankBranchCode());
|
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> entBusinessOpenModify(TEnterpriseWithdrawal enterpriseWithdrawal) 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", enterpriseWithdrawal.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", "0");
|
cardInfo.put("card_name", enterpriseWithdrawal.getDepositName());
|
cardInfo.put("card_no", enterpriseWithdrawal.getBankAccount());
|
cardInfo.put("prov_id", enterpriseWithdrawal.getBankCardProvinceCode());
|
cardInfo.put("area_id", enterpriseWithdrawal.getBankCardCityCode());
|
cardInfo.put("branch_code", enterpriseWithdrawal.getBankBranchCode());
|
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;
|
}
|
|
/**
|
* 电子账户余额查询
|
*
|
* @return
|
* @throws Exception
|
*/
|
public BigDecimal balanceQuery(String huifuId) 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", huifuId);
|
// 请求流水号
|
paramsInfo.put("req_seq_id", RequestSeqUtil.generateForHuiFu());
|
// 请求日期
|
paramsInfo.put("req_date", DateUtil.format(new Date(), "yyyyMMdd"));
|
log.info("账户余额信息查询返回参数:{}", paramsInfo);
|
// 3. 发起API调用
|
Map<String, Object> response = BasePayRequest.requestBasePay("v2/trade/acctpayment/balance/query", paramsInfo, null, false);
|
log.info("账户余额信息查询返回参数:{}", response);
|
JSONArray accountList = JSONArray.parseArray(JSONObject.toJSONString(response.get("acctInfo_list")));
|
if (accountList != null && !accountList.isEmpty()) {
|
JSONObject acctInfo = accountList.getJSONObject(0);
|
log.info("账户余额信息查询返回余额:{}", acctInfo.getString("avail_bal"));
|
return acctInfo.getBigDecimal("avl_bal");
|
}
|
return BigDecimal.ZERO;
|
}
|
}
|