...
|
...
|
@@ -13,6 +13,7 @@ import com.yoho.error.exception.ServiceException; |
|
|
import com.yoho.tools.common.beans.ApiResponse;
|
|
|
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
|
|
|
import com.yohoufo.common.exception.GatewayException;
|
|
|
import com.yohoufo.common.exception.UfoServiceException;
|
|
|
import com.yohoufo.common.utils.HttpClient;
|
|
|
import com.yohoufo.common.utils.UserInfoHiddenHelper;
|
|
|
import com.yohoufo.dal.user.IUserAuthorizeInfoDao;
|
...
|
...
|
@@ -28,9 +29,13 @@ import org.apache.commons.lang.StringUtils; |
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -51,6 +56,9 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
|
|
|
@Autowired
|
|
|
private HttpClient httpClient;
|
|
|
|
|
|
@Value("${zhimacert.switch:true}")
|
|
|
private boolean zhiMaCertSwitch;
|
|
|
/* @Autowired
|
|
|
private GraphVerifyService graphVerifyService;*/
|
|
|
|
...
|
...
|
@@ -188,7 +196,7 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
|
|
|
/**
|
|
|
* 支付宝授权自动绑定
|
|
|
* 1)安卓客户端 --先获取 access_token, iphone跳过此步
|
|
|
* 1)安卓客户端 --先获取 access_token
|
|
|
* 2)获取用户信息
|
|
|
* 3)绑定入库
|
|
|
* @param reqVO
|
...
|
...
|
@@ -197,15 +205,15 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
@Override
|
|
|
public void autoBindAliPayAccount(RealNameAuthorizeReqVO reqVO) throws GatewayException {
|
|
|
int uid = reqVO.getUid();
|
|
|
String access_token = reqVO.getAccess_token();
|
|
|
String auth_code = reqVO.getAuth_code();
|
|
|
logger.info("enter autoBindAliPayAccount, uid={}, auth_code={}, access_token={} ", reqVO, auth_code, access_token);
|
|
|
logger.info("enter autoBindAliPayAccount, uid={}, auth_code={} ", uid, auth_code);
|
|
|
|
|
|
String access_token;
|
|
|
//1)获取access_token
|
|
|
if(StringUtils.isEmpty( access_token)) {
|
|
|
if (StringUtils.isEmpty(auth_code)) {
|
|
|
throw new GatewayException(201, "请求参数错误,绑定失败!");
|
|
|
}
|
|
|
if(StringUtils.isEmpty(auth_code)) {
|
|
|
logger.warn("autoBindAliPayAccount error! auth_code is empty, uid={}",uid);
|
|
|
throw new GatewayException(402, "支付宝绑定失败,请重试");
|
|
|
}else{
|
|
|
//获取access_token alipay.system.oauth.token
|
|
|
AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfigInfo.OPENAPI_URL, AlipayConfigInfo.appid, AlipayConfigInfo.private_key, "json", "utf-8", AlipayConfigInfo.ali_public_key, "RSA");
|
|
|
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
|
...
|
...
|
@@ -216,16 +224,18 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
try {
|
|
|
response = alipayClient.execute(request);
|
|
|
} catch (AlipayApiException e) {
|
|
|
logger.warn("autoBindAliPayAccount AlipaySystemOauthTokenRequest error! uid={},auth_code={},response={}, e: {}", uid, auth_code, response, e);
|
|
|
throw new GatewayException(201, "绑定失败!");
|
|
|
logger.warn("autoBindAliPayAccount AlipaySystemOauthTokenRequest error! uid={},auth_code={},response.getCode={},response.getSubCode={} e: {}", uid, auth_code,
|
|
|
response == null ? "":response.getCode(), response == null ? "":response.getSubCode(), e);
|
|
|
throw new GatewayException(400, "支付宝绑定失败,请重试");
|
|
|
}
|
|
|
|
|
|
logger.info("autoBindAliPayAccount AlipaySystemOauthTokenRequest uid={},auth_code={},response={}", uid, auth_code, access_token, response);
|
|
|
logger.info("autoBindAliPayAccount AlipaySystemOauthTokenRequest uid={},auth_code={},response.getCode={},response.getSubCode={}", uid, auth_code,
|
|
|
response == null ? "":response.getCode(),response == null ? "":response.getSubCode());
|
|
|
//调用成功
|
|
|
if (response.isSuccess()) {
|
|
|
access_token = response.getAccessToken();
|
|
|
} else {
|
|
|
throw new GatewayException(201, "绑定失败!");
|
|
|
throw new GatewayException(400, "支付宝绑定失败,请重试");
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -236,22 +246,24 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
try {
|
|
|
response = alipayClient.execute(request, access_token);
|
|
|
} catch (AlipayApiException e) {
|
|
|
logger.warn("autoBindAliPayAccount AlipayUserInfoShareRequest error! uid={},auth_code={},access_token={},response={}, e: {}", uid, auth_code, access_token,response, e);
|
|
|
throw new GatewayException(201, "绑定失败!");
|
|
|
logger.warn("autoBindAliPayAccount AlipayUserInfoShareRequest error! uid={},auth_code={},access_token={},response.getCode={},response.getSubCode={}, e: {}", uid, auth_code, access_token,
|
|
|
response == null ? "": response.getCode(), response == null ? "":response.getSubCode(), e);
|
|
|
throw new GatewayException(400, "支付宝绑定失败,请重试");
|
|
|
}
|
|
|
|
|
|
logger.info("autoBindAliPayAccount AlipayUserInfoShareRequest , uid={},auth_code={},access_token={}, response={}", uid, auth_code, access_token,response);
|
|
|
logger.info("autoBindAliPayAccount AlipayUserInfoShareRequest , uid={},auth_code={},access_token={}, response.getCode={},response.getSubCode={}", uid, auth_code, access_token,
|
|
|
response == null ? "": response.getCode(), response == null ? "":response.getSubCode());
|
|
|
|
|
|
if (!response.isSuccess()) {
|
|
|
throw new GatewayException(201, "绑定失败!");
|
|
|
throw new GatewayException(400, "支付宝绑定失败,请重试");
|
|
|
}
|
|
|
|
|
|
//3)调用成功--入库操作
|
|
|
String alipayUid = response.getUserId();
|
|
|
String nickName = response.getNickName();
|
|
|
if(StringUtils.isBlank(alipayUid)){
|
|
|
logger.warn("autoBindAliPayAccount error, alipayUid is blank! uid={},auth_code={},access_token={}, response={} ",uid, auth_code,access_token, response);
|
|
|
throw new GatewayException(201, "绑定失败!");
|
|
|
logger.warn("autoBindAliPayAccount error, alipayUid is blank! uid={},auth_code={},access_token={}",uid, auth_code,access_token);
|
|
|
throw new GatewayException(400, "支付宝绑定失败,请重试");
|
|
|
}
|
|
|
|
|
|
UserAuthorizeInfo userAuthorizeInfo = new UserAuthorizeInfo();
|
...
|
...
|
@@ -263,7 +275,19 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
userAuthorizeInfo.setCreateTime(create_time);
|
|
|
userAuthorizeInfoDao.insertSelective(userAuthorizeInfo);
|
|
|
logger.info("autoBindAliPayAccount success!uid={}, alipayUid={}, nickName={} ", uid, alipayUid, nickName);
|
|
|
}
|
|
|
|
|
|
public boolean isValidZhiMaCert(int uid){
|
|
|
//如果芝麻认知没有开启,默认芝麻认证通过
|
|
|
if(!zhiMaCertSwitch){
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
//否则,从db查询认证信息
|
|
|
if(null!=this.getValidZhiMaCert(uid)){
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@Override
|
...
|
...
|
@@ -286,21 +310,37 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
return zhiMaCert;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
38 * 获取现在时间
|
|
|
39 *
|
|
|
40 * @return返回字符串格式 yyyy-MM-dd HH:mm:ss
|
|
|
41 */
|
|
|
public static String getStringDate() {
|
|
|
Date currentTime = new Date();
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
String dateString = formatter.format(currentTime);
|
|
|
return dateString;
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
System.out.println(getStringDate());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public AuthorizeResultRespVO zhiMaCertInit(RealNameAuthorizeReqVO reqVO) {
|
|
|
logger.info("real name zhiMaCertInit reqVO {}", reqVO);
|
|
|
//检查是否已经认证,如果已经认证,报错
|
|
|
if (null != this.getValidZhiMaCert(reqVO.getUid())) {
|
|
|
throw new ServiceException(400, "已实名认证!");
|
|
|
if (isValidZhiMaCert(reqVO.getUid())) {
|
|
|
throw new UfoServiceException(400, "已实名认证!");
|
|
|
}
|
|
|
//检查身份证号认证信息是否已经存在,存在则不允许再次使用
|
|
|
if (null != zhiMaCertDao.selectValidByCertNo(reqVO.getCertNo())) {
|
|
|
throw new ServiceException(400, "身份证号已被占用!");
|
|
|
throw new UfoServiceException(400, "身份证号已被占用!");
|
|
|
}
|
|
|
|
|
|
//调用芝麻接口,返回biz_no
|
|
|
//构建唯一的 transaction_id : ufoCert+id
|
|
|
LocalDateTime now = getLocalDateTime();
|
|
|
Long nowSecond = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
|
|
|
|
|
|
//存储认证信息
|
...
|
...
|
@@ -319,7 +359,8 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
throw new ServiceException(400, "错误:保存实名认知信息异常!");
|
|
|
}
|
|
|
|
|
|
String transactionId="ufoCert"+zhiMaCert.getId();
|
|
|
//7+14+
|
|
|
String transactionId="ufoCert"+getStringDate()+zhiMaCert.getId();
|
|
|
|
|
|
String bizNo=ZhiMaCallUtil.zhiMaCertInit(transactionId,reqVO.getCertName(),reqVO.getCertNo());
|
|
|
|
...
|
...
|
@@ -330,6 +371,7 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
|
|
|
|
|
|
//不需要更新bizNO到数据库了,不需要记录
|
|
|
zhiMaCertDao.updateBizNoByByPrimaryKey(zhiMaCert.getId(),bizNo);
|
|
|
|
|
|
//通过biz_no,生成returnUrl
|
|
|
String returnUrl = ZhiMaCallUtil.zhiMaCertUrl(bizNo);
|
...
|
...
|
@@ -351,18 +393,20 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
public ApiResponse zhiMaCertResultQuery(RealNameAuthorizeReqVO reqVO) {
|
|
|
logger.info("real name zhiMaCertResultQuery reqVO {}", reqVO);
|
|
|
//根据uid,获取biz_no
|
|
|
ZhiMaCert zhiMaCert=zhiMaCertDao.selectByPrimaryKey(reqVO.getZhiMaCertId());
|
|
|
ZhiMaCert zhiMaCert=zhiMaCertDao.selectByBizNo(reqVO.getZhiMaBizNo());
|
|
|
if(zhiMaCert==null){
|
|
|
logger.error("zhiMaCertResultQuery get cert by biz no is null ",reqVO.getZhiMaBizNo());
|
|
|
throw new ServiceException(400, "错误:未找到芝麻认证信息!");
|
|
|
logger.error("zhiMaCertResultQuery get cert is null ",reqVO.getZhiMaBizNo());
|
|
|
throw new UfoServiceException(400, "错误:未找到芝麻认证信息!");
|
|
|
}
|
|
|
|
|
|
logger.info("zhiMaCertResultQuery get zhiMaCert by biz no from db is {} ",zhiMaCert);
|
|
|
logger.info("zhiMaCertResultQuery get zhiMaCert from db is {} ",zhiMaCert);
|
|
|
|
|
|
Integer zhiMaCertId=zhiMaCert.getId();
|
|
|
|
|
|
if(!zhiMaCert.getUid().equals(reqVO.getUid())){
|
|
|
/*if(!zhiMaCert.getUid().equals(reqVO.getUid())){
|
|
|
logger.error("zhiMaCertResultQuery get cert by biz no is not same req uid {} ,db uid {}",reqVO.getUid(),zhiMaCert.getUid());
|
|
|
throw new ServiceException(400, "错误:未找到用户芝麻认证信息!");
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
ZhimaCustomerCertificationQueryResponse zhiMaResp=ZhiMaCallUtil.zhiMaResult(reqVO.getZhiMaBizNo());
|
|
|
if(zhiMaResp==null){
|
...
|
...
|
@@ -372,7 +416,7 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
|
|
|
if(zhiMaResp.isSuccess()&&"true".equals(zhiMaResp.getPassed())){
|
|
|
//芝麻认证通过
|
|
|
int updateCount = zhiMaCertDao.updateValidStatusByPrimaryKey(reqVO.getZhiMaCertId());
|
|
|
int updateCount = zhiMaCertDao.updateValidStatusByPrimaryKey(zhiMaCertId);
|
|
|
if(updateCount <1){
|
|
|
logger.error("zhiMaCertResultQuery update zhi ma cert valid status error,req vo {}",reqVO);
|
|
|
throw new ServiceException(400, "错误:更新用户芝麻认证信息错误!");
|
...
|
...
|
|