提交 063dbeae 编写于 作者: dong.an's avatar dong.an

Merge branch 'dev-20200116-wechat' into 'release'

Dev 20200116 wechat

合并分支到release

See merge request !12
流水线 #20975 已失败 于阶段
in 0 second
......@@ -179,11 +179,8 @@ public class AutoCodeController extends AccountBaseController {
@ApiOperation("微信获取验证码")
@PostMapping(value = "/authCode/get")
public PicaResponse getAuthCode(){
String cacheCode = cacheClient.get("authCode-2-j1VrU5MSc1uuZaEa82ZKfQ==");
String cacheCode = cacheClient.get("authCode-j1VrU5MSc1uuZaEa82ZKfQ==");
return PicaResponse.toResponse(cacheCode);
}
}
......@@ -13,6 +13,7 @@ import com.pica.cloud.account.account.server.service.TokenService;
import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.account.account.server.util.CryptoUtil;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.redis.CacheClient;
import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.utils.CommonUtil;
import io.swagger.annotations.Api;
......@@ -47,6 +48,11 @@ public class LoginController extends AccountBaseController {
@Autowired
private DoctorService doctorService;
@Autowired
private CacheClient cacheClient;
private String cache_prifix = "cache-";
/**
* 密码登录接口
*
......@@ -131,11 +137,22 @@ public class LoginController extends AccountBaseController {
@PostMapping("/login/wechat/bind")
public PicaResponse bindWeChat(@RequestBody EncryptEntity entity) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
long doctorId = super.getDoctorIdByToken();
String nickname = loginService.bindWeChat(doctorId, request);
Map<String, String> map = new HashMap();
map.put("nickname", nickname);
return PicaResponse.toResponse(map);
Long result = cacheClient.setnx(cache_prifix + request.getWeChatCode(), request.getWeChatCode());
if (result == 1) {
cacheClient.set(cache_prifix + request.getWeChatCode(), 60);
long doctorId = super.getDoctorIdByToken();
String nickname = loginService.bindWeChat(doctorId, request);
Map<String, String> map = new HashMap();
map.put("nickname", nickname);
//成功以后释放锁
cacheClient.del(cache_prifix + request.getWeChatCode());
return PicaResponse.toResponse(map);
} else {
cacheClient.del(cache_prifix + request.getWeChatCode());
return PicaResponse.toResponse(null, AccountExceptionEnum.PICA_WECHAT_UNBIND_CURRENT.getCode(),
AccountExceptionEnum.PICA_WECHAT_UNBIND_CURRENT.getMessage());
}
}
@ApiOperation("微信解除绑定接口")
......
......@@ -45,14 +45,17 @@ public class ModifyMobileController extends AccountBaseController {
public PicaResponse modifyMobile(@RequestBody EncryptEntity entity) throws Exception {
Long doctorId = super.getDoctorIdByToken();
Doctor doctorInfo = doctorService.getDoctorInfo(doctorId.intValue());
//旧的手机号
String mobilePhone = doctorInfo.getMobilePhone();
Integer acctId = modifyMobileService.getAcctIdByMobile(mobilePhone);
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
//新的手机号
String mobile = request.getMobile();
accountUtils.checkMobilePhoneAndAuthCode(mobile, AccountTypeEnum.SYSCODE_TYPE_MODIFY_MOBILE.getCode() + "", request.getAuthCode());
//判断当前手机号是否已经注册过
AccountInfoEntity accountInfoEntity = accountService.getAccountByMobilePhone(mobile);
if (accountInfoEntity == null) {
modifyMobileService.recodeMobileModify(acctId,mobilePhone,mobile);
modifyMobileService.modify(acctId, mobile);
return PicaResponse.toResponse();
} else {
......
package com.pica.cloud.account.account.server.entity;
import java.util.Date;
public class LogMobileModify {
private Integer id;
private Integer acctId;
private String mobilePhoneNew;
private String mobilePhoneOld;
private Date modifiedTime;
private Integer modifiedId;
private Integer deleteFlag;
private Integer createdId;
private Date createdTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getAcctId() {
return acctId;
}
public void setAcctId(Integer acctId) {
this.acctId = acctId;
}
public String getMobilePhoneNew() {
return mobilePhoneNew;
}
public void setMobilePhoneNew(String mobilePhoneNew) {
this.mobilePhoneNew = mobilePhoneNew == null ? null : mobilePhoneNew.trim();
}
public String getMobilePhoneOld() {
return mobilePhoneOld;
}
public void setMobilePhoneOld(String mobilePhoneOld) {
this.mobilePhoneOld = mobilePhoneOld == null ? null : mobilePhoneOld.trim();
}
public Date getModifiedTime() {
return modifiedTime;
}
public void setModifiedTime(Date modifiedTime) {
this.modifiedTime = modifiedTime;
}
public Integer getModifiedId() {
return modifiedId;
}
public void setModifiedId(Integer modifiedId) {
this.modifiedId = modifiedId;
}
public Integer getDeleteFlag() {
return deleteFlag;
}
public void setDeleteFlag(Integer deleteFlag) {
this.deleteFlag = deleteFlag;
}
public Integer getCreatedId() {
return createdId;
}
public void setCreatedId(Integer createdId) {
this.createdId = createdId;
}
public Date getCreatedTime() {
return createdTime;
}
public void setCreatedTime(Date createdTime) {
this.createdTime = createdTime;
}
}
\ No newline at end of file
......@@ -26,7 +26,10 @@ public enum AccountExceptionEnum {
PICA_SYSCODE_RETRY("216518", "请X秒后重试"),
PICA_NOT_EXIST("216519", "该用户不存在"),
PICA_REGISTER_FAIL("216520", "注册失败"),
PICA_WECHAT_CODE_ERROR("216521", "微信登录授权code不正确");
PICA_WECHAT_CODE_ERROR("216521", "微信登录授权code不正确"),
PICA_WECHAT_UNBIND("216522", "该微信号已绑定其他云鹊医账户,你可以使用微信登录云鹊医,在「设置」页解除绑定"),
PICA_WECHAT_BIND_OTHER("216524", "该手机号已绑定其他微信号,你可以在「设置」页解除绑定"),
PICA_WECHAT_UNBIND_CURRENT("216523", "正在绑定中,请稍等");
private String code;
......
......@@ -22,6 +22,9 @@ public interface AccountUnionMapper {
AccountUnionEntity selectByUnionId(String unionId);
AccountUnionEntity selectByAcctId(Integer acctId);
int deleteByPrimaryKey(Integer id);
int insert(AccountUnionEntity record);
......@@ -34,5 +37,9 @@ public interface AccountUnionMapper {
int updateByPrimaryKey(AccountUnionEntity record);
/**
* 通过unionid更新记录信息
* @param unionId
*/
void updateUnionStatus(String unionId);
}
\ No newline at end of file
package com.pica.cloud.account.account.server.mapper;
import com.pica.cloud.account.account.server.entity.LogMobileModify;
public interface LogMobileModifyMapper {
int deleteByPrimaryKey(Integer id);
int insert(LogMobileModify record);
int insertSelective(LogMobileModify record);
LogMobileModify selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(LogMobileModify record);
int updateByPrimaryKey(LogMobileModify record);
}
\ No newline at end of file
......@@ -13,4 +13,14 @@ public interface ModifyMobileService {
Integer getAcctIdByMobile(String phone);
/**
* 记录手机号的变更记录
* @param acctId
* @param mobilePhone
* @param mobile
*/
void recodeMobileModify(Integer acctId, String mobilePhone, String mobile);
}
......@@ -193,7 +193,9 @@ public class LoginServiceImpl implements LoginService {
return result;
}
@Override
@Transactional
public LoginResult loginByWeChat(BaseRequest request) {
WeChatEntity weChatEntity = WeChatUtils.getAuthorizationInfo(appId, appSecret, request.getWeChatCode());
if (weChatEntity == null || StringUtils.isEmpty(weChatEntity.getOpenid()) || StringUtils.isEmpty(weChatEntity.getAccess_token())) {
......@@ -207,8 +209,8 @@ public class LoginServiceImpl implements LoginService {
WeChatUserInfoEntity weChatUserInfoEntity = WeChatUtils.mergeWechatUserInfo(weChatUserInfo, weChatEntity.getOpenid());
String unionId = weChatUserInfoEntity.getUnionid();
AccountUnionEntity accountUnionEntity = accountUnionMapper.selectByUnionId(unionId);
//是否绑定逻辑的判断
if (accountUnionEntity != null) {
//是否绑定逻辑的判断
Long acctId = accountUnionEntity.getAcctId();
Long userId = accountUtils.getUserIdByAcctId(request.getProductType(), acctId.intValue());
Account account = new Account();
......@@ -232,6 +234,7 @@ public class LoginServiceImpl implements LoginService {
return result;
} else {
AccountWeChatInfoEntity entity = accountWeChatInfoMapper.selectByUnionId(unionId);
//如果微信信息表数据不存在,就把用户信息存储到微信信息表中。
if (entity == null) {
processWeChatInfoUser(weChatUserInfoEntity, request.getWeChatLoginType());
}
......@@ -264,7 +267,7 @@ public class LoginServiceImpl implements LoginService {
result.setMobile(request.getMobile());
AccountInfoEntity accountInfo = accountInfoDetailMapper.selectByMobile(AESUtil.encryptV0(request.getMobile()));
Integer acctId = accountInfo.getId();
processAccountUnion(acctId, request.getUnionId());
processAccountUnion(acctId, request.getUnionId(),request.getProductType());
return result;
}
......@@ -295,7 +298,7 @@ public class LoginServiceImpl implements LoginService {
updateWechatInfoUser(entity, weChatUserInfoEntity);
}
Integer acctId = doctorInfoMapper.getAcctIdByDoctorId(doctorId);
processAccountUnion(acctId, unionId);
processAccountUnion(acctId, unionId,request.getProductType());
return weChatUserInfoEntity.getNickname();
}
......@@ -305,7 +308,16 @@ public class LoginServiceImpl implements LoginService {
* @param acctId
* @param unionId
*/
private void processAccountUnion(Integer acctId, String unionId) {
private void processAccountUnion(Integer acctId, String unionId,Integer productType) {
//先查询当前产品线是否有记录?如果有就更新成delete_flag=2; 然后在插入新的绑定记录
AccountUnionEntity accountUnionResult = accountUnionMapper.selectByUnionId(unionId);
if (accountUnionResult!=null){
throw new PicaException(AccountExceptionEnum.PICA_WECHAT_UNBIND.getCode(), AccountExceptionEnum.PICA_WECHAT_UNBIND.getMessage());
}
AccountUnionEntity accountUnionEntityAccount = accountUnionMapper.selectByAcctId(acctId);
if (accountUnionEntityAccount!=null){
throw new PicaException(AccountExceptionEnum.PICA_WECHAT_BIND_OTHER.getCode(), AccountExceptionEnum.PICA_WECHAT_BIND_OTHER.getMessage());
}
AccountUnionEntity accountUnionEntity = new AccountUnionEntity();
accountUnionEntity.setAcctId(acctId.longValue());
accountUnionEntity.setDeleteFlag(1);
......
......@@ -2,12 +2,16 @@ package com.pica.cloud.account.account.server.service.impl;
import com.pica.cloud.account.account.server.entity.AccountInfoEntity;
import com.pica.cloud.account.account.server.entity.Doctor;
import com.pica.cloud.account.account.server.entity.LogMobileModify;
import com.pica.cloud.account.account.server.enums.AccountExceptionEnum;
import com.pica.cloud.account.account.server.exception.AccountException;
import com.pica.cloud.account.account.server.mapper.AccountInfoDetailMapper;
import com.pica.cloud.account.account.server.mapper.DoctorMapper;
import com.pica.cloud.account.account.server.mapper.LogMobileModifyMapper;
import com.pica.cloud.account.account.server.service.ModifyMobileService;
import com.pica.cloud.account.account.server.util.AESUtil;
import com.pica.cloud.foundation.encryption.common.constants.EncryptConstants;
import com.pica.cloud.foundation.encryption.util.EncryptUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -25,6 +29,9 @@ public class ModifyMobileServiceImpl implements ModifyMobileService {
@Autowired
private DoctorMapper doctorMapper;
@Autowired
private LogMobileModifyMapper logMobileModifyMapper;
@Value("${doubleWritingMode}")
private boolean doubleWritingMode;
......@@ -64,4 +71,26 @@ public class ModifyMobileServiceImpl implements ModifyMobileService {
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(phone);
return accountInfoEntity.getId();
}
/**
* 记录账号对应的手机号的变更信息
*
* @param acctId
* @param mobilePhone
* @param mobile
*/
@Override
public void recodeMobileModify(Integer acctId, String mobilePhone, String mobile) {
Date date = new Date();
LogMobileModify logMobileModify = new LogMobileModify();
logMobileModify.setAcctId(acctId);
logMobileModify.setDeleteFlag(1);
logMobileModify.setCreatedId(acctId);
logMobileModify.setCreatedTime(date);
logMobileModify.setModifiedId(acctId);
logMobileModify.setModifiedTime(date);
logMobileModify.setMobilePhoneNew(EncryptUtils.encryptContent(mobile,EncryptConstants.ENCRYPT_TYPE_MOBILE));
logMobileModify.setMobilePhoneOld(mobilePhone);
logMobileModifyMapper.insert(logMobileModify);
}
}
......@@ -179,27 +179,27 @@ public class AESUtil {
* 测试
*/
public static void main(String[] args) throws Exception {
// String KEY="zJJ$c5md3$yuuhWW";
// System.out.println("-------------加密---------");
// String content = "18621903846";
//
//
// System.out.println("加密前:" + content);
// System.out.println("加密密钥和解密密钥:" + KEY);
//
// System.out.println("-------------解密---------");
// String encrypt = aesEncrypt(content, KEY);
// System.out.println("加密后:" + encrypt);
// String decrypt = aesDecrypt("ieE4wN+GkIxm8S8tSVqTow==", KEY);
// System.out.println("解密后:" + decrypt);
String KEY="zJJ$c5md3$yuuhWW";
System.out.println("-------------加密---------");
String content = "15607241351";
System.out.println("加密前:" + content);
System.out.println("加密密钥和解密密钥:" + KEY);
System.out.println("-------------解密---------");
String encrypt = aesEncrypt(content, KEY);
System.out.println("加密后:" + encrypt);
String decrypt = aesDecrypt(encrypt, KEY);
System.out.println("解密后:" + decrypt);
//请求参数解密处理
String key="am1pnysCRlz80Rl/eTDj/UE/Pe8zkxb2yP73jvrUWEk3x5/lK9hi104MSmsKbl45cPzJfJXBxO+VeItkA63ZqfaUNA0ezdMd7Ord7rGqvWK+4RqAm1T3Qo3lw/5bT0GwgWMWZBrDr30NHCYLmjg6vwVbv3YCEewwQK+rL7bUXu0=";
String decrypt = RSAUtil.decrypt(key,privateKey);
System.out.println(decrypt);
String content="d9eKA7DGhNx7295N0g82rqzaUOeAvBeuR2gXtOX3Y+VV3ei+zW0BQn9moQgN4mRT8XIzq3x2n3qiqCuOzcDvrlGC0kIcUClM0gt8xDaBw+haVpMAw/7R4FgWNPeVRL5k";
String result = AESUtil.aesDecrypt(content, decrypt);
System.out.println(result);
// String key="am1pnysCRlz80Rl/eTDj/UE/Pe8zkxb2yP73jvrUWEk3x5/lK9hi104MSmsKbl45cPzJfJXBxO+VeItkA63ZqfaUNA0ezdMd7Ord7rGqvWK+4RqAm1T3Qo3lw/5bT0GwgWMWZBrDr30NHCYLmjg6vwVbv3YCEewwQK+rL7bUXu0=";
// String decrypt = RSAUtil.decrypt(key,privateKey);
// System.out.println(decrypt);
// String content="d9eKA7DGhNx7295N0g82rqzaUOeAvBeuR2gXtOX3Y+VV3ei+zW0BQn9moQgN4mRT8XIzq3x2n3qiqCuOzcDvrlGC0kIcUClM0gt8xDaBw+haVpMAw/7R4FgWNPeVRL5k";
// String result = AESUtil.aesDecrypt(content, decrypt);
// System.out.println(result);
// ArrayList<String> list = new ArrayList<>();
......
......@@ -33,6 +33,15 @@
limit 1
</select>
<!--通过unionId查询用户信息-->
<select id="selectByAcctId" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"/>
from account_union
where acct_id = #{acctId,jdbcType=INTEGER} and delete_flag = 1
limit 1
</select>
<!--解除绑定关系-->
<update id="updateUnbindByAcctId" parameterType="java.lang.Integer">
update account_union
......@@ -45,6 +54,13 @@
where id = #{id,jdbcType=INTEGER}
</delete>
<!--更新以前的unionId状态-->
<update id="updateUnionStatus" parameterType="java.lang.String">
update account_union
set delete_flag = 2,modified_time=NOW()
where union_id = #{unionId} and delete_flag = 1
</update>
<insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.AccountUnionEntity">
insert into account_union (id, acct_id, union_type,
union_id, delete_flag, created_id,
......
<?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.LogMobileModifyMapper" >
<resultMap id="BaseResultMap" type="com.pica.cloud.account.account.server.entity.LogMobileModify" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="acct_id" property="acctId" jdbcType="INTEGER" />
<result column="mobile_phone_new" property="mobilePhoneNew" jdbcType="VARCHAR" />
<result column="mobile_phone_old" property="mobilePhoneOld" jdbcType="VARCHAR" />
<result column="modified_time" property="modifiedTime" jdbcType="TIMESTAMP" />
<result column="modified_id" property="modifiedId" jdbcType="INTEGER" />
<result column="delete_flag" property="deleteFlag" jdbcType="INTEGER" />
<result column="created_id" property="createdId" jdbcType="INTEGER" />
<result column="created_time" property="createdTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
id, acct_id, mobile_phone_new, mobile_phone_old, modified_time, modified_id, delete_flag,
created_id, created_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from log_mobile_modify
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from log_mobile_modify
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.LogMobileModify" >
insert into log_mobile_modify (id, acct_id, mobile_phone_new,
mobile_phone_old, modified_time, modified_id,
delete_flag, created_id, created_time
)
values (#{id,jdbcType=INTEGER}, #{acctId,jdbcType=INTEGER}, #{mobilePhoneNew,jdbcType=VARCHAR},
#{mobilePhoneOld,jdbcType=VARCHAR}, #{modifiedTime,jdbcType=TIMESTAMP}, #{modifiedId,jdbcType=INTEGER},
#{deleteFlag,jdbcType=INTEGER}, #{createdId,jdbcType=INTEGER}, #{createdTime,jdbcType=TIMESTAMP}
)
</insert>
<insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.LogMobileModify" >
insert into log_mobile_modify
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="acctId != null" >
acct_id,
</if>
<if test="mobilePhoneNew != null" >
mobile_phone_new,
</if>
<if test="mobilePhoneOld != null" >
mobile_phone_old,
</if>
<if test="modifiedTime != null" >
modified_time,
</if>
<if test="modifiedId != null" >
modified_id,
</if>
<if test="deleteFlag != null" >
delete_flag,
</if>
<if test="createdId != null" >
created_id,
</if>
<if test="createdTime != null" >
created_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="acctId != null" >
#{acctId,jdbcType=INTEGER},
</if>
<if test="mobilePhoneNew != null" >
#{mobilePhoneNew,jdbcType=VARCHAR},
</if>
<if test="mobilePhoneOld != null" >
#{mobilePhoneOld,jdbcType=VARCHAR},
</if>
<if test="modifiedTime != null" >
#{modifiedTime,jdbcType=TIMESTAMP},
</if>
<if test="modifiedId != null" >
#{modifiedId,jdbcType=INTEGER},
</if>
<if test="deleteFlag != null" >
#{deleteFlag,jdbcType=INTEGER},
</if>
<if test="createdId != null" >
#{createdId,jdbcType=INTEGER},
</if>
<if test="createdTime != null" >
#{createdTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.account.account.server.entity.LogMobileModify" >
update log_mobile_modify
<set >
<if test="acctId != null" >
acct_id = #{acctId,jdbcType=INTEGER},
</if>
<if test="mobilePhoneNew != null" >
mobile_phone_new = #{mobilePhoneNew,jdbcType=VARCHAR},
</if>
<if test="mobilePhoneOld != null" >
mobile_phone_old = #{mobilePhoneOld,jdbcType=VARCHAR},
</if>
<if test="modifiedTime != null" >
modified_time = #{modifiedTime,jdbcType=TIMESTAMP},
</if>
<if test="modifiedId != null" >
modified_id = #{modifiedId,jdbcType=INTEGER},
</if>
<if test="deleteFlag != null" >
delete_flag = #{deleteFlag,jdbcType=INTEGER},
</if>
<if test="createdId != null" >
created_id = #{createdId,jdbcType=INTEGER},
</if>
<if test="createdTime != null" >
created_time = #{createdTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.pica.cloud.account.account.server.entity.LogMobileModify" >
update log_mobile_modify
set acct_id = #{acctId,jdbcType=INTEGER},
mobile_phone_new = #{mobilePhoneNew,jdbcType=VARCHAR},
mobile_phone_old = #{mobilePhoneOld,jdbcType=VARCHAR},
modified_time = #{modifiedTime,jdbcType=TIMESTAMP},
modified_id = #{modifiedId,jdbcType=INTEGER},
delete_flag = #{deleteFlag,jdbcType=INTEGER},
created_id = #{createdId,jdbcType=INTEGER},
created_time = #{createdTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册