Commit 1d8b9822 authored by shiyu's avatar shiyu

Merge remote-tracking branch 'origin/master'

parents 7c302bec 8b8edf1a
package com.wwdz.ch.db.dao;
import com.wwdz.ch.db.domain.Switch;
public interface SwitchDao {
Switch find();
}
package com.wwdz.ch.db.domain;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
/**
* @author shiyu
* @date 2023/09/04
*/
@Data
public class Switch implements Serializable {
private Long id;
/**
* 状态(0:关闭,2:打开)
*/
private Integer state;
private static final long serialVersionUID = 1L;
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", state=").append(state);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
Switch other = (Switch) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getState() == null) ? 0 : getState().hashCode());
return result;
}
/**
* This enum was generated by MyBatis Generator.
* This enum corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public enum Column {
id("id", "id", "BIGINT", false),
state("state", "state", "INTEGER", true);
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private static final String BEGINNING_DELIMITER = "`";
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private static final String ENDING_DELIMITER = "`";
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final String column;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final boolean isColumnNameDelimited;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final String javaProperty;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final String jdbcType;
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String value() {
return this.column;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getValue() {
return this.column;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getJavaProperty() {
return this.javaProperty;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getJdbcType() {
return this.jdbcType;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
this.column = column;
this.javaProperty = javaProperty;
this.jdbcType = jdbcType;
this.isColumnNameDelimited = isColumnNameDelimited;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String desc() {
return this.getEscapedColumnName() + " DESC";
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String asc() {
return this.getEscapedColumnName() + " ASC";
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public static Column[] excludes(Column ... excludes) {
ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
if (excludes != null && excludes.length > 0) {
columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
}
return columns.toArray(new Column[]{});
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getEscapedColumnName() {
if (this.isColumnNameDelimited) {
return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
} else {
return this.column;
}
}
}
}
\ No newline at end of file
This diff is collapsed.
package com.wwdz.ch.db.impl;
import com.wwdz.ch.db.dao.SwitchDao;
import com.wwdz.ch.db.domain.Switch;
import com.wwdz.ch.db.domain.SwitchExample;
import com.wwdz.ch.db.mapper.SwitchMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@Repository
public class SwitchDaoImpl implements SwitchDao {
@Autowired
private SwitchMapper switchMapper;
@Override
public Switch find() {
SwitchExample switchExample = new SwitchExample();
switchExample.orderBy("id asc");
return switchMapper.selectOneByExample(switchExample);
}
}
package com.wwdz.ch.db.mapper;
import com.wwdz.ch.db.domain.Switch;
import com.wwdz.ch.db.domain.SwitchExample;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface SwitchMapper {
long countByExample(SwitchExample example);
int deleteByExample(SwitchExample example);
int deleteByPrimaryKey(Long id);
int insert(Switch record);
int insertSelective(Switch record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
Switch selectOneByExample(SwitchExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
Switch selectOneByExampleSelective(@Param("example") SwitchExample example, @Param("selective") Switch.Column ... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
List<Switch> selectByExampleSelective(@Param("example") SwitchExample example, @Param("selective") Switch.Column ... selective);
List<Switch> selectByExample(SwitchExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table switch
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
Switch selectByPrimaryKeySelective(@Param("id") Long id, @Param("selective") Switch.Column ... selective);
Switch selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") Switch record, @Param("example") SwitchExample example);
int updateByExample(@Param("record") Switch record, @Param("example") SwitchExample example);
int updateByPrimaryKeySelective(Switch record);
int updateByPrimaryKey(Switch record);
}
\ No newline at end of file
<?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.wwdz.ch.db.mapper.SwitchMapper">
<resultMap id="BaseResultMap" type="com.wwdz.ch.db.domain.Switch">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="state" jdbcType="INTEGER" property="state" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, `state`
</sql>
<select id="selectByExample" parameterType="com.wwdz.ch.db.domain.SwitchExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
'true' as QUERYID,
<include refid="Base_Column_List" />
from switch
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByExampleSelective" parameterType="map" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
'true' as QUERYID,
<if test="example.distinct">
distinct
</if>
<choose>
<when test="selective != null and selective.length > 0">
<foreach collection="selective" item="column" separator=",">
${column.escapedColumnName}
</foreach>
</when>
<otherwise>
id, `state`
</otherwise>
</choose>
from switch
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
<if test="example.orderByClause != null">
order by ${example.orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from switch
where id = #{id,jdbcType=BIGINT}
</select>
<select id="selectByPrimaryKeySelective" parameterType="map" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
<choose>
<when test="selective != null and selective.length > 0">
<foreach collection="selective" item="column" separator=",">
${column.escapedColumnName}
</foreach>
</when>
<otherwise>
id, `state`
</otherwise>
</choose>
from switch
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from switch
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="com.wwdz.ch.db.domain.SwitchExample">
delete from switch
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.wwdz.ch.db.domain.Switch">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into switch (`state`)
values (#{state,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.wwdz.ch.db.domain.Switch">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into switch
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="state != null">
`state`,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="state != null">
#{state,jdbcType=INTEGER},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.wwdz.ch.db.domain.SwitchExample" resultType="java.lang.Long">
select count(*) from switch
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update switch
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.state != null">
`state` = #{record.state,jdbcType=INTEGER},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update switch
set id = #{record.id,jdbcType=BIGINT},
`state` = #{record.state,jdbcType=INTEGER}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.wwdz.ch.db.domain.Switch">
update switch
<set>
<if test="state != null">
`state` = #{state,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.wwdz.ch.db.domain.Switch">
update switch
set `state` = #{state,jdbcType=INTEGER}
where id = #{id,jdbcType=BIGINT}
</update>
<select id="selectOneByExample" parameterType="com.wwdz.ch.db.domain.SwitchExample" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
'true' as QUERYID,
<include refid="Base_Column_List" />
from switch
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
limit 1
</select>
<select id="selectOneByExampleSelective" parameterType="map" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
'true' as QUERYID,
<choose>
<when test="selective != null and selective.length > 0">
<foreach collection="selective" item="column" separator=",">
${column.escapedColumnName}
</foreach>
</when>
<otherwise>
id, `state`
</otherwise>
</choose>
from switch
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
<if test="example.orderByClause != null">
order by ${example.orderByClause}
</if>
limit 1
</select>
</mapper>
\ No newline at end of file
......@@ -30,9 +30,9 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
registry.addInterceptor(loginInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/*.html", "/**/*.html", "/**/*.css", "/**/*.js"
, "/wx/user/loginByWx", "/wx/user/loginByMobile", "/wx/user/loginRegCaptcha", "/wx/user/updateRegCaptcha", "/wx/user/login"
, "/wx/item/page", "/wx/item/info", "/wx/item/findNames"
, "/wx/favorites/info", "/wx/favorites/itemList"
, "/wx/keyword/recommend", "/wx/queryPrice/**");
, "/wx/user/loginByWx", "/wx/user/loginByMobile", "/wx/user/loginRegCaptcha", "/wx/user/updateRegCaptcha", "/wx/user/login");
// , "/wx/item/page", "/wx/item/info", "/wx/item/findNames"
// , "/wx/favorites/info", "/wx/favorites/itemList"
// , "/wx/keyword/recommend", "/wx/queryPrice/**");
}
}
......@@ -4,8 +4,10 @@ import com.wwdz.ch.core.consts.InvitationCodeStateEnum;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dao.InvitationCodeDao;
import com.wwdz.ch.db.dao.InviteRecordDao;
import com.wwdz.ch.db.dao.UserDao;
import com.wwdz.ch.db.domain.InvitationCode;
import com.wwdz.ch.db.domain.InviteRecord;
import com.wwdz.ch.db.domain.User;
import com.wwdz.ch.db.dto.request.InvitationCodeRequestDto;
import com.wwdz.ch.db.dto.request.InviteRecordRequestDto;
import com.wwdz.ch.wx.service.InviteRecordService;
......@@ -17,6 +19,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@Service
public class InviteRecordServiceImpl implements InviteRecordService {
......@@ -29,6 +32,9 @@ public class InviteRecordServiceImpl implements InviteRecordService {
@Autowired
InvitationCodeDao invitationCodeDao;
@Autowired
UserDao userDao;
@Override
public Result create(InviteRecordRequestDto dto) {
try {
......@@ -74,6 +80,13 @@ public class InviteRecordServiceImpl implements InviteRecordService {
} else {
invitationCodeDao.updateState(dto.getInvitationCode(), InvitationCodeStateEnum.PART_USED.getCode());
}
// 更新user表
User user = userDao.queryById(dto.getInvitee());
if (Objects.nonNull(user)) {
user.setShareUserId(invitationCode.getApplicant());
userDao.updateById(user);
}
return Result.success();
} catch (Exception e) {
logger.error("邀请码使用失败:{}", e);
......
package com.wwdz.ch.wx.impl;
import com.wwdz.ch.db.dao.SwitchDao;
import com.wwdz.ch.db.domain.Switch;
import com.wwdz.ch.wx.service.SwitchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SwitchServiceImpl implements SwitchService {
@Autowired
private SwitchDao switchDao;
@Override
public Switch findOnly() {
return switchDao.find();
}
}
......@@ -12,8 +12,8 @@ import com.wwdz.ch.core.util.RegexUtil;
import com.wwdz.ch.core.util.UUID;
import com.wwdz.ch.core.util.bcrypt.BCryptPasswordEncoder;
import com.wwdz.ch.db.dao.UserDao;
import com.wwdz.ch.db.domain.Switch;
import com.wwdz.ch.db.domain.User;
import com.wwdz.ch.db.dto.request.FavoritesRequestDto;
import com.wwdz.ch.wx.constant.CacheCodeConstants;
import com.wwdz.ch.wx.constant.LoginTypeEnum;
import com.wwdz.ch.wx.dao.UserInfo;
......@@ -23,7 +23,8 @@ import com.wwdz.ch.wx.manager.AlipayLoginManager;
import com.wwdz.ch.wx.manager.TikTokLoginManager;
import com.wwdz.ch.wx.manager.UserTokenManager;
import com.wwdz.ch.wx.manager.WxLoginManager;
import com.wwdz.ch.wx.service.FavoritesService;
import com.wwdz.ch.wx.service.InviteRecordService;
import com.wwdz.ch.wx.service.SwitchService;
import com.wwdz.ch.wx.service.UserService;
import com.wwdz.ch.wx.util.IpUtil;
import com.wwdz.ch.wx.util.RedisUtil;
......@@ -59,8 +60,6 @@ public class UserServiceImpl implements UserService {
@Autowired
private ApplicationContext applicationContext;
@Autowired
private FavoritesService favoritesService;
@Autowired
private WxLoginManager wxLoginManager;
@Autowired
private AlipayLoginManager alipayLoginManager;
......@@ -74,6 +73,11 @@ public class UserServiceImpl implements UserService {
@Autowired
private AliSmsSender aliSmsSender;
@Autowired
private InviteRecordService inviteRecordService;
@Autowired
private SwitchService switchService;
@Override
public Result regCaptcha(UserRequestDto dto) {
......@@ -128,7 +132,12 @@ public class UserServiceImpl implements UserService {
}
// 获取登录结果
Map<String, Object> result = getLoginResult(dto.getMobile(), request);
Switch switchh = switchService.findOnly();
boolean isOpen = Objects.nonNull(switchh) && switchh.getState() == 1;
result.put("isInvited", inviteRecordService.isExisted(dto.getMobile()).getData());
if (!isOpen) {
result.put("isInvited", true);
}
logger.info("【请求结束】手机号登录,响应结果:{}", JSONObject.toJSONString(result));
// 清除验证码缓存
redisUtil.del(key);
......@@ -183,7 +192,12 @@ public class UserServiceImpl implements UserService {
}
// 获取登录结果
Map<String, Object> result = getLoginResult(mobile, request);
Switch switchh = switchService.findOnly();
boolean isOpen = Objects.nonNull(switchh) && switchh.getState() == 1;
result.put("isInvited", inviteRecordService.isExisted(mobile).getData());
if (!isOpen) {
result.put("isInvited", true);
}
logger.info("【请求结束】快捷登录成功,响应结果:{}", JSONObject.toJSONString(result));
return Result.success(result);
} catch (Exception e) {
......@@ -437,10 +451,6 @@ public class UserServiceImpl implements UserService {
user.setLastLoginIp(IpUtil.client(request));
user.setShareUserId(0L);
userDao.insert(user);
FavoritesRequestDto favoritesRequestDto = new FavoritesRequestDto();
favoritesRequestDto.setUserId(user.getId());
favoritesService.addDefault(favoritesRequestDto);
} else {
user.setLastLoginTime(new Date());
user.setLastLoginIp(IpUtil.client(request));
......
package com.wwdz.ch.wx.interceptor;
import com.alibaba.fastjson.JSON;
import com.wwdz.ch.db.dao.UserDao;
import com.wwdz.ch.db.domain.Switch;
import com.wwdz.ch.db.domain.User;
import com.wwdz.ch.wx.manager.UserTokenManager;
import com.wwdz.ch.wx.service.InviteRecordService;
import com.wwdz.ch.wx.service.SwitchService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -11,14 +16,24 @@ import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class LoginInterceptor implements HandlerInterceptor {
Logger logger = LoggerFactory.getLogger(LoginInterceptor.class);
@Autowired
private UserTokenManager userTokenManager;
@Autowired
private SwitchService switchService;
@Autowired
private UserDao userDao;
@Autowired
private InviteRecordService inviteRecordService;
String[] excludeUrl = {"/wx/item/page", "/wx/item/info", "/wx/item/findNames", "/wx/keyword/recommend"};
/***
* 在请求处理之前进行调用(Controller方法调用之前)
......@@ -27,19 +42,67 @@ public class LoginInterceptor implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
logger.info("进入拦截器");
String token = request.getHeader("Authorization");
if (StringUtils.isNotBlank(token)) {
if (userTokenManager.checkLogin(token)) {
Switch switchh = switchService.findOnly();
boolean isOpen = Objects.nonNull(switchh) && switchh.getState() == 1;
String url = request.getRequestURI();
if (!isOpen) {
if (Arrays.asList(excludeUrl).contains(url)) {
return true;
}
if (StringUtils.isNotBlank(token)) {
if (userTokenManager.checkLogin(token)) {
return true;
}
}
Map<Object, Object> map = new HashMap<>();
map.put("code", 401);
map.put("success", false);
map.put("message", "未登录!");
map.put("result", null);
response.setContentType("application/json; charset=utf-8");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.getWriter().write(JSON.toJSONString(map));
} else {
int loginType = 1;
if (StringUtils.isBlank(token)) {
loginType = 2;
} else {
if (userTokenManager.checkLogin(token)) {
if (StringUtils.equals(url, "/wx/user/fillCode")) {
return true;
}
User user = userDao.queryById(userTokenManager.getUserId(token));
if (!(Boolean) inviteRecordService.isExisted(user.getMobile()).getData()) {
loginType = 3;
}
} else {
loginType = 2;
}
}
if (loginType == 1) {
return true;
}
if (loginType == 2) {
Map<Object, Object> map = new HashMap<>();
map.put("code", 401);
map.put("success", false);
map.put("message", "未登录!");
map.put("result", null);
response.setContentType("application/json; charset=utf-8");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.getWriter().write(JSON.toJSONString(map));
}
if (loginType == 3) {
Map<Object, Object> map = new HashMap<>();
map.put("code", 403);
map.put("success", false);
map.put("message", "未授权!");
map.put("result", null);
response.setContentType("application/json; charset=utf-8");
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
response.getWriter().write(JSON.toJSONString(map));
}
}
Map<Object, Object> map = new HashMap<>();
map.put("code", 401);
map.put("success", false);
map.put("message", "未登录!");
map.put("result", null);
response.setContentType("application/json; charset=utf-8");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.getWriter().write(JSON.toJSONString(map));
return false;
}
......
......@@ -82,6 +82,7 @@ public class AlipayLoginManager {
logger.error("支付宝解密失败,解密异常", e);
return "false";
}
logger.info("支付宝解密结果:" + plainData);
if (StringUtils.isBlank(plainData) || !plainData.contains("mobile")) {
logger.info("支付宝解密失败,解密不通过");
return "false";
......
package com.wwdz.ch.wx.service;
import com.wwdz.ch.db.domain.Switch;
public interface SwitchService {
/**
* 获取开关配置
*
* @return
*/
Switch findOnly();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment