Commit 5514970f authored by 黎博's avatar 黎博

更新乐信

parent 65d302d3
......@@ -165,6 +165,12 @@
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
</dependencies>
<build>
......
......@@ -5,7 +5,8 @@ package cn.qg.qaplatform.common.enums;
*/
public enum ChannelEnum {
XYQB("信用钱包", 1);
XYQB("信用钱包", 1),
LEXIN("乐信", 159886);
private String name;
private Integer channelId;
......
......@@ -7,7 +7,8 @@ public enum FundEnum {
GYXD("广达小贷", 480),
YNXT("云南信托", 1040),
PDSB("平顶山银行", 1030);
PDSB("平顶山银行", 1030),
GDLX("广达乐信",1010);
private String name;
private Integer fundId;
......
......@@ -3,18 +3,19 @@ package cn.qg.qaplatform.controller;
import cn.qg.qaplatform.common.JsonResult;
import cn.qg.qaplatform.common.enums.ChannelEnum;
import cn.qg.qaplatform.common.enums.FundEnum;
import cn.qg.qaplatform.domain.ApplyLoanInfo;
import cn.qg.qaplatform.domain.ApplyDataVo;
import cn.qg.qaplatform.domain.GenLoanUser;
import cn.qg.qaplatform.service.GenUserDataService;
import cn.qg.qaplatform.service.LexinDataService;
import cn.qg.qaplatform.service.XyqbDataService;
import cn.qg.qaplatform.service.QueryBasicLoanStatusDataService;
import cn.qg.qaplatform.utils.EnumUtils;
import cn.qg.qaplatform.utils.RandomDataUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
......@@ -25,53 +26,24 @@ import java.util.Map;
public class GenLoanUserDataController {
@Autowired
GenUserDataService genUserDataService;
XyqbDataService xyqbDataService;
@Autowired
LexinDataService lexinDataService;
@Autowired
QueryBasicLoanStatusDataService queryBasicLoanStatusDataService;
@ApiOperation(value = "造数据接口")
@PostMapping("/loanUser")
public JsonResult genLoanUserData(@RequestBody ApplyLoanInfo applyLoanInfo) throws Exception {
if (applyLoanInfo.getNamespace() == null) {
return JsonResult.clientFailed("namespace不能为空!");
}
if (applyLoanInfo.getChannel() == null) {
return JsonResult.clientFailed("渠道不能为空!");
}
if (applyLoanInfo.getFundId() == null) {
return JsonResult.clientFailed("资方不能为空!");
}
if (applyLoanInfo.getStatus() == null) {
return JsonResult.clientFailed("借款状态不能为空!");
}
// 如果手机号为空,则生成一个user库里没有的手机号
if (applyLoanInfo.getPhoneNo() == null) {
while (true) {
String phoneNo = RandomDataUtils.createMobile();
if (!queryBasicLoanStatusDataService.queryIfPhoneExist(applyLoanInfo.getNamespace(), phoneNo)) {
applyLoanInfo.setPhoneNo(phoneNo);
break;
}
}
@PostMapping("/data")
public JsonResult genLoanUserData(@RequestBody ApplyDataVo applyDataVo) throws Exception {
boolean result = false;
if (applyDataVo.getChannel().equals(ChannelEnum.XYQB.getChannelId())) {
result = xyqbDataService.genLoanUser(applyDataVo);
}
if (applyLoanInfo.getAmount() == null) {
applyLoanInfo.setAmount(10000);
if (applyDataVo.getChannel().equals(ChannelEnum.LEXIN.getChannelId())) {
result = lexinDataService.genLexinData(applyDataVo);
}
if (applyLoanInfo.getTerm() == null) {
applyLoanInfo.setTerm(6);
}
if (applyLoanInfo.getName() == null) {
applyLoanInfo.setName("刘志国");
}
if (applyLoanInfo.getCardNo() == null ) {
applyLoanInfo.setCardNo("6222800003478997463");
applyLoanInfo.setBankCode("CCB");
}
if (applyLoanInfo.getBankCode() == null) {
applyLoanInfo.setBankCode("CCB");
}
boolean result = genUserDataService.genLoanUser(applyLoanInfo);
return JsonResult.success(result);
}
......@@ -90,8 +62,51 @@ public class GenLoanUserDataController {
@GetMapping("/userStatus")
public JsonResult queryUserStatus(@RequestParam String namespace,
@RequestParam String phoneNo) {
GenLoanUser genLoanUser = genUserDataService.queryUserStatus(namespace, phoneNo);
GenLoanUser genLoanUser = xyqbDataService.queryUserStatus(namespace, phoneNo);
return JsonResult.success(genLoanUser);
}
@GetMapping("/channelMappedFund")
public JsonResult mapFund(@RequestParam Integer channel) {
List<Map<String, Object>> supportFund = EnumUtils.enumToListMap(FundEnum.class);
List<Map> resultFundList = new LinkedList<>();
if (channel == 1) {
for (Map<String, Object> temp: supportFund) {
if (temp.get("fundId").equals(480) || temp.get("fundId").equals(1030) || temp.get("fundId").equals(1040)) {
resultFundList.add(temp);
}
}
}
if (channel == 159886) {
for (Map<String, Object> temp: supportFund) {
if (temp.get("fundId").equals(1010)) {
resultFundList.add(temp);
}
}
}
return JsonResult.success(resultFundList);
}
@GetMapping("/fundMappedChannel")
public JsonResult mapChannel(@RequestParam Integer fundId) {
List<Map<String, Object>> supportChannel = EnumUtils.enumToListMap(ChannelEnum.class);
List<Map> resultChannelList = new LinkedList<>();
if (fundId == 480 || fundId == 1030 || fundId == 1040) {
for (Map<String, Object> temp: supportChannel) {
if (temp.get("channelId").equals(1)) {
resultChannelList.add(temp);
}
}
}
if (fundId == 1010) {
for (Map<String, Object> temp: supportChannel) {
if (temp.get("channelId").equals(159886)) {
resultChannelList.add(temp);
}
}
}
return JsonResult.success(resultChannelList);
}
}
package cn.qg.qaplatform.domain;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* 造Xyqb数据传递的参数实体类
*/
@Data
public class ApplyDataVo {
@NotNull(message = "借款状态不能为空!")
private Integer status;
@NotNull(message = "环境不能为空!")
private String namespace;
@NotNull(message = "手机号不能为空!")
private String phoneNo;
private Integer channel = 1;
private Integer fundId = 480;
private Integer amount = 10000;
private Integer term = 3;
private Integer rate;
private String name = "刘志国";
private String idCardNo = "330212198511195794";
private String bankCardNo = "6222800003478997463";
private String bankName = "中国建设银行";
private String bankCode = "CCB";
private Integer fixedBillDay = 2;
private Integer fixedRepayDay = 12;
/**
* websocket通信标志位
*/
private String symbol = null;
}
package cn.qg.qaplatform.domain;
import lombok.Data;
/**
* 造数据传递的参数实体类
*/
@Data
public class ApplyLoanInfo {
/**
* 状态
*/
private Integer status;
/**
* 环境
*/
private String namespace;
/**
* 手机号
*/
private String phoneNo;
/**
* 渠道
*/
private Integer channel;
/**
* 资方
*/
private Integer fundId;
/**
* 借款金额
*/
private Integer amount;
/**
* 借款期数
*/
private Integer term;
/**
* 姓名
*/
private String name;
/**
* 身份证号
*/
private String idNo;
/**
* 银行卡号
*/
private String cardNo;
/**
* 银行code
*/
private String bankCode;
/**
* websocket通信标志位
*/
private String symbol;
}
package cn.qg.qaplatform.process;
import cn.qg.qaplatform.config.WebSocketServer;
import cn.qg.qaplatform.utils.DBUtils;
import cn.qg.qaplatform.utils.Encrypt.LexinEncrypt;
import cn.qg.qaplatform.utils.HttpClientUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.DigestUtils;
import java.net.URISyntaxException;
import java.sql.SQLException;
import java.util.*;
@Slf4j
public class Common {
public static String MD5Keywy = "qEAxMJBv";
public static String AESKeywy = "sxD8KO79EDK0N0AJ";
/**
* 登录KA联调平台
*/
public static String loginKA(String namespace) {
String url = "http://boss-" + namespace + ".liangkebang.net/login";
Map<String, Object> params = new HashMap<>();
params.put("username", "wenhaiyuan");
params.put("password", "123");
String jsonParams = JSON.toJSONString(params);
JSONObject result = HttpClientUtils.doPostJson(url, jsonParams);
System.out.println(result);
return result.get("data").toString();
}
/**
* 渠道订单审核通过
*/
public static boolean channelOrderApprove(String namespace, String orderNo, Integer amount, String fundType, boolean isPass, Integer term) {
String token = loginKA(namespace);
String url = "http://boss-" + namespace + ".liangkebang.net/order/approve";
Map<String, Object> params = new HashMap<>();
Map<String, Object> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("boss-token", token);
params.put("amount", amount.toString());
params.put("channelOrderNumber", orderNo);
params.put("fundType", fundType);
params.put("isPass", isPass);
params.put("period", term);
String jsonParams = JSON.toJSONString(params);
JSONObject result = HttpClientUtils.doPostJson(url, jsonParams, headers);
System.out.println(result);
return (boolean) result.get("data");
}
/**
* 提现
*/
public static boolean withDraw(String namespace, String channelCode, String channelOrderNumber, String bankCardNumber, String bankCode, String bankName, String reservePhoneNumber) {
String url = "http://qapi-" + namespace + ".liangkebang.net/ex/api/v2/withdraw/" + channelCode;
Map<String, Object> bizData = new HashMap<>();
bizData.put("channelOrderNumber", channelOrderNumber);
bizData.put("bankCardNumber", bankCardNumber);
bizData.put("bankCode", bankCode);
bizData.put("bankName", bankName);
bizData.put("reservePhoneNumber", reservePhoneNumber);
String bizDataStr = JSONObject.toJSONString(bizData);
String signStr = DigestUtils.md5DigestAsHex((bizDataStr + MD5Keywy).getBytes()).toLowerCase();
Map<String, String> content = new HashMap<>();
content.put("sign", signStr);
content.put("bizData", bizDataStr);
String contentStr = LexinEncrypt.encryptAndBase64Encode(JSONObject.toJSONString(content), AESKeywy);
Map<String, Object> headers = new HashMap<>();
headers.put("Content-Type", "application/x-www-form-urlencoded");
JSONObject result = HttpClientUtils.doPost(url, "content=" + contentStr);
String response = LexinEncrypt.decryptAfterBase64Decode(result.get("content").toString(), AESKeywy);
log.info("提现后结果为:" + response);
return true;
}
/**
* 查询渠道订单号
*/
public static String queryChannelOrderNoByPhone(String namespace, String phoneNo, Integer channel) throws SQLException {
String userId = Xyqb.checkUserId(namespace, phoneNo).get("id").toString();
String sql = "SELECT channel_order_no FROM order_mapping WHERE qg_user_id=" + userId + " and registered_from=" + channel + " order by id desc limit 0,1";
DBUtils dbUtils = new DBUtils(namespace, "cash_loan_flow", "qa", "qatest");
Map map = dbUtils.queryForMap(sql);
String channelOrderNo = map.get("channel_order_no").toString();
log.info("{}查询到的渠道订单号为:{}", phoneNo, channelOrderNo);
return channelOrderNo;
}
/**
* 查询loanId
*/
public static Integer queryLoanId(String namespace, String phoneNo, Integer channel) throws SQLException {
String userId = Xyqb.checkUserId(namespace, phoneNo).get("id").toString();
String sql = "SELECT id FROM loan_application_history WHERE user_id=" + userId + " order by id desc limit 0,1";
DBUtils dbUtils = new DBUtils(namespace, "xyqb", "qa", "qatest");
Map map = dbUtils.queryForMap(sql);
String loanId = map.get("id").toString();
log.info("{}查询到的loanId为:{}", phoneNo, loanId);
return Integer.parseInt(loanId);
}
public static boolean assignFundCorp(String namespace, Integer fundId) {
// 登录资金方OP
String fundOpToken = Xyqb.loginFundOP(namespace);
boolean isAleadyAssign = false;
// 检查是否已分配资产计划
try {
isAleadyAssign = Xyqb.assignFundOrNot(namespace, fundId, fundOpToken);
} catch (URISyntaxException e) {
e.printStackTrace();
}
boolean assignResult = false;
boolean unblockResult = false;
// 如果未分配
if (!isAleadyAssign) {
// 分配资产计划
assignResult = Xyqb.setFundPlan(namespace, fundId, fundOpToken);
// 打开推送放款
unblockResult = Xyqb.unblockLoan(namespace, fundId, fundOpToken);
if (assignResult && unblockResult) {
return true;
}
return false;
} else {
return true;
}
}
}
This diff is collapsed.
package cn.qg.qaplatform.process.xyqb;
package cn.qg.qaplatform.process;
import cn.qg.qaplatform.config.WebSocketServer;
import cn.qg.qaplatform.utils.DBUtils;
......@@ -19,7 +19,7 @@ import java.util.List;
import java.util.Map;
@Slf4j
public class MainProcess {
public class Xyqb {
public static String symbol = null;
......@@ -68,7 +68,7 @@ public class MainProcess {
DBUtils dbUtils = new DBUtils(namespace, "xyqb_user", "qa", "qatest");
Map result = dbUtils.queryForMap(sql);
String uuid = result.get("uuid").toString();
Long userId = (Long) result.get("id");
String userId = result.get("id").toString();
log.info("查询用户中心结果: " + result);
if (symbol != null) {
WebSocketServer.sendInfo("查询用户中心id:" + result, symbol);
......@@ -521,7 +521,7 @@ public class MainProcess {
/**
* 二次风控
*/
public static boolean externalQuotaOrderAuditNotify(String namespace, String token, String uuid, Integer loanId, Integer bizType, boolean auditResult) {
public static boolean externalQuotaOrderAuditNotify(String namespace, Integer bizChannel, String token, String uuid, Integer loanId, Integer bizType, boolean auditResult) {
String url = "http://clotho-" + namespace + ".liangkebang.net" + "/external/quota/order_audit/notify";
Map<String, Object> headers = new HashMap<>();
headers.put("Content-Type", "application/x-www-form-urlencoded");
......@@ -529,7 +529,7 @@ public class MainProcess {
Map<String, Object> params = new HashMap<>();
params.put("code", 0);
params.put("msg", "success");
params.put("bizChannel", 1);
params.put("bizChannel", bizChannel);
params.put("uuid", uuid);
params.put("bizNo", loanId);
params.put("bizType", bizType);
......
package cn.qg.qaplatform.service;
import cn.qg.qaplatform.domain.ApplyDataVo;
/**
* 乐信数据
* @author libo
*/
public interface LexinDataService {
boolean genLexinData(ApplyDataVo applyDataVo) throws Exception;
}
package cn.qg.qaplatform.service;
/**
* 查询造数据流程中的状态
*/
public interface QueryInProcessStatusService {
/**
* 查询资方分配的进度
*/
void queryFundingAssignProgress(String namespace, String phoneNo, Integer fundId, String symbol) throws InterruptedException;
/**
* 查询发起提现的进度
*/
void queryLoanProgress(String namespace, String phoneNo, String symbol) throws InterruptedException;
}
package cn.qg.qaplatform.service;
import cn.qg.qaplatform.domain.ApplyLoanInfo;
import cn.qg.qaplatform.domain.ApplyDataVo;
import cn.qg.qaplatform.domain.GenLoanUser;
import java.io.IOException;
import java.sql.SQLException;
public interface GenUserDataService {
public interface XyqbDataService {
/**
* 分配资金方
......@@ -15,32 +14,32 @@ public interface GenUserDataService {
/**
* 授信
* @param applyLoanInfo 造数据的相关信息
* @param applyDataVo 造数据的相关信息
* @return 成功或失败
*/
boolean quotaAuth(ApplyLoanInfo applyLoanInfo, boolean auditResult) throws Exception;
boolean quotaAuth(ApplyDataVo applyDataVo, boolean auditResult) throws Exception;
/**
* 提现
* @param applyLoanInfo 造数据相关信息
* @param applyDataVo 造数据相关信息
* @return 成功或失败
*/
boolean withDraw(ApplyLoanInfo applyLoanInfo, boolean auditResult) throws Exception;
boolean withDraw(ApplyDataVo applyDataVo, boolean auditResult) throws Exception;
/**
* 放款
* @param applyLoanInfo
* @param applyDataVo
* @return
*/
boolean makeLoan(ApplyLoanInfo applyLoanInfo, boolean payStatus) throws Exception;
boolean makeLoan(ApplyDataVo applyDataVo, boolean payStatus) throws Exception;
/**
* 造数据
* @param applyLoanInfo
* @param applyDataVo
* @return
* @throws Exception
*/
boolean genLoanUser(ApplyLoanInfo applyLoanInfo) throws Exception;
boolean genLoanUser(ApplyDataVo applyDataVo) throws Exception;
/**
* 获取用户状态
......
package cn.qg.qaplatform.service.impl;
import cn.qg.qaplatform.common.enums.ChannelEnum;
import cn.qg.qaplatform.domain.ApplyDataVo;
import cn.qg.qaplatform.process.Common;
import cn.qg.qaplatform.process.Lexin;
import cn.qg.qaplatform.process.Xyqb;
import cn.qg.qaplatform.service.QueryInProcessStatusService;
import cn.qg.qaplatform.service.LexinDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.Map;
@Service
@Slf4j
public class LexinDataServiceImpl implements LexinDataService {
@Autowired
QueryInProcessStatusService queryInProcessStatusService;
@Autowired
RedisTemplate redisTemplate;
@Override
public boolean genLexinData(ApplyDataVo applyDataVo) throws Exception {
String namespace = applyDataVo.getNamespace();
String phoneNo = applyDataVo.getPhoneNo();
String bankCardNo = applyDataVo.getBankCardNo();
String bankCode = applyDataVo.getBankCode();
String bankName = applyDataVo.getBankName();
Integer fundId = applyDataVo.getFundId();
String symbol = applyDataVo.getSymbol();
Integer amount = applyDataVo.getAmount();
Integer term = applyDataVo.getTerm();
Xyqb.symbol = symbol;
// 分配资产计划
boolean fundAssignResult = Common.assignFundCorp(namespace, fundId);
// 进件
boolean createOrderResult = Lexin.createOrder(applyDataVo);
setUserStatusRedisValue(namespace, phoneNo, 0);
if (!createOrderResult) {
return false;
}
String channelOrderNo = Common.queryChannelOrderNoByPhone(namespace, phoneNo, ChannelEnum.LEXIN.getChannelId());
Common.channelOrderApprove(namespace, channelOrderNo, amount, "0", true, term);
// 查询到资方分配成功才进行下一步
queryInProcessStatusService.queryFundingAssignProgress(namespace, phoneNo, fundId, symbol);
// api提现
boolean withDrawResult = Common.withDraw(namespace, "LEXIN", channelOrderNo, bankCardNo, bankCode, bankName, phoneNo);
if (!withDrawResult) {
return false;
}
setUserStatusRedisValue(namespace, phoneNo, 2);
// 二次风控
String token = Xyqb.login(namespace, 1, phoneNo);
Map userInfoResult = Xyqb.checkUserId(namespace, phoneNo);
String uuid = userInfoResult.get("uuid").toString();
String userId = userInfoResult.get("id").toString();
Integer loanId = Common.queryLoanId(namespace, phoneNo, ChannelEnum.LEXIN.getChannelId());
boolean secondWindControlResult = Xyqb.externalQuotaOrderAuditNotify(namespace, 1, token, uuid, loanId, 11, true);
Xyqb.modifyContactStatus(namespace, userId);
// 放款
String opToken = Xyqb.loginOP(namespace);
// 查询待打款数量
Map<String, Integer> peopleMap = Xyqb.checkWaitingFundingCorpOperatePeople(namespace, fundId);
Integer money = peopleMap.get("money");
Integer people = peopleMap.get("people");
// 修改待放款用户创建时间
Xyqb.modifyWaitingFundingCreatedAt(namespace, loanId);
Thread.sleep(5000);
// 直接打款
Xyqb.fundsPlanLoanApply(namespace,opToken, fundId, money, people);
Thread.sleep(30000);
// 放款结果通知
boolean makeLoanResult = Xyqb.payNotify(namespace, loanId, true);
setUserStatusRedisValue(namespace, phoneNo, 3);
return makeLoanResult;
}
public void setUserStatusRedisValue(String namespace, String phoneNo, Integer status) {
String redisKey = namespace + "_" + phoneNo;
redisTemplate.opsForValue().set(redisKey, status);
}
}
package cn.qg.qaplatform.service.impl;
import cn.qg.qaplatform.config.WebSocketServer;
import cn.qg.qaplatform.service.QueryBasicLoanStatusDataService;
import cn.qg.qaplatform.service.QueryInProcessStatusService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class QueryInProcessStatusServiceImpl implements QueryInProcessStatusService {
@Autowired
QueryBasicLoanStatusDataService queryBasicLoanStatusDataService;
@Override
public void queryFundingAssignProgress(String namespace, String phoneNo, Integer fundId, String symbol) throws InterruptedException {
String userId = queryBasicLoanStatusDataService.getUserInfoByPhoneNo(namespace, phoneNo).getUserId();
while (true) {
Integer searchResult = queryBasicLoanStatusDataService.getAssignFundIdByUserId(namespace, userId);
log.info(searchResult.toString());
if (fundId.equals(searchResult)) {
log.info("用户:" + userId + "资方分配成功!");
if (!StringUtils.isEmpty(symbol)) {
WebSocketServer.sendInfo("查询到的资方为:" + searchResult +",资方分配成功.", symbol);
}
break;
} else {
if (!StringUtils.isEmpty(symbol)) {
WebSocketServer.sendInfo("查询到的资方为:" + searchResult +",资方还未分配成功,10秒后重试", symbol);
}
Thread.sleep(10000);
}
}
}
@Override
public void queryLoanProgress(String namespace, String phoneNo, String symbol) throws InterruptedException {
String userId = queryBasicLoanStatusDataService.getUserInfoByPhoneNo(namespace, phoneNo).getUserId();
while (true) {
Integer progress = queryBasicLoanStatusDataService.getLoanProgressByUserId(namespace, userId);
if (progress == 15) {
log.info("用户:" + userId + "放款成功!");
if (!StringUtils.isEmpty(symbol)) {
WebSocketServer.sendInfo("放款成功.", symbol);
}
break;
} else {
if (!StringUtils.isEmpty(symbol)) {
WebSocketServer.sendInfo("查询到的状态为:" + progress + ",资方放款中,30秒后重新查询状态!", symbol);
}
Thread.sleep(30000);
}
}
}
}
package cn.qg.qaplatform.utils.Encrypt;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.misc.BASE64Decoder;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;
public class LexinEncrypt {
private static final Logger LOGGER = LoggerFactory.getLogger(LexinEncrypt.class);
/**
* KEY算法
*/
private static final String KEY_ALGORITHM = "AES";
/**
* 加密算法
* "/算法/模式/补码方式"
*/
public static final String CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding";
/**
* KEY长度
*/
private static final int KEY_SIZE = 128;
/**
* 编码
*/
private static final String CHARSET = "UTF-8";
public static void main(String[] args) {
try {
String key = getKeyStr();
} catch (Exception e) {
LOGGER.error("e={}", ExceptionUtils.getStackTrace(e));
}
}
/**
* 获取密钥 - Base64
*
* @return
* @throws Exception
*/
public static String getKeyStr() throws Exception {
return Base64.encodeBase64String(getKey().getEncoded());
}
/**
* 获取密钥
*
* @return
* @throws Exception
*/
public static Key getKey() throws Exception {
// 实例化
KeyGenerator kg = KeyGenerator.getInstance(KEY_ALGORITHM);
// AES 要求密钥长度为128位、192位或256位
kg.init(KEY_SIZE);
// 生成密钥
SecretKey secretKey = kg.generateKey();
return secretKey;
}
/**
* 数据加密
*
* @param data 待加密的数据
* @param key 加密使用的KEY
* @return 加密之后的数据
*/
public static String encryptAndBase64Encode(String data, String key) {
try {
return encryptAndBase64Encode(data.getBytes(CHARSET), key);
} catch (Exception e) {
LOGGER.error("AES加密报错,error={}", e);
return null;
}
}
/**
* 加密后base64编码,指定algorithm
* @param data
* @param key
* @param algorithm
* @return
*/
public static String encryptAndBase64Encode(String data, String key, String algorithm, AESKeyType aesKeyType) {
try {
return encryptAndBase64Encode(data.getBytes(CHARSET), key, algorithm, aesKeyType);
} catch (Exception e) {
LOGGER.error("AES加密报错,error={}", e);
return null;
}
}
/**
* 对字节数组加密
* @param data
* @param key
* @return
*/
public static String encryptAndBase64Encode(byte[] data, String key) {
try {
if (StringUtils.isBlank(key)) {
LOGGER.error("AES Key为空");
return null;
}
return doEncryptAndBase64Encode(data, key, CIPHER_ALGORITHM, AESKeyType.plain);
} catch (Exception ex) {
LOGGER.error("AES加密报错,error={}", ex);
return null;
}
}
/**
* 对字节数组加密,指定algorithm
* @param data
* @param key
* @return
*/
public static String encryptAndBase64Encode(byte[] data, String key, String algorithm, AESKeyType aesKeyType) {
try {
if (StringUtils.isBlank(key)) {
LOGGER.error("AES Key为空");
return null;
}
if (StringUtils.isBlank(algorithm)) {
LOGGER.error("AES 算法为空");
return null;
}
return doEncryptAndBase64Encode(data, key, algorithm, aesKeyType);
} catch (Exception ex) {
LOGGER.error("AES加密报错,error={}", ex);
return null;
}
}
/**
* 执行加密和base64编码
* @param data
* @param key
* @param algorithm
* @param aesKeyType
* @return
* @throws Exception
*/
private static String doEncryptAndBase64Encode(byte[] data, String key, String algorithm, AESKeyType aesKeyType) throws Exception {
algorithm = StringUtils.isBlank(algorithm)?CIPHER_ALGORITHM:algorithm;
byte[] raw = toKey(key, aesKeyType);
SecretKeySpec skeySpec = new SecretKeySpec(raw, KEY_ALGORITHM);
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(data);
return new Base64().encodeToString(encrypted);
}
/**
* 数据解密,返回字符串
* @param data 待解密的数据
* @param key 解密使用的KEY
* @return 解密之后的数据
*/
public static String decryptAfterBase64Decode(String data, String key) {
try {
byte[] bytes = decryptAfterBase64DecodeToByte(data, key);
if (bytes != null && bytes.length > 0){
return new String(bytes, CHARSET);
}
} catch (Exception e) {
LOGGER.error("AES解密报错,error={}", e);
}
return null;
}
/**
* base64解码后解密,指定algorithm
* @param data
* @param key
* @param algorithm
* @return
*/
public static String decryptAfterBase64Decode(String data, String key, String algorithm, AESKeyType aesKeyType) {
try {
byte[] bytes = decryptAfterBase64DecodeToByte(data, key, algorithm, aesKeyType);
if (bytes != null && bytes.length > 0){
return new String(bytes, CHARSET);
}
} catch (Exception e) {
LOGGER.error("AES解密报错,error={}", e);
}
return null;
}
/**
* 数据解密,返回字节数据
* @param data
* @param key
* @return
*/
public static byte[] decryptAfterBase64DecodeToByte(String data, String key) {
try {
if (StringUtils.isBlank(key)) {
LOGGER.error("AES Key为空");
return null;
}
return doDecryptAfterBase64DecodeToBtype(data, key, CIPHER_ALGORITHM, AESKeyType.plain);
} catch (Exception ex) {
LOGGER.error("AES解密报错:" + ex.toString());
return null;
}
}
/**
* base64解码后解密,返回字节数组,指定算法
* @param data
* @param key
* @param algorithm
* @return
*/
public static byte[] decryptAfterBase64DecodeToByte(String data, String key, String algorithm, AESKeyType aesKeyType) {
try {
if (StringUtils.isBlank(key)) {
LOGGER.error("AES Key为空");
return null;
}
if (StringUtils.isBlank(algorithm)) {
LOGGER.error("AES 算法为空");
return null;
}
return doDecryptAfterBase64DecodeToBtype(data, key, algorithm, aesKeyType);
} catch (Exception ex) {
LOGGER.error("AES解密报错:" + ex.toString());
return null;
}
}
/**
* 执行base64解码后解密
* @param data
* @param key
* @param algorithm
* @param aesKeyType
* @return
* @throws Exception
*/
private static byte[] doDecryptAfterBase64DecodeToBtype(String data, String key, String algorithm, AESKeyType aesKeyType) throws Exception {
algorithm = StringUtils.isBlank(algorithm)?CIPHER_ALGORITHM:algorithm;
byte[] raw = toKey(key, aesKeyType);
SecretKeySpec skeySpec = new SecretKeySpec(raw, KEY_ALGORITHM);
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] encrypted1 = new Base64().decode(data);
byte[] original = cipher.doFinal(encrypted1);
return original;
}
/**
* 转换密钥
* @param key
* @param aesKeyType
* @return
* @throws Exception
*/
private static byte[] toKey(String key, AESKeyType aesKeyType) throws Exception {
if (aesKeyType == AESKeyType.plain){
return key.getBytes(CHARSET);
}else if (aesKeyType == AESKeyType.base64){
return new BASE64Decoder().decodeBuffer(key);
}
return null;
}
public enum AESKeyType {
plain("普通字符串"),
base64("base64编码字符串");
public String text;
AESKeyType(String text){
this.text = text;
}
}
}
......@@ -2,6 +2,7 @@ package cn.qg.qaplatform.utils;
import com.alibaba.fastjson.JSONException;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.expression.JsonExpression;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
......@@ -162,8 +163,11 @@ public class HttpClientUtils {
CloseableHttpResponse response = client.execute(post);
HttpEntity responseEntity = response.getEntity();
String responseString = EntityUtils.toString(responseEntity, "utf-8");
try {
jsonResult = JSONObject.parseObject(responseString);
} catch (JSONException e) {
jsonResult.put("content", responseString);
}
} catch (IOException e) {
e.printStackTrace();
}
......
This diff is collapsed.
......@@ -16,30 +16,31 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class xyqb {
public static String namespace = "xyqb";
public class Xyqb {
public static String namespace = "pre";
public static Integer channelId = 1;
public static Integer fundId = 1040;
public static String phone = "18300120382";
public static Integer fundId = 1010;
public static String phone = "13039252170";
public static String token = "";
public static String uuid = "";
public static Long userId;
public static String productId = "1";
public static String name = "刘志国";
public static String idNo = "455129197108031107";
public static String name = "刘凯乐";
public static String idNo = "371101199508060897";
public static Long createdFrom = 1L;
public static String ocrToken;
public static String idCardNo = "6222800007700762652";
public static String idCardNo = "371101199508060897";
public static String orderNo = "";
public static Integer bizType = 0;
public static String auditResult = "true";
public static String creditAmount = "10000";
public static Integer maxAmount = 8000;
public static Integer minAmount = 5000;
public static Integer term = 3;
public static String creditAmount = "9600"; // 授信时返回的额度
public static Integer maxAmount = 9600; // 提现时的额度,
public static Integer minAmount = 1000; //
public static Integer term = 12;
public static Long accountId;
public static String payToken = "";
public static String cardNo = "6222800005354563814";
public static String cardNo = "6228220000020362026";
public static String bankCode = "ABC";
public static Integer cardId;
public static Integer cardBindInfoId;
public static Integer loanId;
......@@ -333,6 +334,10 @@ public class xyqb {
if (fundId == 1040) {
fundInfoObject.put("fundProductId", 1061);
}
// 平银新增fundProductId
if (fundId == 1030) {
fundInfoObject.put("fundProductId", 1060);
}
fundInfoList.add(fundInfoObject);
firstTerm.put("fundInfo", fundInfoList);
terms.add(firstTerm);
......@@ -402,7 +407,7 @@ public class xyqb {
params.put("preservePhoneNo", phone);
params.put("province", 110000);
params.put("city", 110101);
params.put("bankCode", "CCB");
params.put("bankCode", bankCode);
JSONObject result = HttpClientUtils.doPost(url, params, headers);
System.out.println("绑卡发送短信:" + result);
}
......@@ -454,6 +459,7 @@ public class xyqb {
params.put("productId", productId);
params.put("cardId", cardId);
params.put("cardBindInfoId", cardBindInfoId);
params.put("purpose", "手机数码");
JSONObject result = HttpClientUtils.doPost(url, params, headers);
System.out.println("绑卡后提现:" + result);
Map respData = (Map) result.get("data");
......@@ -658,58 +664,58 @@ public class xyqb {
public static void main(String[] args) throws Exception {
// 分配资金方
loginFundOP();
unblockLoan();
boolean result = assignFundOrNot();
if (!result) {
setFundPlan();
unblockLoan();
}
// 授信
login();
checkUserId();
// 如果是云信,则需要插入银行卡
if (fundId == 1040) {
insertBankCardOfYunxing();
}
syncSessionToXyqb();
creditSessionSync();
realNameVerified();
authBasicInfo();
enterAuthOcr();
uploadFrontOfIdCard();
uploadBackOfIdCard();
submitPhotoAuth();
credit();
submitAudit();
queryUserAuditRecord();
creditAuthNotify();
Thread.sleep(180000);
// loginFundOP();
// unblockLoan();
// boolean result = assignFundOrNot();
// if (!result) {
// setFundPlan();
// unblockLoan();
// }
//
// // 授信
// login();
// checkUserId();
// // 如果是云信,则需要插入银行卡
// if (fundId == 1040) {
// insertBankCardOfYunxing();
// }
// syncSessionToXyqb();
// creditSessionSync();
// realNameVerified();
// authBasicInfo();
// enterAuthOcr();
// uploadFrontOfIdCard();
// uploadBackOfIdCard();
// submitPhotoAuth();
// credit();
// submitAudit();
// queryUserAuditRecord();
// creditAuthNotify();
// Thread.sleep(180000);
// 绑卡提现
login();
checkUserId();
syncSessionToXyqb();
loginWithDrawPage();
getUserAccountId();
bindCard();
cardAuthSms();
cardAuthSmsConfirm();
getBindCardList();
createLoan();
externalQuotaOrderAuditNotify();
modifyContactStatus();
Thread.sleep(10000);
// 放款
loginOP();
checkWaitingFundingCorpOperatePeople();
modifyWaitingFundingCreatedAt();
Thread.sleep(10000);
fundsPlanLoanApply();
Thread.sleep(10000);
payNotify();
// login();
// checkUserId();
// syncSessionToXyqb();
// loginWithDrawPage();
// getUserAccountId();
// bindCard();
// cardAuthSms();
// cardAuthSmsConfirm();
// getBindCardList();
// createLoan();
// externalQuotaOrderAuditNotify();
// modifyContactStatus();
// Thread.sleep(10000);
//
// // 放款
// loginOP();
// checkWaitingFundingCorpOperatePeople();
// modifyWaitingFundingCreatedAt();
// Thread.sleep(10000);
// fundsPlanLoanApply();
// Thread.sleep(10000);
// payNotify();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment