|
@@ -0,0 +1,161 @@
|
|
|
+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.infrastructure.utils.StringDecodeUtils;
|
|
|
+import com.hrsk.cloud.eg.vo.response.DataVo;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.crypto.Cipher;
|
|
|
+import javax.crypto.spec.SecretKeySpec;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+/**
|
|
|
+ * @Descrption
|
|
|
+ * @Author: chend
|
|
|
+ * @Date: 2023/2/7
|
|
|
+ * @Version V1.0
|
|
|
+ **/
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class PingXunCreditService implements LoanDockingApi {
|
|
|
+
|
|
|
+
|
|
|
+ private final static String checkPath = "pull/common/warehouse";
|
|
|
+ private final static String applyPath = "pull/common/receive";
|
|
|
+
|
|
|
+ private final static String cityCodePath = "pull/get-code-by-name-status";
|
|
|
+
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ProductBusinessApiInfoService apiInfoService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RetryRestTemplate httpRestTemplate;
|
|
|
+
|
|
|
+
|
|
|
+ @Data
|
|
|
+ private static class ReqData {
|
|
|
+ private String channel;
|
|
|
+ private Long timestamp;
|
|
|
+ private String sign;
|
|
|
+ private String content;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ private static class Result {
|
|
|
+
|
|
|
+ private Integer code;
|
|
|
+
|
|
|
+ private String msg;
|
|
|
+
|
|
|
+ private Object data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DataVo qualityCheck(UserInBaseInfoDto userInfo, PlanDto product) {
|
|
|
+ try {
|
|
|
+ log.info("credit PingXunCreditService qualityCheck begin...userId:{}", userInfo.getUserId());
|
|
|
+// XdProductJointConfig xdProductJointConfig = xdProductJointConfigMapper.selectById(product.getJointType());
|
|
|
+ ProductBusinessApiInfoDo apiInfo = apiInfoService.getById(product.getApiId());
|
|
|
+ String configJson = apiInfo.getThreeSystemConfig();
|
|
|
+ JSONObject config = JSONObject.parseObject(configJson);
|
|
|
+ log.info("平讯对接参数:{}", JSON.toJSONString(config));
|
|
|
+
|
|
|
+// LambdaQueryWrapper<XdUserBasicInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+// queryWrapper.eq(XdUserBasicInfo::getUserId, userInfo.getUserId());
|
|
|
+// XdUserBasicInfo xdUserBasicInfo = this.xdUserBasicInfoMapper.selectOne(queryWrapper);
|
|
|
+
|
|
|
+// String cityPath = config.getString("url") + cityCodePath;
|
|
|
+// String cityCode = getCityCode(cityPath, xdUserBasicInfo.getCityOfWork());
|
|
|
+//
|
|
|
+// ApplyInfo applyInfo = bulidInfo(userInfo, xdUserBasicInfo, userInfo.getBorrowMoney(), userInfo.getBorrowPurpose(), userInfo.getBorrowLimit());
|
|
|
+// applyInfo.setProvince(Integer.parseInt(cityCode));
|
|
|
+// applyInfo.setPhone(null);
|
|
|
+// applyInfo.setId_card(null);
|
|
|
+// applyInfo.setApply_name(null);
|
|
|
+// log.info("平讯撞库业务数据:{}", JSON.toJSONString(applyInfo));
|
|
|
+
|
|
|
+ ReqData reqData = new ReqData() {{
|
|
|
+ setChannel(config.getString("channel"));
|
|
|
+ setContent(encrypt(userInfo.getPhoneMd5(), config.getString("secret")));
|
|
|
+ Long timestamp = System.currentTimeMillis();
|
|
|
+ setSign(bulidSign(config, timestamp + ""));
|
|
|
+ setTimestamp(timestamp);
|
|
|
+ }};
|
|
|
+
|
|
|
+ String url = config.getString("url") + checkPath;
|
|
|
+ log.info("credit qualityCheck PingXunCreditService request userId:{}, url:{}, reqData:{}", userInfo.getUserId(), url, reqData);
|
|
|
+
|
|
|
+ ResponseEntity<String> response = null;
|
|
|
+ try {
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.valueOf("application/json;UTF-8"));
|
|
|
+ HttpEntity<ReqData> entity = new HttpEntity(reqData, headers);
|
|
|
+ response = httpRestTemplate.restTemplate().postForEntity(url, entity, String.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("平讯准入异常,异常信息:{}", e.getMessage(), e);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("credit qualityCheck PingXunCreditService response userId:{}, result:{}", userInfo.getUserId(), response);
|
|
|
+ if (response == null) {
|
|
|
+ return DataVo.timeout(product.getPlanId(), product.getPlanName());
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(StringDecodeUtils.decodeUnicode(response.getBody()));
|
|
|
+ if (200 == jsonObject.getInteger("status") && 1 == jsonObject.getJSONObject("data").getInteger("code")) {
|
|
|
+ return DataVo.success(0, "平讯撞库成功", product.getPlanId());
|
|
|
+ }
|
|
|
+ return DataVo.fail(jsonObject.getString("msg"), product.getPlanId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("平讯撞库失败", e);
|
|
|
+ return DataVo.fail(1, "平讯撞库失败,请联系系统管理员", product.getPlanId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ServerCodeEnums getType() {
|
|
|
+ return ServerCodeEnums.PingXun;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String bulidSign(JSONObject config, String timestamp) {
|
|
|
+ String channel = config.getString("channel");
|
|
|
+ String secret = config.getString("secret");
|
|
|
+ return Md5Util.encoderByMd5(channel + timestamp + secret);
|
|
|
+ }
|
|
|
+ public static String encrypt(String content, String key) {
|
|
|
+ byte[] originalContent = content.getBytes(StandardCharsets.UTF_8);
|
|
|
+ String keys = key.substring(0, 16);
|
|
|
+ byte[] encryptKey = keys.getBytes();
|
|
|
+ try {
|
|
|
+ Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
|
|
+ SecretKeySpec skeySpec = new SecretKeySpec(encryptKey, "AES");
|
|
|
+ cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
|
|
|
+ byte[] encrypted = cipher.doFinal(originalContent);
|
|
|
+ return Base64.encodeBase64String(encrypted);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|