Authored by mlge

用户绑定支付宝账号 接口

... ... @@ -8,4 +8,6 @@ public interface IUserAuthorizeInfoDao {
UserAuthorizeInfo selectValidAuthorizeInfoByUid(int uid);
int insert(UserAuthorizeInfo userAuthorizeInfo);
int insertSelective(UserAuthorizeInfo userAuthorizeInfo);
}
... ...
... ... @@ -24,4 +24,6 @@ public class UserAuthorizeInfo {
private long updateTime;
private String alipayUid;//支付宝uid 最长16位
}
... ...
... ... @@ -7,12 +7,13 @@
<result column="valid_status" property="validStatus" jdbcType="INTEGER" />
<result column="alipay_account" property="alipayAccount" jdbcType="VARCHAR" />
<result column="cert_name" property="certName" jdbcType="VARCHAR" />
<result column="alipay_uid" property="alipayUid" 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,alipay_account, cert_name, create_time, update_time
id, uid, valid_status,alipay_account, cert_name, alipay_uid,create_time, update_time
</sql>
<select id="selectValidAuthorizeInfoByUid" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
... ... @@ -31,4 +32,55 @@
</insert>
<insert id="insertSelective" parameterType="com.yohoufo.dal.user.model.UserAuthorizeInfo">
insert into authorize_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="uid != null">
uid,
</if>
<if test="validStatus != null">
valid_status,
</if>
<if test="alipayAccount != null">
alipay_account,
</if>
<if test="certName != null">
cert_name,
</if>
<if test="alipayUid != null">
alipay_uid,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="uid != null">
#{uid,jdbcType=INTEGER},
</if>
<if test="validStatus != null">
#{validStatus,jdbcType=INTEGER},
</if>
<if test="alipayAccount != null">
#{alipayAccount,jdbcType=VARCHAR},
</if>
<if test="certName != null">
#{certName,jdbcType=VARCHAR},
</if>
<if test="alipayUid != null">
#{alipayUid,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=INTEGER},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
</mapper>
\ No newline at end of file
... ...
... ... @@ -24,53 +24,32 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
public class RealNameAuthorizeController {
private Logger logger = LoggerFactory.getLogger(RealNameAuthorizeController.class);
private static final Logger logger = LoggerFactory.getLogger(RealNameAuthorizeController.class);
@Autowired
IRealNameAuthorizeService realNameAuthorizeService;
@Autowired
GraphVerifyService graphVerifyService;
/*@Autowired
GraphVerifyService graphVerifyService;*/
/**
* 获取实名认证账号信息
*/
@RequestMapping(params = "method=ufo.user.aliPayAccountQuery")
public ApiResponse queryAuthorizeInfo( @RequestParam("uid") Integer uid) throws GatewayException {
logger.info("enter RealNameAuthorizeController queryAuthorizeInfo authorize info param uid is {}", uid);
//获取
UserAuthorizeInfo info= realNameAuthorizeService.getValidAuthorizeInfo(uid);
//封装结果
AuthorizeResultRespVO result=new AuthorizeResultRespVO();
result.setUid(uid);
if(null!=info){
result.setAuthorizeFlag(true);
result.setAlipayAccount(info.getAlipayAccount());
//result.setAlipayMaskAccount(info.getAlipayMaskAccount());
result.setCertName(info.getCertName());
result.setCreateTime(info.getCreateTime());
//把账号部分信息隐藏
if(HideDataUtil.isEmail(info.getAlipayAccount())){
result.setAlipayMaskAccount(HideDataUtil.hideEmail(info.getAlipayAccount()));
}else if(UserInfoHiddenHelper.isPhone(info.getAlipayAccount())){
result.setAlipayMaskAccount(UserInfoHiddenHelper.hidePhoneNo(info.getAlipayAccount()));
}else if(info.getAlipayAccount().length()>2){
//即不是手机,又不是邮箱,只显示首末位
result.setAlipayMaskAccount(info.getAlipayAccount().substring(0,1)
+"****"
+info.getAlipayAccount().substring(info.getAlipayAccount().length()-1));
}else{
result.setAlipayMaskAccount(info.getAlipayAccount());
}
}else{
result.setAuthorizeFlag(false);
}
public ApiResponse queryAuthorizeInfo( @RequestParam("uid") Integer uid) {
logger.info("enter queryAuthorizeInfo authorize info param uid is {}", uid);
try{
AuthorizeResultRespVO result = realNameAuthorizeService.queryAuthorizeInfo(uid);
logger.info("queryAuthorizeInfo success! uid={},result={}", uid, result);
//返回结果
ApiResponse apiResponse=new ApiResponse();
ApiResponse apiResponse = new ApiResponse();
apiResponse.setData(result);
return apiResponse;
}catch (Exception e){
logger.warn("queryAuthorizeInfo error! uid={}, e :{}", uid, e);
ApiResponse apiResponse = new ApiResponse(201, "failed");
return apiResponse;
}
}
/**
* 实名认证
... ... @@ -107,4 +86,35 @@ public class RealNameAuthorizeController {
}
/**
* 新接口
* 支付宝第三方验证后, 调用接口 保存 用户对应的支付宝账号信息
*/
@RequestMapping(params = "method=ufo.user.aliPayAccountBindNew")
public ApiResponse aliPayAccountBindNew(RealNameAuthorizeReqVO reqVO) throws GatewayException {
logger.info("enter aliPayAccountBindNew reqVO is {}", reqVO);
//(1) 优先校验请求的参数
if (reqVO == null || StringUtils.isEmpty(reqVO.getAlipayUid()) ){
throw new GatewayException(400, "alipayUid参数为空!");
}
//(2) 校验用户id
if(reqVO.getUid() <= 0 ){
throw new GatewayException(400, "uid参数为空!");
}
//检查是否已经实名认证,如果已经认证直接返回
if(null != realNameAuthorizeService.getValidAuthorizeInfo(reqVO.getUid())){
throw new GatewayException (601,"已实名认证");
}
//(3) 开始绑定支付宝账号 入库
try{
realNameAuthorizeService.saveAuthorizeInfoNew(reqVO);
return new ApiResponse(200,"success!");
}catch(Exception e){
logger.warn("aliPayAccountBindNew error! reqVO ={}, e : {}", reqVO, e);
return new ApiResponse(201,"failed!");
}
}
}
... ...
... ... @@ -15,4 +15,6 @@ public class RealNameAuthorizeReqVO extends BaseBO {
//证件姓名
private String certName;
private String alipayUid;//支付宝uid 最长16位
}
... ...
package com.yohoufo.user.service;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.dal.user.model.UserAuthorizeInfo;
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
import net.sf.json.JSONObject;
... ... @@ -14,5 +15,10 @@ public interface IRealNameAuthorizeService {
void saveAuthorizeInfo(RealNameAuthorizeReqVO reqVO);
void saveAuthorizeInfoNew(RealNameAuthorizeReqVO reqVO);
AuthorizeResultRespVO queryAuthorizeInfo(Integer uid);
//JSONObject authorizeRealNameWithBank(RealNameAuthorizeReqVO reqVO) throws ServiceException;
}
... ...
package com.yohoufo.user.service.impl;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.common.utils.UserInfoHiddenHelper;
import com.yohoufo.dal.user.IUserAuthorizeInfoDao;
import com.yohoufo.dal.user.model.UserAuthorizeInfo;
import com.yohoufo.user.cache.CacheService;
import com.yohoufo.user.helper.HideDataUtil;
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
import com.yohoufo.user.service.IRealNameAuthorizeService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -19,7 +22,7 @@ import java.time.ZoneOffset;
*/
@Service("realNameAuthorizeServiceImpl")
public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
private Logger logger = LoggerFactory.getLogger(RealNameAuthorizeServiceImpl.class);
private static final Logger logger = LoggerFactory.getLogger(RealNameAuthorizeServiceImpl.class);
@Autowired
private IUserAuthorizeInfoDao userAuthorizeInfoDao;
... ... @@ -58,7 +61,7 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
}
//如果不存在,则从数据库获取
authorizeInfo= userAuthorizeInfoDao.selectValidAuthorizeInfoByUid(uid);
authorizeInfo = userAuthorizeInfoDao.selectValidAuthorizeInfoByUid(uid);
logger.info("RealNameAuthorizeServiceImpl getValidAuthorizeInfo uid is {} ,database info is {} ",uid,authorizeInfo);
if(authorizeInfo!=null){
//保存到redis
... ... @@ -90,6 +93,76 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService {
cacheService.setUserAuthorizeInfo( userAuthorizeInfo);
}
@Override
public void saveAuthorizeInfoNew(RealNameAuthorizeReqVO reqVO) {
logger.info("enter saveAuthorizeInfoNew reqVO = {}", reqVO);
int uid = reqVO.getUid();
String alipayAccount = reqVO.getAlipayAccount();
String certName = reqVO.getCertName();
String alipayUid = reqVO.getAlipayUid();
UserAuthorizeInfo userAuthorizeInfo =new UserAuthorizeInfo();
userAuthorizeInfo.setUid(uid);
userAuthorizeInfo.setValidStatus(1);
userAuthorizeInfo.setAlipayAccount(alipayAccount);
userAuthorizeInfo.setCertName(certName);
userAuthorizeInfo.setAlipayUid(alipayUid);
long create_time = System.currentTimeMillis() /1000;
userAuthorizeInfo.setCreateTime(create_time);
userAuthorizeInfoDao.insertSelective(userAuthorizeInfo);
logger.info("real name saveAuthorizeInfo success ,reqVO= {}", reqVO);
}
/**
* 根据uid 查询用户绑定的支付宝信息
* 旧版本:没有存alipayId(支付宝userId)
* 新版本:有alipayId
* @param uid
* @return
*/
@Override
public AuthorizeResultRespVO queryAuthorizeInfo(Integer uid) {
//获取
UserAuthorizeInfo info = getValidAuthorizeInfo(uid);
//封装结果
AuthorizeResultRespVO result = new AuthorizeResultRespVO();
result.setUid(uid);
if(null == info){//没有实名认证
result.setAuthorizeFlag(false);
return result;
}
result.setAuthorizeFlag(true);
//支付宝userId
if(StringUtils.isNotBlank( info.getAlipayUid())){
result.setAlipayId(info.getAlipayUid());
}
//支付宝账户信息
if(StringUtils.isNotBlank(info.getAlipayAccount())){
result.setAlipayAccount(info.getAlipayAccount());
//把账号部分信息隐藏
if(HideDataUtil.isEmail(info.getAlipayAccount())){
result.setAlipayMaskAccount(HideDataUtil.hideEmail(info.getAlipayAccount()));
}else if(UserInfoHiddenHelper.isPhone(info.getAlipayAccount())){
result.setAlipayMaskAccount(UserInfoHiddenHelper.hidePhoneNo(info.getAlipayAccount()));
}else if(info.getAlipayAccount().length()>2){
//即不是手机,又不是邮箱,只显示首末位
result.setAlipayMaskAccount(info.getAlipayAccount().substring(0,1) + "****"
+ info.getAlipayAccount().substring(info.getAlipayAccount().length()-1));
}else{
result.setAlipayMaskAccount(info.getAlipayAccount());
}
}
result.setCertName(info.getCertName());
result.setCreateTime(info.getCreateTime());
return result;
}
private LocalDateTime getLocalDateTime(){
LocalDateTime now=LocalDateTime.now();
... ...