parent
6fc542f739
commit
1404a31e3b
@ -0,0 +1,338 @@ |
||||
package com.hfkj.channel.saas; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.channel.saas.config.SaasConfig; |
||||
import com.hfkj.channel.saas.utils.RSAUtil; |
||||
import com.hfkj.channel.saas.utils.SaasCommon; |
||||
import com.hfkj.channel.saas.utils.SaasMerRequest; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.DateUtil; |
||||
import com.hfkj.common.utils.HttpsUtils; |
||||
import com.hfkj.config.CommonSysConst; |
||||
import com.hfkj.entity.*; |
||||
import com.hfkj.model.MerBasisModel; |
||||
import com.hfkj.service.*; |
||||
import com.hfkj.sysenum.MerAttachType; |
||||
import com.hfkj.sysenum.MerSettleType; |
||||
import com.hfkj.sysenum.MerTypeEnum; |
||||
import com.hfkj.sysenum.PlatformTypeEnum; |
||||
import org.apache.commons.codec.binary.Base64; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.io.File; |
||||
import java.util.*; |
||||
|
||||
/** |
||||
* 公共 |
||||
* @className: SasaCommon |
||||
* @author: HuRui |
||||
* @date: 2023/4/4 |
||||
**/ |
||||
@Component |
||||
public class SaasMerService { |
||||
|
||||
@Resource |
||||
private BsMerContractRecordService merContractRecordService; |
||||
|
||||
@Resource |
||||
private BsMerContractRecordMsgService merContractRecordMsgService; |
||||
|
||||
@Resource |
||||
private BsMerService merService; |
||||
|
||||
@Resource |
||||
private BsIndustryService industryService; |
||||
|
||||
@Resource |
||||
private SecRegionService regionService; |
||||
|
||||
@Resource |
||||
private BsMerRateService merRateService; |
||||
|
||||
@Resource |
||||
private BsMerPlatformNoService merPlatformNoService; |
||||
|
||||
@Resource |
||||
private BsMerPlatformNoRateService merPlatformNoRateService; |
||||
|
||||
@Resource |
||||
private BsMerAttachService merAttachService; |
||||
|
||||
@Resource |
||||
private CommonService commonService; |
||||
|
||||
@Resource |
||||
private SaasCommon saasCommon; |
||||
|
||||
@Resource |
||||
private SaasMerRequest saasMerRequest; |
||||
|
||||
public void addMer(Long merId) throws Exception { |
||||
MerBasisModel basisModel = merService.getMerDetail(merId); |
||||
|
||||
SecRegion province = commonService.getRegionsById(basisModel.getMerRegion().getProvinceCode()); |
||||
if (province == null || StringUtils.isBlank(province.getSaasCode())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户地址未配置正确,请联系客服!"); |
||||
} |
||||
SecRegion city = commonService.getRegionsById(basisModel.getMerRegion().getCityCode()); |
||||
if (city == null || StringUtils.isBlank(city.getSaasCode())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户地址未配置正确,请联系客服!"); |
||||
} |
||||
SecRegion area = commonService.getRegionsById(basisModel.getMerRegion().getAreaCode()); |
||||
if (area == null || StringUtils.isBlank(area.getSaasCode())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户地址未配置正确,请联系客服!"); |
||||
} |
||||
|
||||
// 经营内容
|
||||
BsIndustry industry = industryService.getDetailById(basisModel.getMerIndustry().getChildId()); |
||||
if (industry == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到经营范围"); |
||||
} |
||||
Map<String,Object> body = new HashMap<>(); |
||||
body.put("userNo", SaasConfig.userNo); |
||||
body.put("email", basisModel.getRegEmail()); |
||||
body.put("busiCode", "PAPER_CODE"); |
||||
body.put("merRegName", basisModel.getMerName()); |
||||
body.put("merType", basisModel.getMerType().equals(MerTypeEnum.status2.getNumber())?"TP_MERCHANT":"TP_PERSONAL"); |
||||
body.put("merName", basisModel.getMerName()); |
||||
body.put("merAddr", SaasMerService.dislodge(basisModel.getMerRegion().getAddress())); |
||||
body.put("provinceCode", province.getSaasCode()); |
||||
body.put("cityCode", city.getSaasCode()); |
||||
body.put("countyCode", area.getSaasCode()); |
||||
body.put("licenseName", basisModel.getMerName()); |
||||
|
||||
// 小微商户可不传营业执照信息
|
||||
if (!basisModel.getMerType().equals(MerTypeEnum.status3.getNumber())) { |
||||
body.put("licenseNo", basisModel.getBlisNo()); |
||||
body.put("licenseDtStart", basisModel.getBlisPeriodStart().replace("年", "-").replace("月", "-").replace("日", "")); |
||||
if (basisModel.getBlisPeriodType().equals(2)) { |
||||
body.put("licenseDtEnd", "长期有效"); |
||||
} else { |
||||
body.put("licenseDtEnd", basisModel.getBlisPeriodEnd().replace("年", "-").replace("月", "-").replace("日", "")); |
||||
} |
||||
} |
||||
|
||||
// 法人信息
|
||||
body.put("larName", basisModel.getLarName()); |
||||
body.put("larIdType", "01"); |
||||
body.put("larIdCard", basisModel.getLarIdCard()); |
||||
body.put("larIdCardStart", basisModel.getLarIdCardPeriodStart().replace(".", "-")); |
||||
if (basisModel.getLarIdCardPeriodType().equals(2)) { |
||||
Calendar larIdCardEnd = Calendar.getInstance(); |
||||
larIdCardEnd.set(Calendar.YEAR, 2099); |
||||
larIdCardEnd.set(Calendar.MONTH, 12); |
||||
body.put("larIdCardEnd", DateUtil.date2String(larIdCardEnd.getTime(), "yyyy-MM-dd")); |
||||
} else { |
||||
body.put("larIdCardEnd", basisModel.getLarIdCardPeriodEnd().replace(".", "-")); |
||||
} |
||||
body.put("contactMobile", basisModel.getRegPhone()); |
||||
body.put("contactName", basisModel.getRegName()); |
||||
|
||||
|
||||
/** --------- 结算信息---------- **/ |
||||
SecRegion settleProvince = commonService.getRegionsById(basisModel.getMerSettleAcct().getOpenningBankProvinceCode()); |
||||
if (settleProvince == null || StringUtils.isBlank(settleProvince.getSaasCode())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "结算地区未配置正确,请联系客服!"); |
||||
} |
||||
SecRegion settleCity = commonService.getRegionsById(basisModel.getMerSettleAcct().getOpenningBankCityCode()); |
||||
if (settleCity == null || StringUtils.isBlank(settleCity.getSaasCode())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "结算地区未配置正确,请联系客服!"); |
||||
} |
||||
body.put("openningBankCode", basisModel.getMerSettleAcct().getOpenningBankCode()); |
||||
body.put("openningBankName", basisModel.getMerSettleAcct().getOpenningBankName()); |
||||
body.put("clearingBankCode", basisModel.getMerSettleAcct().getClearingBankCode()); |
||||
body.put("settleProvinceCode", settleProvince.getSaasCode()); |
||||
body.put("settleProvinceName", basisModel.getMerSettleAcct().getOpenningBankProvinceName()); |
||||
body.put("settleCityCode", settleCity.getSaasCode()); |
||||
body.put("settleCityName", basisModel.getMerSettleAcct().getOpenningBankCityName()); |
||||
body.put("accountNo", basisModel.getMerSettleAcct().getBankCardNo()); |
||||
body.put("accountName", basisModel.getMerSettleAcct().getBankName()); |
||||
|
||||
if (basisModel.getMerSettleAcct().getSettleType().equals(MerSettleType.status1.getNumber())) { |
||||
body.put("accountType", "57"); |
||||
} else { |
||||
body.put("accountType", "58"); |
||||
} |
||||
body.put("accountIdCard", basisModel.getMerSettleAcct().getSettleIdCardNo()); |
||||
|
||||
// 非法人结算
|
||||
if (basisModel.getMerSettleAcct().getSettleType().equals(MerSettleType.status3.getNumber())) { |
||||
body.put("accountIdType", basisModel.getLarName()); |
||||
body.put("accountIdDtStart", basisModel.getMerSettleAcct().getSettleIdCardPeriodStart().replace(".", "-")); |
||||
if (basisModel.getLarIdCardPeriodType().equals(2)) { |
||||
Calendar accountIdDtEnd = Calendar.getInstance(); |
||||
accountIdDtEnd.set(Calendar.YEAR, 2099); |
||||
accountIdDtEnd.set(Calendar.MONTH, 12); |
||||
accountIdDtEnd.set(Calendar.DATE , 31); |
||||
body.put("accountIdDtEnd", DateUtil.date2String(accountIdDtEnd.getTime(), "yyyy-MM-dd")); |
||||
} else { |
||||
body.put("accountIdDtEnd", basisModel.getLarIdCardPeriodEnd().replace(".", "-")); |
||||
} |
||||
} |
||||
/** --------- 结算信息---------- **/ |
||||
Map<String,Object> bizContent = new HashMap<>(); |
||||
bizContent.put("termNum", "1"); |
||||
|
||||
Map<String, Object> feesMap; |
||||
List<Map<String,Object>> feesMapList = new ArrayList<>(); |
||||
// 商户费率
|
||||
List<BsMerRate> rateList = merRateService.getRateListByMerId(merId); |
||||
for (BsMerRate rate : rateList) { |
||||
feesMap = new HashMap<>(); |
||||
feesMap.put("feeCode", rate.getRateSaasTypeCode()); |
||||
feesMap.put("feeValue", rate.getRatePct()); |
||||
feesMapList.add(feesMap); |
||||
} |
||||
bizContent.put("fees", feesMapList); |
||||
bizContent.put("mcc", basisModel.getMerMccCode()); |
||||
bizContent.put("activityId", SaasConfig.activityId); |
||||
|
||||
Map<String,Object> attchMap; |
||||
List<Map<String,Object>> attchMapList = new ArrayList<>(); |
||||
|
||||
List<BsMerAttach> attachList = merAttachService.getAttachListByMer(merId, PlatformTypeEnum.type0, null); |
||||
for (BsMerAttach attach : attachList) { |
||||
attchMap = new HashMap<>(); |
||||
MerAttachType attachType = MerAttachType.getDataByNumber(attach.getType()); |
||||
if (attachType == null || StringUtils.isBlank(attachType.getLakalaCode())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的附件类型"); |
||||
} |
||||
attchMap.put("type", attachType.getLakalaCode()); |
||||
attchMap.put("id", saasCommon.fileUpload(new File(CommonSysConst.getSysConfig().getFile_url() +"/"+ attach.getFileUrl()), attachType.getLakalaCode(), "0").getString("url")); |
||||
attchMapList.add(attchMap); |
||||
} |
||||
|
||||
body.put("bizContent", bizContent); |
||||
body.put("attchments", attchMapList); |
||||
body.put("businessContent", basisModel.getMerIndustry().getChildName()); |
||||
body.put("latitude", "0.0"); |
||||
body.put("longtude", "0.0"); |
||||
body.put("source", "H5"); |
||||
body.put("settleType", "D1"); |
||||
saasMerRequest.addMerchant(body); |
||||
|
||||
Map<String,Object> header = new HashMap<>(); |
||||
header.put("Authorization", "bearer " + saasCommon.getToken()); |
||||
|
||||
JSONObject responseBody = HttpsUtils.doPost(SaasConfig.requestMerRegistrationCommonUrl+"merchant", body, header); |
||||
System.out.println("body:" + JSONObject.toJSONString(body)); |
||||
System.out.println("response:" + responseBody); |
||||
if (responseBody == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请求进件失败"); |
||||
} |
||||
if (StringUtils.isBlank(responseBody.getString("state"))) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseBody.getString("message")); |
||||
} |
||||
if (!responseBody.getString("state").equals("1")) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请求进件失败"); |
||||
} |
||||
|
||||
BsMerPlatformNo platform = merPlatformNoService.getPlatformNo(merId, PlatformTypeEnum.type1); |
||||
if (platform != null) { |
||||
platform.setStatus(0); |
||||
merPlatformNoService.editMerPlatformNo(platform); |
||||
} |
||||
|
||||
platform = new BsMerPlatformNo(); |
||||
platform.setCompanyId(basisModel.getCompanyId()); |
||||
platform.setAgentId(basisModel.getAgentId()); |
||||
platform.setMerId(basisModel.getId()); |
||||
platform.setMerNo(basisModel.getMerNo()); |
||||
platform.setPlatformType(PlatformTypeEnum.type1.getNumber()); |
||||
platform.setPlatformNo(responseBody.getString("merchantNo")); |
||||
merPlatformNoService.editMerPlatformNo(platform); |
||||
|
||||
String orderNo = System.currentTimeMillis()+""; |
||||
// 增加进件记录
|
||||
BsMerContractRecord record = new BsMerContractRecord(); |
||||
record.setMerId(merId); |
||||
record.setPlatformType(PlatformTypeEnum.type1.getNumber()); |
||||
record.setOrderNo(orderNo); |
||||
record.setContractId(responseBody.toJSONString()); |
||||
record.setStatus(1); |
||||
merContractRecordService.insertRecord(record); |
||||
|
||||
// 增加进件记录消息
|
||||
BsMerContractRecordMsg recordMsg = new BsMerContractRecordMsg(); |
||||
recordMsg.setOrderNo(orderNo); |
||||
recordMsg.setType(1); |
||||
recordMsg.setRequestContent(JSONObject.toJSONString(body)); |
||||
recordMsg.setResponseCode(responseBody.getString("state")); |
||||
recordMsg.setResponseMsg(null); |
||||
recordMsg.setResponseContent(responseBody.toJSONString()); |
||||
merContractRecordMsgService.insertRecordMsg(recordMsg); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 查询银行地区编码 |
||||
* @param customerNo |
||||
* @return |
||||
*/ |
||||
public JSONObject merchantInfo(String customerNo) { |
||||
try { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("customerNo", customerNo); |
||||
|
||||
Map<String,Object> header = new HashMap<>(); |
||||
header.put("Authorization", "bearer " + saasCommon.getToken()); |
||||
|
||||
JSONObject obj = new JSONObject(); |
||||
obj.put("data", Base64.encodeBase64String(RSAUtil.encryptByPrivateKey(JSONObject.toJSONString(param).getBytes(), Base64.decodeBase64(RSAUtil.PRIVATE_KEY)))); |
||||
|
||||
JSONObject responseObj = HttpsUtils.doPost(SaasConfig.requestMerUrl + "open/merchant/info", obj, header); |
||||
System.out.println(responseObj.toJSONString()); |
||||
if (responseObj == null || !responseObj.getString("code").equals("000000")) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseObj.getString("message")); |
||||
} |
||||
return JSONObject.parseObject(new String(RSAUtil.decryptByPublicKey(Base64.decodeBase64(responseObj.getString("data")), Base64.decodeBase64(RSAUtil.PUBLIC_KEY)))); |
||||
|
||||
} catch (Exception e) { |
||||
System.out.println(e); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 地址去除省、市 |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static String dislodge(String str) { |
||||
char[] chars = str.toCharArray(); |
||||
// oP: '省' 的偏移, oC: '市' 的偏移, oR: "自治区" 的偏移
|
||||
int oP = -1, oC = -1, oR = -1; |
||||
char ch; |
||||
for (int i = 0; i < chars.length; i++) { |
||||
ch = chars[i]; |
||||
// 一般来说 '省' 的位置会比 '市' 早出现
|
||||
if (ch == '省') { |
||||
oP = i; |
||||
} else if (ch == '市') { |
||||
oC = i; |
||||
// 找到 '市' 后就可以跳出循环了
|
||||
break; |
||||
} else if (ch == '自' |
||||
&& i + 2 < chars.length |
||||
&& chars[i + 1] == '治' |
||||
&& chars[i + 2] == '区') { |
||||
// "自治区" 出现的几率挺小
|
||||
oR = i + 2; |
||||
} |
||||
} |
||||
|
||||
if (oC != -1) { |
||||
str = str.substring(oC + 1); |
||||
} else if (oP != -1) { |
||||
str = str.substring(oP + 1); |
||||
} else if (oR != -1) { |
||||
str = str.substring(oR + 1); |
||||
} |
||||
|
||||
return str; |
||||
} |
||||
} |
@ -0,0 +1,31 @@ |
||||
package com.hfkj.channel.saas.config; |
||||
|
||||
import com.hfkj.config.CommonSysConst; |
||||
|
||||
/** |
||||
* @className: SaasConfig |
||||
* @author: HuRui |
||||
* @date: 2023/4/4 |
||||
**/ |
||||
public class SaasConfig { |
||||
|
||||
public static String requestMerRegistrationTokenUrl = CommonSysConst.getSysConfig().getLkl_saas_request_mer_registration_token_url(); |
||||
public static String requestMerRegistrationUrl = CommonSysConst.getSysConfig().getLkl_saas_request_mer_registration_url(); |
||||
public static String requestMerRegistrationCommonUrl = CommonSysConst.getSysConfig().getLkl_saas_request_mer_registration_common_url(); |
||||
public static String requestMerUrl = CommonSysConst.getSysConfig().getLkl_saas_request_mer_url(); |
||||
public static String client_id = CommonSysConst.getSysConfig().getLkl_saas_client_id(); |
||||
public static String client_secret = CommonSysConst.getSysConfig().getLkl_saas_client_secret(); |
||||
public static String activityId = CommonSysConst.getSysConfig().getLkl_saas_activity_id(); |
||||
public static String userNo = CommonSysConst.getSysConfig().getLkl_saas_user_no(); |
||||
|
||||
/* public static String requestMerRegistrationTokenUrl = "https://test.wsmsd.cn/sit/htkauth/oauth/token"; |
||||
public static String requestMerRegistrationUrl = "https://test.wsmsd.cn/sit/htkregistration/merchant/"; |
||||
public static String requestMerRegistrationCommonUrl = "https://test.wsmsd.cn/sit/htkregistration/"; |
||||
public static String requestMerUrl = "https://test.wsmsd.cn/sit/htkmerchants/"; |
||||
public static String client_id = "testsit"; |
||||
public static String client_secret = "EguwEckByf2I6u6z"; |
||||
public static String activityId = "37"; |
||||
public static String userNo = "20000101";*/ |
||||
|
||||
|
||||
} |
@ -0,0 +1,67 @@ |
||||
package com.hfkj.channel.saas.saasenum; |
||||
|
||||
import java.util.Objects; |
||||
|
||||
/** |
||||
* SAAS 文件图片 |
||||
* @className: FileImgType |
||||
* @author: HuRui |
||||
* @date: 2023/4/5 |
||||
**/ |
||||
public enum FileImgType { |
||||
|
||||
ID_CARD_FRONT("ID_CARD_FRONT", "身份证正⾯"), |
||||
ID_CARD_BEHIND("ID_CARD_BEHIND", "身份证反⾯"), |
||||
BUSINESS_LICENCE("BUSINESS_LICENCE", "营业执照照⽚"), |
||||
BANK_CARD("BANK_CARD", "银行卡"), |
||||
AGREE_MENT("AGREE_MENT", "协议"), |
||||
OPENING_PERMIT("OPENING_PERMIT", "开户许可证"), |
||||
CHECKSTAND_IMG("CHECKSTAND_IMG", "收银台照片(仅对公进件需传)"), |
||||
SHOP_OUTSIDE_IMG("SHOP_OUTSIDE_IMG", "上传门头照片(仅对公进件需传"), |
||||
SHOP_INSIDE_IMG("SHOP_INSIDE_IMG", "商铺内部照片(仅对公进件需传)"), |
||||
OTHERS("OTHERS", "其他 无对应类型图片,请传其他类型"), |
||||
SETTLE_ID_CARD_FRONT("SETTLE_ID_CARD_FRONT", "结算人身份证人像面"), |
||||
SETTLE_ID_CARD_BEHIND("SETTLE_ID_CARD_BEHIND", "结算人身份证国徽面"), |
||||
LETTER_OF_AUTHORIZATION("LETTER_OF_AUTHORIZATION", "法人授权涵"), |
||||
; |
||||
|
||||
private String code; |
||||
|
||||
private String name; |
||||
|
||||
FileImgType(String code, String name) { |
||||
this.code = code; |
||||
this.name = name; |
||||
} |
||||
|
||||
/** |
||||
* 查询数据 |
||||
* @param code |
||||
* @return |
||||
*/ |
||||
public static FileImgType getDataByCode(String code) { |
||||
for (FileImgType ele : values()) { |
||||
if (Objects.equals(code,ele.getCode())) { |
||||
return ele; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
|
||||
public String getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public void setCode(String code) { |
||||
this.code = code; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,196 @@ |
||||
package com.hfkj.channel.saas.utils; |
||||
|
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.channel.saas.config.SaasConfig; |
||||
import com.hfkj.channel.saas.saasenum.FileImgType; |
||||
import com.hfkj.common.Base64Util; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.HttpsUtils; |
||||
import com.hfkj.common.utils.RedisUtil; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.apache.http.entity.mime.content.FileBody; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.io.File; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 公共 |
||||
* @className: SasaCommon |
||||
* @author: HuRui |
||||
* @date: 2023/4/4 |
||||
**/ |
||||
@Component |
||||
public class SaasCommon { |
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SaasCommon.class); |
||||
|
||||
@Autowired |
||||
private RedisUtil redisUtil; |
||||
|
||||
/** |
||||
* 获取token |
||||
* @return |
||||
*/ |
||||
public Object getToken() { |
||||
try { |
||||
Object saasToken = redisUtil.get("SAAS_TOKEN"); |
||||
if (saasToken != null) { |
||||
return saasToken.toString(); |
||||
} |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("grant_type", "client_credentials"); |
||||
param.put("client_id", SaasConfig.client_id); |
||||
param.put("client_secret", SaasConfig.client_secret); |
||||
|
||||
Map<String,Object> header = new HashMap<>(); |
||||
header.put("Authorization", "Basic " + Base64Util.encode(SaasConfig.client_id+":"+SaasConfig.client_secret)); |
||||
|
||||
// 请求参数
|
||||
String requestParam = SaasUtils.paramSort(param); |
||||
|
||||
log.info("==============start 获取token start =============="); |
||||
log.info("请求header:" + JSONObject.toJSONString(header)); |
||||
log.info("请求参数:" + requestParam); |
||||
JSONObject jsonObject = HttpsUtils.doPostForm(SaasConfig.requestMerRegistrationTokenUrl, requestParam, header); |
||||
log.info("响应参数:" + jsonObject); |
||||
if (StringUtils.isNotBlank(jsonObject.getString("access_token"))) { |
||||
redisUtil.set("SAAS_TOKEN", jsonObject.getString("access_token"), jsonObject.getLong("expires_in")); |
||||
return jsonObject.getString("access_token"); |
||||
} |
||||
} catch (Exception e) { |
||||
log.info("出现异常:", e); |
||||
return null; |
||||
} finally { |
||||
log.info("==============end 获取token end =============="); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 文件上传 |
||||
* @param file 文件 |
||||
* @param attType 文件类型 |
||||
* @param sourcechnl 来源 0:PC,1:安卓,2:IOS |
||||
* @return |
||||
*/ |
||||
public JSONObject fileUpload(File file, String attType, String sourcechnl) { |
||||
try { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("file", new FileBody(file)); |
||||
param.put("imgType", attType); |
||||
param.put("sourcechnl", sourcechnl); |
||||
param.put("isOcr", false); |
||||
|
||||
Map<String,Object> header = new HashMap<>(); |
||||
header.put("Authorization", "bearer " + getToken()); |
||||
|
||||
JSONObject jsonObject = HttpsUtils.doPostSaasUpload(SaasConfig.requestMerRegistrationCommonUrl+"/file/upload",file,param, header); |
||||
if (!jsonObject.getString("status").equals("00")) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "文件上传失败"); |
||||
} |
||||
return jsonObject; |
||||
} catch (Exception e) { |
||||
System.out.println(e); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 查询商户类别【父类】 |
||||
* @param parentCode |
||||
* @return |
||||
*/ |
||||
public JSONArray getCategory(String parentCode) { |
||||
try { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("businessScene", 2); |
||||
if (StringUtils.isNotBlank(parentCode)) { |
||||
param.put("parentCode", parentCode); |
||||
} |
||||
|
||||
Map<String,Object> header = new HashMap<>(); |
||||
header.put("Authorization", "bearer " + getToken()); |
||||
|
||||
String result = HttpsUtils.doSaasGet(SaasConfig.requestMerRegistrationCommonUrl+"customer/category", param, header, true); |
||||
return JSONArray.parseArray(result); |
||||
} catch (Exception e) { |
||||
System.out.println(e); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 查询地区编码 |
||||
* @param parentCode |
||||
* @return |
||||
*/ |
||||
public JSONArray getArea(String parentCode) { |
||||
try { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("parentCode", parentCode); |
||||
|
||||
Map<String,Object> header = new HashMap<>(); |
||||
header.put("Authorization", "bearer " + getToken()); |
||||
|
||||
String result = HttpsUtils.doSaasGet(SaasConfig.requestMerRegistrationCommonUrl+"organization", param, header, false); |
||||
return JSONArray.parseArray(result); |
||||
} catch (Exception e) { |
||||
System.out.println(e); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 查询银行地区编码 |
||||
* @param parentCode |
||||
* @return |
||||
*/ |
||||
public JSONArray getBankArea(String parentCode) { |
||||
try { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("parentCode", parentCode); |
||||
|
||||
Map<String,Object> header = new HashMap<>(); |
||||
header.put("Authorization", "bearer " + getToken()); |
||||
|
||||
String result = HttpsUtils.doSaasGet(SaasConfig.requestMerRegistrationCommonUrl + "/organization/bank", param, header, false); |
||||
return JSONArray.parseArray(result); |
||||
|
||||
} catch (Exception e) { |
||||
System.out.println(e); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 查询银行列表 |
||||
* @param areaCode 地区编码 |
||||
* @param bankName 银行名称 |
||||
* @return |
||||
*/ |
||||
public JSONArray getBank(String areaCode,String bankName) { |
||||
try { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("areaCode", areaCode); |
||||
param.put("bankName", bankName); |
||||
|
||||
Map<String,Object> header = new HashMap<>(); |
||||
header.put("Authorization", "bearer " + getToken()); |
||||
|
||||
String result = HttpsUtils.doSaasGet(SaasConfig.requestMerRegistrationCommonUrl + "/bank", param, header, true); |
||||
return JSONArray.parseArray(result); |
||||
} catch (Exception e) { |
||||
System.out.println(e); |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,55 @@ |
||||
package com.hfkj.channel.saas.utils; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.channel.lakala.config.RSAUtils; |
||||
import com.hfkj.channel.saas.config.SaasConfig; |
||||
import com.hfkj.common.Base64Util; |
||||
import com.hfkj.common.utils.HttpsUtils; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @className: SaasMerRequest |
||||
* @author: HuRui |
||||
* @date: 2023/4/5 |
||||
**/ |
||||
@Component |
||||
public class SaasMerRequest { |
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SaasMerRequest.class); |
||||
|
||||
@Resource |
||||
private SaasCommon saasCommon; |
||||
|
||||
/** |
||||
* 增加进件 |
||||
* @param body 参数 |
||||
* @return |
||||
*/ |
||||
public Object addMerchant(Map<String, Object> body) { |
||||
try { |
||||
Map<String,Object> header = new HashMap<>(); |
||||
header.put("Authorization", "bearer " + saasCommon.getToken()); |
||||
|
||||
log.info("==============start 商户进件 start =============="); |
||||
log.info("请求header:" + JSONObject.toJSONString(header)); |
||||
log.info("请求参数:" + JSONObject.toJSONString(body)); |
||||
|
||||
JSONObject jsonObject = HttpsUtils.doPost(SaasConfig.requestMerRegistrationUrl, body, header); |
||||
log.info("响应参数:" + jsonObject); |
||||
return jsonObject; |
||||
} catch (Exception e) { |
||||
log.info("出现异常:", e); |
||||
return null; |
||||
} finally { |
||||
log.info("==============end 商户进件 end =============="); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,33 @@ |
||||
package com.hfkj.channel.saas.utils; |
||||
|
||||
import org.apache.commons.lang3.StringUtils; |
||||
|
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* @className: SaasUtils |
||||
* @author: HuRui |
||||
* @date: 2023/4/5 |
||||
**/ |
||||
public class SaasUtils { |
||||
|
||||
/** |
||||
* 参数排序 |
||||
* @param param |
||||
* @return |
||||
*/ |
||||
public static String paramSort(final Map<String, Object> param) { |
||||
Set<String> keySet = param.keySet(); |
||||
String[] keyArray = keySet.toArray(new String[keySet.size()]); |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (String k : keyArray) { |
||||
if (StringUtils.isBlank(sb.toString())) { |
||||
sb.append(k).append("=").append(param.get(k)); |
||||
} else { |
||||
sb.append("&").append(k).append("=").append(param.get(k)); |
||||
} |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
} |
Loading…
Reference in new issue