Authored by qinchao

绑卡接口

... ... @@ -15,9 +15,8 @@ public class UserAuthorizeInfo {
//生效状态:1 生效 ; 0 不生效
private Integer validStatus;
//卡号、身份证号、姓名
private String cardNo;
private String certNo;
//支付宝账号、姓名
private String alipayAccount;
private String certName;
private long createTime;
... ...
... ... @@ -5,29 +5,29 @@
<id column="id" property="id" jdbcType="INTEGER" />
<result column="uid" property="uid" jdbcType="INTEGER" />
<result column="valid_status" property="validStatus" jdbcType="INTEGER" />
<result column="card_no" property="cardNo" jdbcType="VARCHAR" />
<result column="cert_no" property="certNo" jdbcType="VARCHAR" />
<result column="alipay_account" property="alipayAccount" jdbcType="VARCHAR" />
<result column="cert_name" property="certName" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, uid, valid_status, card_no, cert_no, cert_name, create_time, update_time
id, uid, valid_status,alipay_account, cert_name, create_time, update_time
</sql>
<select id="selectValidAuthorizeInfoByUid" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from authorize_info
where uid = #{uid,jdbcType=INTEGER} and valid_status = 1
where uid = #{uid} and valid_status = 1
order by id desc limit 1
</select>
<insert id="insert" parameterType="com.yohoufo.dal.user.model.UserAuthorizeInfo" >
insert into authorize_info (uid, valid_status, card_no, cert_no, cert_name, create_time, update_time)
values (#{uid,jdbcType=INTEGER},#{validStatus,jdbcType=INTEGER},
#{cardNo,jdbcType=VARCHAR},#{certNo,jdbcType=VARCHAR},#{certName,jdbcType=VARCHAR},
#{createTime,jdbcType=BIGINT},#{updateTime,jdbcType=BIGINT})
insert into authorize_info (uid, valid_status, alipay_account, cert_name, create_time, update_time)
values (#{uid},#{validStatus},
#{alipayAccount},#{certName},
#{createTime},#{updateTime})
</insert>
... ...
... ... @@ -4,13 +4,10 @@ package com.yohoufo.user.controller.passport;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.dal.user.model.UserAuthorizeInfo;
import com.yohoufo.user.common.BankCardUtil;
import com.yohoufo.user.common.IDCardUtils;
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 net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -27,8 +24,6 @@ import org.springframework.web.bind.annotation.RestController;
public class RealNameAuthorizeController {
private Logger logger = LoggerFactory.getLogger(RealNameAuthorizeController.class);
private final String default_authorize_from_page="ufoUserAuthorize";
@Autowired
IRealNameAuthorizeService realNameAuthorizeService;
... ... @@ -38,9 +33,9 @@ public class RealNameAuthorizeController {
/**
* 获取实名认证账号信息
*/
@RequestMapping(params = "method=ufo.user.realNameQuery")
@RequestMapping(params = "method=ufo.user.aliPayAccountQuery")
public ApiResponse queryAuthorizeInfo( @RequestParam("uid") Integer uid) throws GatewayException {
logger.info("enter realNameAuthorize.query authorize info param uid is {}", uid);
logger.info("enter RealNameAuthorizeController queryAuthorizeInfo authorize info param uid is {}", uid);
//获取
UserAuthorizeInfo info= realNameAuthorizeService.getValidAuthorizeInfo(uid);
//封装结果
... ... @@ -48,9 +43,8 @@ public class RealNameAuthorizeController {
result.setUid(uid);
if(null!=info){
result.setAuthorizeFlag(true);
result.setCardNo(info.getCardNo());
result.setCertNo(info.getCertNo());
result.setName(info.getCertName());
result.setAlipayAccount(info.getAlipayAccount());
result.setCertName(info.getCertName());
result.setCreateTime(info.getCreateTime());
}else{
result.setAuthorizeFlag(false);
... ... @@ -62,46 +56,31 @@ public class RealNameAuthorizeController {
}
/**
* 实名认证
* 直接绑定支付宝账号,不再与第三方校验
*/
@RequestMapping(params = "method=ufo.user.realNameAuthorize")
@RequestMapping(params = "method=ufo.user.aliPayAccountBind")
public ApiResponse realNameAuthorize(RealNameAuthorizeReqVO reqVO) throws GatewayException {
logger.info("enter realNameAuthorize.authorize param reqVO is {}", reqVO);
//(1) 优先校验请求的参数
if (reqVO == null || StringUtils.isEmpty(reqVO.getCardNo())|| StringUtils.isEmpty(reqVO.getCertNo())|| StringUtils.isEmpty(reqVO.getName())){
throw new GatewayException(400, "参数不能为空!");
if (reqVO == null || StringUtils.isEmpty(reqVO.getAlipayAccount())|| StringUtils.isEmpty(reqVO.getCertName())){
throw new GatewayException(400, "支付宝账号、姓名不能为空!");
}
//(2) 校验用户id、身份证号、银行卡号的合法性
//(2) 校验用户id
if(reqVO.getUid()<=0){
throw new GatewayException(400, "uid参数为空!");
}
if(!IDCardUtils.validate(reqVO.getCertNo())){
throw new GatewayException(400, "身份证号不合法!");
}
if(!BankCardUtil.checkBankCard(reqVO.getCardNo())){
throw new GatewayException(400, "银行卡号不合法!");
}
//暂时在此定义fromPage
reqVO.setFromPage(default_authorize_from_page);
//验证图像验证码
graphVerifyService.checkAndVerifyGrap(reqVO.getApp_type(),reqVO.getClient_type(), reqVO.getApp_version(), reqVO.getFromPage(),
reqVO.getUdid(), reqVO.getDegrees());
//检查是否已经实名认证,如果已经认证直接返回
if(null!=realNameAuthorizeService.getValidAuthorizeInfo(reqVO.getUid())){
throw new GatewayException (400,"已实名认证");
}
//(3) 开始调用接口实名验证
JSONObject jo=realNameAuthorizeService.authorizeRealNameWithBank(reqVO);
//(3) 开始绑定支付宝账号
realNameAuthorizeService.saveAuthorizeInfo(reqVO);
ApiResponse apiResponse=new ApiResponse();
apiResponse.setData(jo);
ApiResponse apiResponse=new ApiResponse(200,"绑卡成功");
return apiResponse;
}
... ...
package com.yohoufo.user.requestVO;
import com.yoho.service.model.BaseBO;
import lombok.Data;
import java.util.List;
@Data
public class RealNameAuthorizeReqVO extends BaseBO {
// uid
private int uid;
// udid
private String udid;
private String fromPage;
private List<Integer> degrees;
private String app_type;
private String client_type;
private String app_version;
//卡号
private String cardNo;
//证件号码
private String certNo;
//支付宝账号
private String alipayAccount;
//证件姓名
private String name;
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public String getUdid() {
return udid;
}
public void setUdid(String udid) {
this.udid = udid;
}
public String getFromPage() {
return fromPage;
}
public void setFromPage(String fromPage) {
this.fromPage = fromPage;
}
public List<Integer> getDegrees() {
return degrees;
}
public void setDegrees(List<Integer> degrees) {
this.degrees = degrees;
}
public String getCardNo() {
return cardNo;
}
public void setCardNo(String cardNo) {
this.cardNo = cardNo;
}
public String getCertNo() {
return certNo;
}
public void setCertNo(String certNo) {
this.certNo = certNo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getApp_version() {
return app_version;
}
public void setApp_version(String app_version) {
this.app_version = app_version;
}
public String getClient_type() {
return client_type;
}
public void setClient_type(String client_type) {
this.client_type = client_type;
}
public String getApp_type() {
return app_type;
}
private String certName;
public void setApp_type(String app_type) {
this.app_type = app_type;
}
}
... ...
package com.yohoufo.user.responseVO;
import com.yoho.service.model.BaseBO;
import lombok.Data;
/**
* 实名认证结果查询
*/
@Data
public class AuthorizeResultRespVO extends BaseBO {
private int uid;
//是否已经实名认证
//是否已经绑卡
private boolean authorizeFlag;
//认证的银行账号
private String cardNo;
//认证的身份证号
private String certNo;
//支付宝账号
private String alipayAccount;
//认证的姓名
private String name;
private String certName;
//创建时间
private long createTime;
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public boolean isAuthorizeFlag() {
return authorizeFlag;
}
public void setAuthorizeFlag(boolean authorizeFlag) {
this.authorizeFlag = authorizeFlag;
}
public String getCardNo() {
return cardNo;
}
public void setCardNo(String cardNo) {
this.cardNo = cardNo;
}
public String getCertNo() {
return certNo;
}
public void setCertNo(String certNo) {
this.certNo = certNo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
}
... ...
package com.yohoufo.user.service;
import com.yoho.error.exception.ServiceException;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohoufo.dal.user.model.UserAuthorizeInfo;
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
import com.yohoufo.user.responseVO.AuthorizeResultRespVO;
import net.sf.json.JSONObject;
/**
... ... @@ -15,5 +12,7 @@ public interface IRealNameAuthorizeService {
UserAuthorizeInfo getValidAuthorizeInfo(int uid);
JSONObject authorizeRealNameWithBank(RealNameAuthorizeReqVO reqVO) throws ServiceException;
void saveAuthorizeInfo(RealNameAuthorizeReqVO reqVO);
//JSONObject authorizeRealNameWithBank(RealNameAuthorizeReqVO reqVO) throws ServiceException;
}
... ...
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;
}
}
... ...