提交 a01d1a4c 编写于 作者: Chongwen.jiang's avatar Chongwen.jiang

Merge branch 'dev-login0218' of...

Merge branch 'dev-login0218' of 192.168.110.53:com.pica.cloud.account/pica-cloud-account into dev-login0218
流水线 #22028 已失败 于阶段
in 2 second
......@@ -240,7 +240,9 @@ public class LoginController extends AccountBaseController {
@PostMapping("/login/one-click")
public PicaResponse<LoginResult> oneClickLogin(@RequestBody EncryptEntity entity) throws Exception {
OneClickLoginReq req = CryptoUtil.decrypt(entity, OneClickLoginReq.class);
req.setType(super.getSourceType());
req.setProductType(super.getProductType());
req.setSourceType(super.getSourceType());
req.setLoginIp(super.getIpAddr());
LoginResult oneClickLoginResultVo = loginService.oneClickLogin(req);
return PicaResponse.toResponse(oneClickLoginResultVo);
}
......
package com.pica.cloud.account.account.server.entity;
import java.util.Date;
public class LogLoginOnekey {
private Integer id;
private Integer logLoginId;
private Byte deviceType;
private String mobile;
private String tradeNo;
private Byte fanqizha;
private String tag;
private String info;
private Integer deleteFlag;
private Integer createId;
private Date createTime;
private Integer modifyId;
private Date modifyTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getLogLoginId() {
return logLoginId;
}
public void setLogLoginId(Integer logLoginId) {
this.logLoginId = logLoginId;
}
public Byte getDeviceType() {
return deviceType;
}
public void setDeviceType(Byte deviceType) {
this.deviceType = deviceType;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile == null ? null : mobile.trim();
}
public String getTradeNo() {
return tradeNo;
}
public void setTradeNo(String tradeNo) {
this.tradeNo = tradeNo == null ? null : tradeNo.trim();
}
public Byte getFanqizha() {
return fanqizha;
}
public void setFanqizha(Byte fanqizha) {
this.fanqizha = fanqizha;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag == null ? null : tag.trim();
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info == null ? null : info.trim();
}
public Integer getDeleteFlag() {
return deleteFlag;
}
public void setDeleteFlag(Integer deleteFlag) {
this.deleteFlag = deleteFlag;
}
public Integer getCreateId() {
return createId;
}
public void setCreateId(Integer createId) {
this.createId = createId;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Integer getModifyId() {
return modifyId;
}
public void setModifyId(Integer modifyId) {
this.modifyId = modifyId;
}
public Date getModifyTime() {
return modifyTime;
}
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
}
\ No newline at end of file
......@@ -28,6 +28,16 @@ public class LoginResult {
@ApiModelProperty("用户id,已经加密处理")
private String doctorId;
private Integer logLoginId;
public Integer getLogLoginId() {
return logLoginId;
}
public void setLogLoginId(Integer logLoginId) {
this.logLoginId = logLoginId;
}
public String getToken() {
return token;
}
......
......@@ -43,4 +43,14 @@ public class MobileDataEntity {
public void setTag(String tag) {
this.tag = tag;
}
@Override
public String toString() {
return "MobileDataEntity{" +
"mobileName='" + mobileName + '\'' +
", tradeNo='" + tradeNo + '\'' +
", fanqizha=" + fanqizha +
", tag='" + tag + '\'' +
'}';
}
}
......@@ -11,6 +11,15 @@ public class QueryMobileEntity {
private String message;
private Integer chargeStatus;
private MobileDataEntity data;
private String mobile;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getCode() {
return code;
......@@ -51,6 +60,7 @@ public class QueryMobileEntity {
", message='" + message + '\'' +
", chargeStatus=" + chargeStatus +
", data=" + data +
", mobile='" + mobile + '\'' +
'}';
}
}
package com.pica.cloud.account.account.server.mapper;
import com.pica.cloud.account.account.server.entity.LogLoginOnekey;
public interface LogLoginOnekeyMapper {
int deleteByPrimaryKey(Integer id);
int insert(LogLoginOnekey record);
int insertSelective(LogLoginOnekey record);
LogLoginOnekey selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(LogLoginOnekey record);
int updateByPrimaryKey(LogLoginOnekey record);
}
\ No newline at end of file
package com.pica.cloud.account.account.server.model;
import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.server.entity.LogLoginOnekey;
import com.pica.cloud.account.account.server.entity.MobileDataEntity;
import com.pica.cloud.account.account.server.entity.QueryMobileEntity;
import com.pica.cloud.account.account.server.mapper.LogLoginOnekeyMapper;
import com.pica.cloud.account.account.server.util.AESUtil;
import com.pica.cloud.account.account.server.util.HttpUtil;
import com.pica.cloud.account.account.server.util.MD5;
......@@ -12,8 +15,10 @@ 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.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
......@@ -45,9 +50,10 @@ public class OneClickProcessor {
@Value("${shanyan.ios.appKey}")
private String iosAppKey;
@Autowired
private LogLoginOnekeyMapper logLoginOnekeyMapper;
public String tokenExchangeMobile(String token, Integer type) {
public QueryMobileEntity tokenExchangeMobile(String token, Integer type) {
if (type == null) {
return null;
}
......@@ -62,16 +68,17 @@ public class OneClickProcessor {
} else {
return null;
}
String returnMobile = null;
//从SDK获取的token参数
QueryMobileEntity queryMobileEntity = null;
try {
Map<String, String> params = new HashMap<String, String>();
Map<String, String> params = new HashMap<>();
params.put("token", token);
params.put("appId", appId);
params.put("encryptType", encryptType);//可以不传,不传则解密直接使用AES解密
params.put("sign", SignUtils.getSign(params, appKey));
QueryMobileEntity queryMobileEntity = (QueryMobileEntity) HttpUtil.postForm(mobileQueryUrl, params, QueryMobileEntity.class);
queryMobileEntity = HttpUtil.postForm(mobileQueryUrl, params, QueryMobileEntity.class);
if (null != queryMobileEntity) {
logger.info("一键登录token换取手机号结果:{}", queryMobileEntity);
String code = queryMobileEntity.getCode(); //返回码 200000为成功
if ("200000".equals(code)) {
MobileDataEntity mobileDataEntity = queryMobileEntity.getData();
......@@ -82,16 +89,30 @@ public class OneClickProcessor {
} else if (rsaEncryptType.equals(encryptType)) {
mobile = RSAUtil.decryptByPrivateKeyForLongStr(mobile, privateKey);
}
mobileDataEntity.setMobileName(mobile);
returnMobile = mobileDataEntity.getMobileName();
} else {
throw new RuntimeException();
queryMobileEntity.setMobile(mobile);
}
}
} catch (Exception e) {
logger.error(e.getMessage());
throw new PicaException("token换取手机号调用失败!");
}
return returnMobile;
return queryMobileEntity;
}
@Async
public void savelogLoginOnekey(QueryMobileEntity queryMobileEntity, Integer type, Integer logLoginId) {
LogLoginOnekey l = new LogLoginOnekey();
l.setDeviceType(type.byteValue());
MobileDataEntity data = queryMobileEntity.getData();
l.setFanqizha(data.getFanqizha().byteValue());
l.setTradeNo(data.getTradeNo());
l.setMobile(AESUtil.encryptV0(data.getMobileName()));
l.setLogLoginId(logLoginId);
l.setInfo(JSONObject.toJSONString(queryMobileEntity));
Date d = new Date();
l.setCreateId(-1);
l.setCreateTime(d);
l.setModifyId(-1);
l.setModifyTime(d);
logLoginOnekeyMapper.insertSelective(l);
}
}
......@@ -7,16 +7,28 @@ package com.pica.cloud.account.account.server.req;
* @create: 2020-02-12 15:58
*/
public class OneClickLoginReq {
private Integer type;
private Integer sourceType;
private String token = "";
public Integer getType() {
return type;
private String loginIp;
private int productType;
public String getLoginIp() {
return loginIp;
}
public void setType(Integer type) {
this.type = type;
public void setLoginIp(String loginIp) {
this.loginIp = loginIp;
}
public int getProductType() {
return productType;
}
public void setProductType(int productType) {
this.productType = productType;
}
public String getToken() {
......@@ -27,4 +39,11 @@ public class OneClickLoginReq {
this.token = token;
}
public Integer getSourceType() {
return sourceType;
}
public void setSourceType(Integer sourceType) {
this.sourceType = sourceType;
}
}
......@@ -28,6 +28,7 @@ import com.pica.cloud.account.account.server.vo.OneClickLoginResultVo;
import com.pica.cloud.foundation.encryption.common.constants.EncryptConstants;
import com.pica.cloud.foundation.encryption.util.EncryptUtils;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.utils.HttpClientUtil;
import com.pica.cloud.foundation.utils.utils.ValidateUtils;
......@@ -251,6 +252,7 @@ public class LoginServiceImpl implements LoginService {
}
/**
* 登录逻辑处理
* 登录逻辑处理
*
* @param baseRequest
......@@ -279,6 +281,7 @@ public class LoginServiceImpl implements LoginService {
LogLoginEntity entity = AccountLogEntityUtils.getLogLoginEntity(acctId, baseRequest.getProductType(), baseRequest.getSourceType(),
loginType, baseRequest.getLoginIp(), AccountTypeEnum.LOGIN_STATUS_SUCCESS.getCode(), AccountTypeEnum.LOG_TYPE_LOGIN.getCode());
picaLogUtils.info(entity);
result.setLogLoginId(entity.getId());
return result;
}
......@@ -486,22 +489,30 @@ public class LoginServiceImpl implements LoginService {
@Override
public LoginResult oneClickLogin(OneClickLoginReq req) {
OneClickLoginResultVo o = new OneClickLoginResultVo();
String mobile = oneClickProcessor.tokenExchangeMobile(req.getToken(),req.getType());
if(StringUtils.isBlank(mobile)){
QueryMobileEntity queryMobileEntity = oneClickProcessor.tokenExchangeMobile(req.getToken(),req.getSourceType());
if (queryMobileEntity == null || StringUtils.isBlank(queryMobileEntity.getMobile()) || !ValidateUtils.isMobile(queryMobileEntity.getMobile())) {
throw new PicaException(PicaResultCode.INTERFACE_INVOKE_EXCEPTION.code(), "获取手机号失败!");
}
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(mobile));
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(queryMobileEntity.getMobile()));
BaseRequest baseRequest = new BaseRequest();
baseRequest.setMobile(queryMobileEntity.getMobile());
baseRequest.setSourceType(req.getSourceType());
baseRequest.setProductType(req.getProductType());
baseRequest.setLoginIp(req.getLoginIp());
LoginResult result;
if (accountInfoEntity == null) {
//说明是注册功能
return registerService.register(baseRequest);
result = registerService.register(baseRequest);
} else {
//登录功能
return processLogin(baseRequest, accountInfoEntity.getId(), AccountTypeEnum.LOGIN_CODE.getCode());
result = processLogin(baseRequest, accountInfoEntity.getId(), AccountTypeEnum.LOGIN_CODE.getCode());
}
oneClickProcessor.savelogLoginOnekey(queryMobileEntity,req.getSourceType(),result.getLogLoginId());
return result;
}
private String processDoctorAvatar(String avatar_image_url) {
if (StringUtils.isEmpty(avatar_image_url)) {
return DEFAULT_DOCTOR_PICTURE_URL;
......
......@@ -153,6 +153,7 @@ public class RegisterServiceImpl implements RegisterService {
AccountTypeEnum.LOGIN_REGISTER.getCode(), baseRequest.getLoginIp(), AccountTypeEnum.LOGIN_STATUS_SUCCESS.getCode(),
AccountTypeEnum.LOG_TYPE_LOGIN.getCode());
picaLogUtils.info(entity);
result.setLogLoginId(entity.getId());
processAgreement(userId);
processRoleMap(userId);
redisClient.del(REPEAT_REGISTER_PREFIX + mobile);
......
......@@ -36,7 +36,7 @@ public class HttpUtil {
hc = HttpClients.custom().setConnectionManager(cm).build();
}
public static Object postForm(String url, Map<String, String> params, Class clazz) throws IOException, URISyntaxException {
public static <T> T postForm(String url, Map<String, String> params, Class<T> clazz) throws IOException, URISyntaxException {
URIBuilder builder = new URIBuilder(url);
if (params != null && params.size() > 0) {
params.forEach((k, v) -> {
......@@ -45,7 +45,7 @@ public class HttpUtil {
}
HttpPost post = new HttpPost(builder.build());
CloseableHttpResponse resp = null;
Object data;
T data;
try {
resp = hc.execute(post);
String buf = IOUtils.toString(resp.getEntity().getContent(), "utf-8");
......
......@@ -33,6 +33,9 @@
</delete>
<insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.LogLoginEntity" >
<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
SELECT LAST_INSERT_ID()
</selectKey>
insert into log_login ( acct_id, acct_name,
product_type, source_type, login_type,
login_ip, login_time, login_status,
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.pica.cloud.account.account.server.mapper.LogLoginOnekeyMapper" >
<resultMap id="BaseResultMap" type="com.pica.cloud.account.account.server.entity.LogLoginOnekey" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="log_login_id" property="logLoginId" jdbcType="INTEGER" />
<result column="device_type" property="deviceType" jdbcType="TINYINT" />
<result column="mobile" property="mobile" jdbcType="VARCHAR" />
<result column="trade_no" property="tradeNo" jdbcType="VARCHAR" />
<result column="fanqizha" property="fanqizha" jdbcType="TINYINT" />
<result column="tag" property="tag" jdbcType="VARCHAR" />
<result column="info" property="info" jdbcType="VARCHAR" />
<result column="delete_flag" property="deleteFlag" jdbcType="INTEGER" />
<result column="create_id" property="createId" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="modify_id" property="modifyId" jdbcType="INTEGER" />
<result column="modify_time" property="modifyTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
id, log_login_id, device_type, mobile, trade_no, fanqizha, tag, info, delete_flag,
create_id, create_time, modify_id, modify_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from log_login_onekey
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from log_login_onekey
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.LogLoginOnekey" >
insert into log_login_onekey (id, log_login_id, device_type,
mobile, trade_no, fanqizha,
tag, info, delete_flag,
create_id, create_time, modify_id,
modify_time)
values (#{id,jdbcType=INTEGER}, #{logLoginId,jdbcType=INTEGER}, #{deviceType,jdbcType=TINYINT},
#{mobile,jdbcType=VARCHAR}, #{tradeNo,jdbcType=VARCHAR}, #{fanqizha,jdbcType=TINYINT},
#{tag,jdbcType=VARCHAR}, #{info,jdbcType=VARCHAR}, #{deleteFlag,jdbcType=INTEGER},
#{createId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{modifyId,jdbcType=INTEGER},
#{modifyTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.LogLoginOnekey" >
insert into log_login_onekey
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="logLoginId != null" >
log_login_id,
</if>
<if test="deviceType != null" >
device_type,
</if>
<if test="mobile != null" >
mobile,
</if>
<if test="tradeNo != null" >
trade_no,
</if>
<if test="fanqizha != null" >
fanqizha,
</if>
<if test="tag != null" >
tag,
</if>
<if test="info != null" >
info,
</if>
<if test="deleteFlag != null" >
delete_flag,
</if>
<if test="createId != null" >
create_id,
</if>
<if test="createTime != null" >
create_time,
</if>
<if test="modifyId != null" >
modify_id,
</if>
<if test="modifyTime != null" >
modify_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="logLoginId != null" >
#{logLoginId,jdbcType=INTEGER},
</if>
<if test="deviceType != null" >
#{deviceType,jdbcType=TINYINT},
</if>
<if test="mobile != null" >
#{mobile,jdbcType=VARCHAR},
</if>
<if test="tradeNo != null" >
#{tradeNo,jdbcType=VARCHAR},
</if>
<if test="fanqizha != null" >
#{fanqizha,jdbcType=TINYINT},
</if>
<if test="tag != null" >
#{tag,jdbcType=VARCHAR},
</if>
<if test="info != null" >
#{info,jdbcType=VARCHAR},
</if>
<if test="deleteFlag != null" >
#{deleteFlag,jdbcType=INTEGER},
</if>
<if test="createId != null" >
#{createId,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="modifyId != null" >
#{modifyId,jdbcType=INTEGER},
</if>
<if test="modifyTime != null" >
#{modifyTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.account.account.server.entity.LogLoginOnekey" >
update log_login_onekey
<set >
<if test="logLoginId != null" >
log_login_id = #{logLoginId,jdbcType=INTEGER},
</if>
<if test="deviceType != null" >
device_type = #{deviceType,jdbcType=TINYINT},
</if>
<if test="mobile != null" >
mobile = #{mobile,jdbcType=VARCHAR},
</if>
<if test="tradeNo != null" >
trade_no = #{tradeNo,jdbcType=VARCHAR},
</if>
<if test="fanqizha != null" >
fanqizha = #{fanqizha,jdbcType=TINYINT},
</if>
<if test="tag != null" >
tag = #{tag,jdbcType=VARCHAR},
</if>
<if test="info != null" >
info = #{info,jdbcType=VARCHAR},
</if>
<if test="deleteFlag != null" >
delete_flag = #{deleteFlag,jdbcType=INTEGER},
</if>
<if test="createId != null" >
create_id = #{createId,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="modifyId != null" >
modify_id = #{modifyId,jdbcType=INTEGER},
</if>
<if test="modifyTime != null" >
modify_time = #{modifyTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.pica.cloud.account.account.server.entity.LogLoginOnekey" >
update log_login_onekey
set log_login_id = #{logLoginId,jdbcType=INTEGER},
device_type = #{deviceType,jdbcType=TINYINT},
mobile = #{mobile,jdbcType=VARCHAR},
trade_no = #{tradeNo,jdbcType=VARCHAR},
fanqizha = #{fanqizha,jdbcType=TINYINT},
tag = #{tag,jdbcType=VARCHAR},
info = #{info,jdbcType=VARCHAR},
delete_flag = #{deleteFlag,jdbcType=INTEGER},
create_id = #{createId,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP},
modify_id = #{modifyId,jdbcType=INTEGER},
modify_time = #{modifyTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册