|
|
package com.yohoufo.user.service.impl;
|
|
|
|
|
|
import com.yoho.core.config.ConfigReader;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.tools.common.beans.ApiResponse;
|
|
|
import com.yohoufo.dal.user.IUserAuthorizeHistoryDao;
|
|
|
import com.yohoufo.dal.user.IUserAuthorizeInfoDao;
|
|
|
import com.yohoufo.dal.user.model.UserAuthorizeHistory;
|
|
|
import com.yohoufo.dal.user.model.UserAuthorizeInfo;
|
|
|
import com.yohoufo.user.cache.CacheService;
|
|
|
import com.yohoufo.user.common.EnumBankBackCode;
|
|
|
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
|
|
|
import com.yohoufo.user.responseVO.AuthorizeResultRespVO;
|
|
|
import com.yohoufo.user.service.IRealNameAuthorizeService;
|
|
|
import com.yohoufo.user.service.risk.GraphVerifyService;
|
|
|
import lombok.Data;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.commons.codec.digest.HmacUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.HttpClientErrorException;
|
|
|
import org.springframework.web.client.HttpServerErrorException;
|
|
|
import org.springframework.web.client.RestClientException;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.Random;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
/**
|
|
|
* 用户身份实名认证
|
|
|
*/
|
|
|
@Service("realNameAuthorizeServiceImpl")
|
|
|
public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(RealNameAuthorizeServiceImpl.class);
|
|
|
|
|
|
private final static DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
|
|
|
//请求实名认证银联接口url 测试环境
|
|
|
private final String requestUrl="http://58.247.0.18:29015/v1/datacenter/smartverification/bankcard/verify";
|
|
|
//请求实名认证银联接口url 生产环境
|
|
|
//private final String requestUrl="https://api-mop.chinaums.com/v1/datacenter/smartverification/bankcard/verify";
|
|
|
|
|
|
ExecutorService executeService = Executors.newFixedThreadPool(10);
|
|
|
|
|
|
@Autowired
|
|
|
private IUserAuthorizeInfoDao userAuthorizeInfoDao;
|
|
|
|
|
|
@Autowired
|
|
|
private IUserAuthorizeHistoryDao userAuthorizeHistoryDao;
|
|
|
private CacheService cacheService;
|
|
|
|
|
|
@Resource(name="authorizeBankRestTemplate")
|
|
|
private RestTemplate restTemplate;
|
|
|
/* @Autowired
|
|
|
private GraphVerifyService graphVerifyService;*/
|
|
|
|
|
|
@Resource(name = "core-config-reader")
|
|
|
private ConfigReader configReader;
|
|
|
/* @Resource(name="authorizeBankRestTemplate")
|
|
|
private RestTemplate restTemplate;*/
|
|
|
|
|
|
@Autowired
|
|
|
private CacheService cacheService;
|
|
|
/* @Resource(name = "core-config-reader")
|
|
|
private ConfigReader configReader;*/
|
|
|
|
|
|
@Autowired
|
|
|
private GraphVerifyService graphVerifyService;
|
|
|
/* @Autowired
|
|
|
private IUserAuthorizeHistoryDao userAuthorizeHistoryDao;*/
|
|
|
//private final static DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
|
|
|
//请求实名认证银联接口url 测试环境
|
|
|
//private final String requestUrl="http://58.247.0.18:29015/v1/datacenter/smartverification/bankcard/verify";
|
|
|
//请求实名认证银联接口url 生产环境
|
|
|
//private final String requestUrl="https://api-mop.chinaums.com/v1/datacenter/smartverification/bankcard/verify";
|
|
|
|
|
|
//ExecutorService executeService = Executors.newFixedThreadPool(10);
|
|
|
|
|
|
|
|
|
public UserAuthorizeInfo getValidAuthorizeInfo(int uid){
|
|
|
logger.info("RealNameAuthorizeServiceImpl getValidAuthorizeInfo uid is {} ",uid);
|
|
|
// 从redis缓存中获取
|
|
|
UserAuthorizeInfo authorizeInfo = cacheService.getUserAuthorizeInfo(uid);
|
|
|
logger.info("RealNameAuthorizeServiceImpl getValidAuthorizeInfo uid is {} ,redis info is {} ",uid,authorizeInfo);
|
|
|
if(null != authorizeInfo){
|
|
|
return authorizeInfo;
|
|
|
}
|
|
|
|
|
|
//如果不存在,则从数据库获取
|
|
|
authorizeInfo= userAuthorizeInfoDao.selectValidAuthorizeInfoByUid(uid);
|
|
|
logger.info("RealNameAuthorizeServiceImpl getValidAuthorizeInfo uid is {} ,database info is {} ",uid,authorizeInfo);
|
|
|
if(authorizeInfo!=null){
|
|
|
//保存到redis
|
|
|
try{
|
|
|
cacheService.setUserAuthorizeInfo( authorizeInfo);
|
|
|
}catch(Exception e){
|
|
|
logger.warn("set valid authorize info to redis error. uid={}", uid);
|
|
|
}
|
|
|
cacheService.setUserAuthorizeInfo( authorizeInfo);
|
|
|
}
|
|
|
return authorizeInfo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 实名身份认证
|
|
|
*/
|
|
|
public JSONObject authorizeRealNameWithBank(RealNameAuthorizeReqVO reqVO) throws ServiceException {
|
|
|
public void saveAuthorizeInfo(RealNameAuthorizeReqVO reqVO){
|
|
|
logger.info("real name saveAuthorizeInfo reqVO {}", reqVO);
|
|
|
int uid=reqVO.getUid();
|
|
|
String alipayAccount=reqVO.getAlipayAccount();
|
|
|
String certName=reqVO.getCertName();
|
|
|
long ts=getLocalDateTime().toEpochSecond(ZoneOffset.of("+8"));
|
|
|
UserAuthorizeInfo userAuthorizeInfo =new UserAuthorizeInfo();
|
|
|
userAuthorizeInfo.setUid(uid);
|
|
|
userAuthorizeInfo.setValidStatus(1);
|
|
|
userAuthorizeInfo.setAlipayAccount(alipayAccount);
|
|
|
userAuthorizeInfo.setCertName(certName);
|
|
|
userAuthorizeInfo.setCreateTime(ts);
|
|
|
userAuthorizeInfo.setUpdateTime(ts);
|
|
|
logger.info("real name saveAuthorizeInfo begin UserAuthorizeInfo {}", userAuthorizeInfo);
|
|
|
userAuthorizeInfoDao.insert(userAuthorizeInfo);
|
|
|
logger.info("real name saveAuthorizeInfo end UserAuthorizeInfo {}", userAuthorizeInfo);
|
|
|
//保存之后放redis
|
|
|
//保存到redis
|
|
|
cacheService.setUserAuthorizeInfo( userAuthorizeInfo);
|
|
|
}
|
|
|
|
|
|
|
|
|
private LocalDateTime getLocalDateTime(){
|
|
|
LocalDateTime now=LocalDateTime.now();
|
|
|
return now;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************************************
|
|
|
* 银联实名身份认证相关,暂时不做,代码后续可去掉
|
|
|
**************************************************************************************************/
|
|
|
/* public JSONObject authorizeRealNameWithBank(RealNameAuthorizeReqVO reqVO) throws ServiceException {
|
|
|
int uid=reqVO.getUid();
|
|
|
String cardNo=reqVO.getCardNo();
|
|
|
String certNo=reqVO.getCertNo();
|
...
|
...
|
@@ -137,34 +136,34 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
jo.put("errInfo",responseResult.getErrInfo());
|
|
|
|
|
|
return jo;
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
/**
|
|
|
* 把失败写入redis,过期时间为30分钟
|
|
|
* 超过一定次数需要通知uic开启图像验证码
|
|
|
*/
|
|
|
public void recordFailTimesAndOpenGraphVerify(RealNameAuthorizeReqVO reqVO){
|
|
|
/*public void recordFailTimesAndOpenGraphVerify(RealNameAuthorizeReqVO reqVO){
|
|
|
Long failedNum=cacheService.incrementAuthorizeFailNum(reqVO.getUid());
|
|
|
if(failedNum.intValue()>=getAuthorizeGraphVerifyLimit()){
|
|
|
graphVerifyService.triggerUfoGraphVerifySwitch(reqVO.getApp_type(),reqVO.getClient_type(), reqVO.getApp_version(), reqVO.getFromPage(),
|
|
|
reqVO.getUdid(), reqVO.getDegrees());
|
|
|
}
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取图像验证码开启验证次数
|
|
|
*/
|
|
|
public int getAuthorizeGraphVerifyLimit() {
|
|
|
/*public int getAuthorizeGraphVerifyLimit() {
|
|
|
int time = configReader.getInt("ufo.passport.authorize.graph.verify.count", 3);
|
|
|
logger.info("RealNameAuthorizeServiceImpl getGraphVerifyLimit result is {}", time);
|
|
|
return time;
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
/**
|
|
|
* 组织银联实名认证的请求报文
|
|
|
*/
|
|
|
private JSONObject constructMsg(String cardNo, String certNo, String name){
|
|
|
/*private JSONObject constructMsg(String cardNo, String certNo, String name){
|
|
|
JSONObject msgContentParams = new JSONObject();
|
|
|
msgContentParams.put("cardNo",cardNo);//卡号
|
|
|
msgContentParams.put("certNo",certNo);//证件号
|
...
|
...
|
@@ -172,13 +171,13 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
msgContentParams.put("name",name);//证件姓名
|
|
|
msgContentParams.put("personalMandate","1"); //个人是否授权,1表示授权,0表示未授权,只能是授权用户
|
|
|
return msgContentParams;
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
/**
|
|
|
* 请求银联接口,获取返回信息
|
|
|
* 捕获所有异常
|
|
|
*/
|
|
|
private PostBankResult postRequest(JSONObject msgContentParams,String authorizationContentByOpenBodySig){
|
|
|
/* private PostBankResult postRequest(JSONObject msgContentParams,String authorizationContentByOpenBodySig){
|
|
|
PostBankResult result=new PostBankResult();
|
|
|
try{
|
|
|
//组成post的请求参数
|
...
|
...
|
@@ -252,20 +251,20 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Data
|
|
|
*/
|
|
|
/* @Data
|
|
|
private static class PostBankResult {
|
|
|
private boolean sucFlag;
|
|
|
private int statusCode;
|
|
|
private String errCode;
|
|
|
private String errInfo;
|
|
|
private String backMsg;
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
/**
|
|
|
* 无论成功还是失败,都把访问记录日志表
|
|
|
*/
|
|
|
private void recordHistory(int uid,String cardNo,String certNo,String name,PostBankResult responseResult ,long ts){
|
|
|
/* private void recordHistory(int uid,String cardNo,String certNo,String name,PostBankResult responseResult ,long ts){
|
|
|
UserAuthorizeHistory history=new UserAuthorizeHistory();
|
|
|
history.setUid(uid);
|
|
|
history.setCardNo(cardNo);
|
...
|
...
|
@@ -286,7 +285,7 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
logger.error("RealNameAuthorizeServiceImpl authorizeRealNameWithBank userAuthorizeHistoryDao insert history {} error {}",history,e);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -294,7 +293,7 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
* 内容生成算法请参考接口文档
|
|
|
* @param msgContentParams 请求报文
|
|
|
*/
|
|
|
public String generateAuthorizationByOpenBodySig(JSONObject msgContentParams){
|
|
|
/* public String generateAuthorizationByOpenBodySig(JSONObject msgContentParams){
|
|
|
//产品ID,由商务提供
|
|
|
String appId="2c909a515499b76b01549a01d2730000";
|
|
|
String appKey="keyqinchao";
|
...
|
...
|
@@ -305,14 +304,14 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
|
|
|
//timestamp="20180911154812";
|
|
|
//nonce=26713;
|
|
|
/******************** 根据报文体,生成签名 **********/
|
|
|
*//******************** 根据报文体,生成签名 **********//*
|
|
|
//1.报文内容转字节数组 ,sha256加密转16进制后再转小写
|
|
|
String sha256_hex_lower= DigestUtils.sha256Hex(msgContentParams.toString()).toLowerCase();
|
|
|
//2.生成代签名字符串
|
|
|
String prepare_sig_str=appId+timestamp+nonce+sha256_hex_lower;
|
|
|
//3.HmacSHA256签名 ,并base64编码
|
|
|
String signature= Base64.encodeBase64String(HmacUtils.hmacSha256(appKey, prepare_sig_str));
|
|
|
/****************************************************/
|
|
|
*//****************************************************//*
|
|
|
|
|
|
//得到授权内容
|
|
|
StringBuilder sb=new StringBuilder("OPEN-BODY-SIG ");
|
...
|
...
|
@@ -321,10 +320,6 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
sb.append("Nonce=\"").append(nonce).append("\", ");
|
|
|
sb.append("Signature=\"").append(signature).append("\"");
|
|
|
return sb.toString();
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
private LocalDateTime getLocalDateTime(){
|
|
|
LocalDateTime now=LocalDateTime.now();
|
|
|
return now;
|
|
|
}
|
|
|
} |
...
|
...
|
|