fix:登录调整
This commit is contained in:
@@ -22,6 +22,8 @@ public class CommonConstants {
|
||||
|
||||
public static final int THREE_DAY_SECONDS = 60 * 60 * 24 * 3;
|
||||
|
||||
public static final int SEVEN_DAY_SECONDS = 60 * 60 * 24 * 7;
|
||||
|
||||
public static final int NORMAL_LOCK_TIMES = 60 * 1000;
|
||||
|
||||
public static final int AN_HOUR_SECONDS = 3600;
|
||||
@@ -48,6 +50,8 @@ public class CommonConstants {
|
||||
public static final String WX_APP_SECRET_KEY = "wx_app_secret_key:{0}";
|
||||
public static final String MINI_PROGRAM_SESSION_KEY = "mini_program_session_key:{0}:{1}";
|
||||
|
||||
public static final String MINI_PROGRAM_LOGIN_FLAG = "mini_program_login_flag:{0}";
|
||||
|
||||
public static final String ROOT_DEPT_ID_STR = "1";
|
||||
|
||||
public static final Integer DEAL_RECORD_MAX_SIZE = 1000;
|
||||
|
||||
@@ -61,6 +61,7 @@ public enum ErrorCodeEnum {
|
||||
PARAMS_REQUIRED(400002, "参数缺失!", null),
|
||||
DATA_CONVERT_ERROR(400002, "日期转换异常!", null),
|
||||
PARENT_NODE_NOT_EXIST(400002, "父节点不存在", null),
|
||||
LOGIN_ERROR_MOBILE_ERROR(418, "登录失败 获取手机号失败!!", null),
|
||||
|
||||
|
||||
LINE_ID_IS_NOT_EXIST(500001, "线索信息不存在!", null),
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.cool.store.dao;
|
||||
|
||||
import com.cool.store.entity.PartnerUserWechatBindDO;
|
||||
import com.cool.store.mapper.PartnerUserWechatBindMapper;
|
||||
import com.cool.store.utils.StringUtil;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @Author suzhuhong
|
||||
* @Date 2025/2/19 15:09
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Repository
|
||||
public class PartnerUserWechatBindDAO {
|
||||
|
||||
@Resource
|
||||
PartnerUserWechatBindMapper partnerUserWechatBindMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @param partnerUserWechatBindDO
|
||||
* @return
|
||||
*/
|
||||
public Integer insertSelective(PartnerUserWechatBindDO partnerUserWechatBindDO) {
|
||||
if (partnerUserWechatBindDO == null) {
|
||||
return 0;
|
||||
}
|
||||
return partnerUserWechatBindMapper.insertSelective(partnerUserWechatBindDO);
|
||||
}
|
||||
|
||||
|
||||
public PartnerUserWechatBindDO getByOpenIdAndPartnerId(String partnerId, String openId) {
|
||||
if (StringUtil.isNotEmpty(partnerId)|| StringUtil.isEmpty(openId)){
|
||||
return null;
|
||||
}
|
||||
return partnerUserWechatBindMapper.selectByPartnerAndOpenId(partnerId,openId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.cool.store.mapper;
|
||||
|
||||
import com.cool.store.entity.PartnerUserWechatBindDO;
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
|
||||
/**
|
||||
* @Author suzhuhong
|
||||
* @Date 2025/2/19 15:07
|
||||
* @Version 1.0
|
||||
*/
|
||||
public interface PartnerUserWechatBindMapper extends Mapper<PartnerUserWechatBindDO> {
|
||||
|
||||
|
||||
/**
|
||||
* 根据partnerId与openId查询
|
||||
* @param partnerId
|
||||
* @param openId
|
||||
* @return
|
||||
*/
|
||||
PartnerUserWechatBindDO selectByPartnerAndOpenId(String partnerId, String openId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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.cool.store.mapper.PartnerUserWechatBindMapper">
|
||||
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.cool.store.entity.PartnerUserWechatBindDO">
|
||||
<id column="id" property="id" jdbcType="BIGINT" />
|
||||
<result column="open_id" property="openId" jdbcType="VARCHAR" />
|
||||
<result column="bind_time" property="bindTime" jdbcType="TIMESTAMP" />
|
||||
<result column="partner_id" property="partnerId" jdbcType="VARCHAR" />
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
|
||||
</resultMap>
|
||||
|
||||
<select id="selectByPartnerAndOpenId" resultMap="BaseResultMap">
|
||||
select * from zl_partner_user_wechat_bind where partner_id = #{partnerId} and open_id = #{openId}
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.cool.store.entity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* C端微信用户映射表DO
|
||||
* </p>
|
||||
*
|
||||
* @author ZhangHua
|
||||
* @since 2024/08/19
|
||||
*/
|
||||
@Data
|
||||
public class PartnerUserWechatBindDO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 平台内用户标识
|
||||
*/
|
||||
private String openId;
|
||||
|
||||
/**
|
||||
* 绑定时间
|
||||
*/
|
||||
private Date bindTime;
|
||||
|
||||
/**
|
||||
* zl_partner_user_info.partner_id
|
||||
*/
|
||||
private String partnerId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
}
|
||||
@@ -17,6 +17,8 @@ public interface WechatMiniAppService {
|
||||
|
||||
PartnerUserInfoVO getUserInfoByJsCode(String jsCode);
|
||||
|
||||
Boolean cancellation(String openId);
|
||||
|
||||
String getUserPhoneNumber(String mobileCode);
|
||||
|
||||
String updateUserPhoneNumber(MobileUpdateRequest request, PartnerUserInfoVO userInfoVO);
|
||||
|
||||
@@ -49,6 +49,8 @@ public class WechatMiniAppServiceImpl implements WechatMiniAppService {
|
||||
private LineInfoDAO lineInfoDAO;
|
||||
@Resource
|
||||
HyOpenAreaInfoDAO hyOpenAreaInfoDAO;
|
||||
@Resource
|
||||
PartnerUserWechatBindDAO partnerUserWechatBindDAO;
|
||||
@Value("${weixin.appId}")
|
||||
private String wxAppId;
|
||||
@Value("${weixin.appSecret}")
|
||||
@@ -72,59 +74,25 @@ public class WechatMiniAppServiceImpl implements WechatMiniAppService {
|
||||
}
|
||||
CodeSessionDTO codeSession = wechatRest.miniProgramJsCodeSession(wxAppId, wxAppSecret, jsCode);
|
||||
String openid = codeSession.getOpenid();
|
||||
String sessionCacheKey = MessageFormat.format(CommonConstants.MINI_PROGRAM_SESSION_KEY, wxAppId, openid);
|
||||
redisUtilPool.setString(sessionCacheKey, codeSession.getSessionKey(), CommonConstants.THREE_DAY_SECONDS);
|
||||
String unionId = codeSession.getUnionId();
|
||||
log.info("小程序登录:{}", unionId);
|
||||
log.info("sessionKey {}", codeSession.getSessionKey());
|
||||
/* String decryptUser = AesUtil.decryptWechat(codeSession.getSessionKey(), param.getEncryptedData(), param.getIvStr());
|
||||
log.info("解密用户信息:{}", decryptUser);
|
||||
MiniProgramUserVO miniProgramUser = JSON.parseObject(decryptUser, MiniProgramUserVO.class);
|
||||
if (Objects.isNull(miniProgramUser)) {
|
||||
throw new ServiceException(ErrorCodeEnum.GET_WECHAT_USER_INFO_FAIL);
|
||||
}*/
|
||||
// 获取小程序token
|
||||
String accessToken = wechatRest.getAccessToken(wxAppId, wxAppSecret);
|
||||
// 获取手机号码
|
||||
PhoneInfoDTO phoneInfoDTO = wechatRest.getUserPhoneNumber(param.getMobileCode(), accessToken);
|
||||
if(phoneInfoDTO != null && phoneInfoDTO.getPhoneInfo() != null && StringUtils.isNotBlank(phoneInfoDTO.getPhoneInfo().getPhoneNumber())){
|
||||
HyPartnerUserInfoDO hyPartnerUserInfoDO = hyPartnerUserInfoDAO.selectByOpenid(openid);
|
||||
if( hyPartnerUserInfoDO != null && !hyPartnerUserInfoDO.getMobile().equals(phoneInfoDTO.getPhoneInfo().getPhoneNumber())){
|
||||
throw new ServiceException(ErrorCodeEnum.WECHAT_BIND_OTHER_MOBILE);
|
||||
if (Objects.isNull(phoneInfoDTO) || Objects.isNull(phoneInfoDTO.getPhoneInfo())){
|
||||
throw new ServiceException(ErrorCodeEnum.LOGIN_ERROR_MOBILE_ERROR);
|
||||
}
|
||||
// 微信未授权过
|
||||
if(hyPartnerUserInfoDO == null){
|
||||
hyPartnerUserInfoDO = hyPartnerUserInfoDAO.selectByMobile(phoneInfoDTO.getPhoneInfo().getPhoneNumber());
|
||||
if(hyPartnerUserInfoDO != null && StringUtils.isNotBlank(hyPartnerUserInfoDO.getOpenid()) && !openid.equals(hyPartnerUserInfoDO.getOpenid())){
|
||||
throw new ServiceException(ErrorCodeEnum.MOBILE_WECHAT_EXIST);
|
||||
}
|
||||
if(hyPartnerUserInfoDO == null){
|
||||
//通过手机号查询用户信
|
||||
HyPartnerUserInfoDO hyPartnerUserInfoDO = hyPartnerUserInfoDAO.selectByMobile(phoneInfoDTO.getPhoneInfo().getPhoneNumber());
|
||||
if (hyPartnerUserInfoDO == null) {
|
||||
//系统中没有改手机号 需要先注册该手机号
|
||||
hyPartnerUserInfoDO = new HyPartnerUserInfoDO();
|
||||
hyPartnerUserInfoDO.setMobile(phoneInfoDTO.getPhoneInfo().getPhoneNumber());
|
||||
hyPartnerUserInfoDO.setOpenid(openid);
|
||||
hyPartnerUserInfoDO.setPartnerId(UUIDUtils.get32UUID());
|
||||
Integer channelId = null;
|
||||
String userChannel = param.getUserChannelEnum();
|
||||
if(StringUtils.isNotEmpty(userChannel)){
|
||||
if(UserChannelEnum.EXHIBITION.getCode().equals(userChannel)){
|
||||
channelId = exhibition;
|
||||
}else if(UserChannelEnum.RECOMMENDED.getCode().equals(userChannel)){
|
||||
channelId = recommended;
|
||||
}else {
|
||||
if (StringUtils.isNumeric(userChannel)) {
|
||||
channelId = Integer.valueOf(userChannel);
|
||||
HyPartnerUserChannelDO hyPartnerUserChannelDO = hyPartnerUserChannelMapper.selectByChannelId(Long.valueOf(channelId));
|
||||
if (Objects.isNull(hyPartnerUserChannelDO)|| hyPartnerUserChannelDO.getChannelId() == null ) {
|
||||
//用户渠道不存在
|
||||
throw new ServiceException(ErrorCodeEnum.USER_CHANNEL_NOT_EXISTS);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
hyPartnerUserInfoDO.setUserChannelId(channelId);
|
||||
hyPartnerUserInfoDAO.insertSelective(hyPartnerUserInfoDO);
|
||||
//授权的时候 新增线索 放到公海
|
||||
LineInfoDO lineInfoDO = new LineInfoDO();
|
||||
lineInfoDO.setLineStatus(LineStatusEnum.PUBLIC_SEAS.getCode());
|
||||
lineInfoDO.setWorkflowSubStage(WorkflowSubStageEnum.INTEND.getCode());
|
||||
@@ -134,16 +102,23 @@ public class WechatMiniAppServiceImpl implements WechatMiniAppService {
|
||||
lineInfoDO.setWorkflowSubStageStatus(WorkflowSubStageStatusEnum.INTENT_0.getCode());
|
||||
lineInfoDO.setPartnerId(hyPartnerUserInfoDO.getPartnerId());
|
||||
lineInfoDAO.insertOrUpdate(lineInfoDO);
|
||||
}else {
|
||||
hyPartnerUserInfoDO.setOpenid(openid);
|
||||
hyPartnerUserInfoDAO.updateByPrimaryKeySelective(hyPartnerUserInfoDO);
|
||||
}
|
||||
//判断绑定表种是否绑定了手机号与微信openid
|
||||
PartnerUserWechatBindDO zlPartnerUserBindDO = partnerUserWechatBindDAO.getByOpenIdAndPartnerId(hyPartnerUserInfoDO.getPartnerId(), openid);
|
||||
if (zlPartnerUserBindDO == null) {
|
||||
//绑定手机号与微信openid
|
||||
PartnerUserWechatBindDO bindDO = new PartnerUserWechatBindDO();
|
||||
bindDO.setBindTime(new Date());
|
||||
bindDO.setOpenId(openid);
|
||||
bindDO.setPartnerId(hyPartnerUserInfoDO.getPartnerId());
|
||||
bindDO.setCreateTime(new Date());
|
||||
partnerUserWechatBindDAO.insertSelective(bindDO);
|
||||
}
|
||||
BeanUtil.copyProperties(hyPartnerUserInfoDO, userInfoVO);
|
||||
fillLineInfo(userInfoVO, hyPartnerUserInfoDO.getPartnerId());
|
||||
}
|
||||
userInfoVO.setOpenid(openid);
|
||||
userInfoVO.setUnionId(unionId);
|
||||
//将数据存储到redis中
|
||||
String key = MessageFormat.format(CommonConstants.MINI_PROGRAM_LOGIN_FLAG, openid);
|
||||
redisUtilPool.setString(key,JSONObject.toJSONString(userInfoVO),CommonConstants.SEVEN_DAY_SECONDS);
|
||||
return userInfoVO;
|
||||
}
|
||||
|
||||
@@ -157,17 +132,28 @@ public class WechatMiniAppServiceImpl implements WechatMiniAppService {
|
||||
}
|
||||
CodeSessionDTO codeSession = wechatRest.miniProgramJsCodeSession(wxAppId, wxAppSecret, jsCode);
|
||||
String openid = codeSession.getOpenid();
|
||||
String sessionCacheKey = MessageFormat.format(CommonConstants.MINI_PROGRAM_SESSION_KEY, wxAppId, openid);
|
||||
redisUtilPool.setString(sessionCacheKey, codeSession.getSessionKey(), CommonConstants.THREE_DAY_SECONDS);
|
||||
HyPartnerUserInfoDO hyPartnerUserInfoDO = hyPartnerUserInfoDAO.selectByOpenid(openid);
|
||||
if(hyPartnerUserInfoDO != null){
|
||||
userInfoVO = new PartnerUserInfoVO();
|
||||
BeanUtil.copyProperties(hyPartnerUserInfoDO, userInfoVO);
|
||||
fillLineInfo(userInfoVO, hyPartnerUserInfoDO.getPartnerId());
|
||||
String key = MessageFormat.format(CommonConstants.MINI_PROGRAM_LOGIN_FLAG, openid);
|
||||
String value = redisUtilPool.getString(key);
|
||||
if (StringUtils.isNotEmpty(value)){
|
||||
//设置有效期
|
||||
Long expire = redisUtilPool.getExpire(key);
|
||||
if (expire < CommonConstants.THREE_DAY_SECONDS){
|
||||
//重置时间为7天
|
||||
redisUtilPool.expire(key,CommonConstants.SEVEN_DAY_SECONDS);
|
||||
}
|
||||
userInfoVO = JSONObject.parseObject(value,PartnerUserInfoVO.class);
|
||||
}
|
||||
return userInfoVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean cancellation(String openId) {
|
||||
//删除登录态缓存
|
||||
String key = MessageFormat.format(CommonConstants.MINI_PROGRAM_LOGIN_FLAG, openId);
|
||||
redisUtilPool.delKey(key);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getUserPhoneNumber(String mobileCode) {
|
||||
|
||||
Reference in New Issue
Block a user