|
@@ -0,0 +1,123 @@
|
|
|
+package com.hrsk.cloud.eg.app.threedocking.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.hrsk.cloud.eg.app.constant.ServerCodeEnums;
|
|
|
+import com.hrsk.cloud.eg.app.threedocking.LoanDockingApi;
|
|
|
+import com.hrsk.cloud.eg.dto.data.egPlan.PlanDto;
|
|
|
+import com.hrsk.cloud.eg.dto.data.user.UserInBaseInfoDto;
|
|
|
+import com.hrsk.cloud.eg.infrastructure.config.client.config.RetryRestTemplate;
|
|
|
+import com.hrsk.cloud.eg.infrastructure.repository.database.entity.ProductBusinessApiInfoDo;
|
|
|
+import com.hrsk.cloud.eg.infrastructure.service.ProductBusinessApiInfoService;
|
|
|
+import com.hrsk.cloud.eg.infrastructure.utils.Md5Util;
|
|
|
+import com.hrsk.cloud.eg.vo.response.DataVo;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.time.Instant;
|
|
|
+import java.util.Random;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author Liu Tao
|
|
|
+ * @Date 2024 03 22 11 13
|
|
|
+ **/
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class MoGuTouCreditService implements LoanDockingApi {
|
|
|
+ @Resource
|
|
|
+ private ProductBusinessApiInfoService apiInfoService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RetryRestTemplate httpRestTemplate;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ServerCodeEnums getType() {
|
|
|
+ return ServerCodeEnums.MoGuTou;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ private static class CheckInfo{
|
|
|
+ private String tenantId;//企业ID
|
|
|
+ private String md5Code;//手机号Md5小写加密串
|
|
|
+ private String signature;//按照tenantId、timestamp、randomStr、系统密钥和企业密钥的顺序拼接的字符串,再通过Md5小写加密串
|
|
|
+ private String randomStr;//由大小写字母和数字组成的6位的随机字符串
|
|
|
+ private String timestamp;//时间戳,单位:毫秒
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DataVo qualityCheck(UserInBaseInfoDto userInfo, PlanDto product) {
|
|
|
+ try {
|
|
|
+ log.info("credit SouYuJinFuCreditService qualityCheck begin...userId:{}", userInfo.getUserId());
|
|
|
+ ProductBusinessApiInfoDo apiInfo = apiInfoService.getById(product.getApiId());
|
|
|
+ String configJson = apiInfo.getThreeSystemConfig();
|
|
|
+ JSONObject config = JSONObject.parseObject(configJson);
|
|
|
+ log.info("蘑菇投对接参数:{}", JSON.toJSONString(config));
|
|
|
+ CheckInfo checkInfo = new CheckInfo();
|
|
|
+ checkInfo.setMd5Code((userInfo.getPhoneMd5() == null ? Md5Util.encoderByMd5(userInfo.getUserMobile()) : userInfo.getPhoneMd5()));
|
|
|
+ checkInfo.setTenantId(config.getString("tenantId"));
|
|
|
+ String millisecondsSinceEpoch = String.valueOf(Instant.now().toEpochMilli());
|
|
|
+ checkInfo.setTimestamp(millisecondsSinceEpoch);//当前时间搓
|
|
|
+ checkInfo.setRandomStr(getRandomStr());//随机字符串
|
|
|
+ String signature=checkInfo.getTenantId()+checkInfo.getTimestamp()+checkInfo.getRandomStr()+config.getString("key")+config.getString("qykey");
|
|
|
+ String s = Md5Util.encoderByMd5(signature);
|
|
|
+ checkInfo.setSignature(s);
|
|
|
+ String url = config.getString("checkUrl");
|
|
|
+
|
|
|
+ log.info("credit qualityCheck MoGuTouCreditService request userId:{}, url:{}, CheckInfo:{}", userInfo.getUserId(), url, checkInfo);
|
|
|
+ String response = null;
|
|
|
+ try {
|
|
|
+ response =httpRestTemplate.restTemplate().postForObject(url,checkInfo, String.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("蘑菇投准入异常,异常信息:{}", e.getMessage(), e);
|
|
|
+ }
|
|
|
+ log.info("credit qualityCheck MoGuTouCreditService response userId:{}, result:{}", userInfo.getUserId(), response);
|
|
|
+ if (response == null) {
|
|
|
+ return DataVo.timeout(product.getPlanId(), product.getPlanName());
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(response);
|
|
|
+ log.info("credit qualityCheck MoGuTouCreditService response userId:{}, jsonObject:{}", userInfo.getUserId(), jsonObject);
|
|
|
+ if (jsonObject == null) {
|
|
|
+ return DataVo.timeout(product.getPlanId(), product.getPlanName());
|
|
|
+ }
|
|
|
+ if (jsonObject.getInteger("code")==200&&!jsonObject.getString("data").equals("duplicate")) {
|
|
|
+ return DataVo.success(0, "蘑菇投撞库成功", product.getPlanId());
|
|
|
+ } else {
|
|
|
+ return DataVo.fail(1, "蘑菇投撞库失败,请联系系统管理员", product.getPlanId());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("蘑菇投撞库失败", e);
|
|
|
+ return DataVo.fail(1, "授渔金服撞库失败,请联系系统管理员", product.getPlanId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getRandomStr(){
|
|
|
+ // 定义一个字符串,包含所有可能的字符
|
|
|
+ String charPool = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
|
+
|
|
|
+ // 创建Random对象
|
|
|
+ Random random = new Random();
|
|
|
+
|
|
|
+ // 使用StringBuilder来构建随机字符串
|
|
|
+ StringBuilder sb = new StringBuilder(6);
|
|
|
+
|
|
|
+ // 循环6次,生成6个随机字符
|
|
|
+ for (int i = 0; i < 6; i++) {
|
|
|
+ // 从charPool中随机选择一个字符
|
|
|
+ int index = random.nextInt(charPool.length());
|
|
|
+ char randomChar = charPool.charAt(index);
|
|
|
+
|
|
|
+ // 将随机字符添加到StringBuilder中
|
|
|
+ sb.append(randomChar);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将StringBuilder转换为String并输出
|
|
|
+ String randomString = sb.toString();
|
|
|
+ return randomString;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|