|
|
package com.yohoufo.user.service.impl;
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alipay.api.response.ZhimaCustomerCertificationQueryResponse;
|
|
|
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.utils.HttpClient;
|
|
|
import com.yohoufo.common.utils.RSAUtils;
|
|
|
import com.yohoufo.common.utils.UserInfoHiddenHelper;
|
|
|
import com.yohoufo.dal.user.IUserAuthorizeInfoDao;
|
|
|
import com.yohoufo.dal.user.IZhiMaCertDao;
|
|
|
import com.yohoufo.dal.user.model.UserAuthorizeInfo;
|
|
|
import com.yohoufo.dal.user.model.ZhiMaCert;
|
|
|
import com.yohoufo.user.cache.CacheService;
|
|
|
import com.yohoufo.user.common.AlipayConfigInfo;
|
|
|
import com.yohoufo.user.helper.HideDataUtil;
|
|
|
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
|
|
|
import com.yohoufo.user.responseVO.AlipayUserInfoRespVO;
|
|
|
import com.yohoufo.user.service.IRealNameAuthorizeService;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.TreeMap;
|
|
|
|
|
|
/**
|
|
|
* 用户身份实名认证
|
...
|
...
|
@@ -39,6 +52,8 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
@Autowired
|
|
|
private IZhiMaCertDao zhiMaCertDao;
|
|
|
|
|
|
@Autowired
|
|
|
private HttpClient httpClient;
|
|
|
/* @Autowired
|
|
|
private GraphVerifyService graphVerifyService;*/
|
|
|
|
...
|
...
|
@@ -145,14 +160,17 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
}
|
|
|
|
|
|
result.setAuthorizeFlag(true);
|
|
|
result.setCreateTime(info.getCreateTime());
|
|
|
//支付宝userId
|
|
|
if(StringUtils.isNotBlank( info.getAlipayUid())){
|
|
|
if(StringUtils.isNotBlank( info.getAlipayUid())){//通过授权绑定的账户
|
|
|
result.setAlipayId(info.getAlipayUid());
|
|
|
result.setAlipayMaskAccount(info.getNickName());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//支付宝账户信息
|
|
|
if(StringUtils.isNotBlank(info.getAlipayAccount())){
|
|
|
result.setAlipayAccount(info.getAlipayAccount());
|
|
|
if(StringUtils.isNotBlank(info.getAlipayAccount())){//用户手动输入的
|
|
|
// result.setAlipayAccount(info.getAlipayAccount());
|
|
|
//把账号部分信息隐藏
|
|
|
if(HideDataUtil.isEmail(info.getAlipayAccount())){
|
|
|
result.setAlipayMaskAccount(HideDataUtil.hideEmail(info.getAlipayAccount()));
|
...
|
...
|
@@ -168,10 +186,137 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { |
|
|
}
|
|
|
|
|
|
result.setCertName(info.getCertName());
|
|
|
result.setCreateTime(info.getCreateTime());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 支付宝授权自动绑定
|
|
|
* 1)安卓客户端 --先获取 access_token, iphone跳过此步
|
|
|
* 2)获取用户信息
|
|
|
* 3)绑定入库
|
|
|
* @param reqVO
|
|
|
* @throws GatewayException
|
|
|
*/
|
|
|
@Override
|
|
|
public void autoBindAliPayAccount(RealNameAuthorizeReqVO reqVO) throws GatewayException {
|
|
|
logger.info("enter autoBindAliPayAccount, reqVO = {}", reqVO);
|
|
|
int uid = reqVO.getUid();
|
|
|
String access_token = reqVO.getAccess_token();
|
|
|
String auth_code = reqVO.getAuth_code();
|
|
|
|
|
|
AlipayUserInfoRespVO respVO;
|
|
|
String respStr;
|
|
|
|
|
|
//1)获取access_token
|
|
|
if(StringUtils.isEmpty( access_token)){
|
|
|
if(StringUtils.isEmpty(auth_code)){
|
|
|
throw new GatewayException(201,"请求参数错误,绑定失败!");
|
|
|
}
|
|
|
Map<String,String> tempParam = new TreeMap<>();
|
|
|
tempParam.put("grant_type", "authorization_code");
|
|
|
tempParam.put("code",auth_code );
|
|
|
|
|
|
respStr = queryInfo(AlipayConfigInfo.OAUTH_TOKEN_METHOD, AlipayConfigInfo.OAUTH_TOKEN_URL, tempParam);
|
|
|
if(StringUtils.isBlank(respStr)){
|
|
|
throw new GatewayException(201,"绑定失败!");
|
|
|
}
|
|
|
logger.info("autoBindAliPayAccount getAlipayOauthToken uid={}, app_auth_token={}, respStr={}, ", uid, auth_code, respStr);
|
|
|
respVO = JSON.parseObject(JSONObject.toJSONString(JSON.parseObject(respStr).getJSONObject("alipay_system_oauth_token_response")), AlipayUserInfoRespVO.class);
|
|
|
if( StringUtils.isBlank(respVO.getAccess_token()) ){//调用失败
|
|
|
throw new GatewayException(201,"绑定失败!");
|
|
|
}
|
|
|
access_token = respVO.getAccess_token();
|
|
|
|
|
|
}
|
|
|
|
|
|
//2)alipay.user.info.share(支付宝会员授权信息查询接口)
|
|
|
Map<String,String> param = new HashMap<>();
|
|
|
param.put("auth_token",access_token);
|
|
|
respStr = queryInfo(AlipayConfigInfo.USERINFO_SHARE_METHOD, AlipayConfigInfo.USERINFO_SHARE_URL,param);
|
|
|
logger.info("autoBindAliPayAccount getAlipayUserInfo uid={}, app_auth_token={},access_token={}, respStr={}, ", uid,access_token, auth_code, respStr);
|
|
|
if(StringUtils.isBlank(respStr)){
|
|
|
throw new GatewayException(201,"绑定失败!");
|
|
|
}
|
|
|
|
|
|
respVO = JSON.parseObject(JSONObject.toJSONString(JSON.parseObject(respStr).getJSONObject("alipay_user_info_share_response")), AlipayUserInfoRespVO.class);
|
|
|
//调用失败
|
|
|
if( !StringUtils.equals("10000", respVO.getCode()) ){
|
|
|
throw new GatewayException(201,"绑定失败!");
|
|
|
}
|
|
|
//3)调用成功--入库操作
|
|
|
String alipayUid = respVO.getUser_id();
|
|
|
String nickName = respVO.getNick_name();
|
|
|
logger.info("autoBindAliPayAccount save bandInfo reqVO={}, alipayUid={},nickName={}",reqVO, alipayUid,nickName);
|
|
|
UserAuthorizeInfo userAuthorizeInfo = new UserAuthorizeInfo();
|
|
|
userAuthorizeInfo.setUid(uid);
|
|
|
userAuthorizeInfo.setValidStatus(1);
|
|
|
userAuthorizeInfo.setAlipayUid(alipayUid);
|
|
|
userAuthorizeInfo.setNickName(nickName);
|
|
|
long create_time = System.currentTimeMillis() /1000;
|
|
|
userAuthorizeInfo.setCreateTime(create_time);
|
|
|
userAuthorizeInfoDao.insertSelective(userAuthorizeInfo);
|
|
|
logger.info("autoBindAliPayAccount success!reqVO= {}", reqVO);
|
|
|
|
|
|
}
|
|
|
|
|
|
private String queryInfo(String methodName, String methodUrl, Map<String,String> params) {
|
|
|
Map<String,String> map = getAlipayCommonParam();//公共请求参数
|
|
|
map.put("method",methodName);
|
|
|
if(params != null && params.size() > 0 ){//其他参数
|
|
|
map.putAll(params);
|
|
|
}
|
|
|
String sign = buildSignStr(map);//签名
|
|
|
map.put("sign",sign);
|
|
|
|
|
|
logger.info("autoBindAliPayAccount queryInfo start, methodName ={},methodUrl is ={}, paramMap ={} ",methodName, methodUrl, params);
|
|
|
|
|
|
try {
|
|
|
String response = httpClient.postFormData(methodUrl, map);
|
|
|
return response;
|
|
|
} catch (Exception e) {
|
|
|
logger.warn("queryAlipayInfo error! methodName={},methodUrl ={},paramMap ={},e :{}, ",methodName, methodUrl, params, e);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
private Map<String,String> getAlipayCommonParam() {
|
|
|
String app_id = AlipayConfigInfo.appid;
|
|
|
String format = "json";
|
|
|
String charset = "utf-8";
|
|
|
String sign_type = AlipayConfigInfo.sign_type;
|
|
|
|
|
|
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
String timestamp = sf.format(new Date());
|
|
|
String version = "1.0";
|
|
|
|
|
|
Map<String,String> map = new TreeMap<>();
|
|
|
map.put("app_id",app_id);
|
|
|
map.put("sign_type",sign_type);
|
|
|
map.put("format",format);
|
|
|
map.put("charset",charset);
|
|
|
map.put("version",version);
|
|
|
map.put("timestamp",timestamp);
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
|
|
|
private String buildSignStr(Map<String, String> paramsMap) {
|
|
|
StringBuilder payStrBuilder = new StringBuilder();
|
|
|
int count = 0;
|
|
|
for(Map.Entry<String, String> entry : paramsMap.entrySet()) {
|
|
|
if(count > 0)
|
|
|
payStrBuilder.append("&");
|
|
|
|
|
|
payStrBuilder.append(entry.getKey()).append("=").append(entry.getValue());
|
|
|
count++;
|
|
|
}
|
|
|
|
|
|
String sign = RSAUtils.sign(payStrBuilder.toString(), AlipayConfigInfo.private_key, AlipayConfigInfo.input_charset);
|
|
|
|
|
|
return sign ;
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public ZhiMaCert getValidZhiMaCert(int uid) {
|
...
|
...
|
|