2024-09-19 注册页调试
parent
6c5a458185
commit
2cf242edee
|
|
@ -38,6 +38,9 @@ public class Customer extends BaseEntity
|
||||||
@Excel(name = "0 男 1 女")
|
@Excel(name = "0 男 1 女")
|
||||||
private Integer sex;
|
private Integer sex;
|
||||||
|
|
||||||
|
@Excel(name="身份证号")
|
||||||
|
private String idCard;
|
||||||
|
|
||||||
/** 昵称 */
|
/** 昵称 */
|
||||||
@Excel(name = "昵称")
|
@Excel(name = "昵称")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.constant.RedisConstant;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
@ -42,6 +44,11 @@ public class TokenService
|
||||||
|
|
||||||
private final static Long MILLIS_MINUTE_TEN = CacheConstants.REFRESH_TIME * MILLIS_MINUTE;
|
private final static Long MILLIS_MINUTE_TEN = CacheConstants.REFRESH_TIME * MILLIS_MINUTE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token过期时间
|
||||||
|
*/
|
||||||
|
private static final Long EXPIRE_TIME = 30 * 24 * 60 * 60L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建令牌
|
* 创建令牌
|
||||||
*/
|
*/
|
||||||
|
|
@ -69,6 +76,40 @@ public class TokenService
|
||||||
return rspMap;
|
return rspMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建令牌
|
||||||
|
*/
|
||||||
|
public String createTokenApp(Long customerId,Long channelId)
|
||||||
|
{
|
||||||
|
String token = IdUtils.fastUUID();
|
||||||
|
// Long userId = loginUser.getSysUser().getUserId();
|
||||||
|
// String userName = loginUser.getSysUser().getUserName();
|
||||||
|
// loginUser.setToken(token);
|
||||||
|
// loginUser.setUserid(userId);
|
||||||
|
// loginUser.setUsername(userName);
|
||||||
|
// loginUser.setIpaddr(IpUtils.getIpAddr());
|
||||||
|
// refreshToken(loginUser);
|
||||||
|
|
||||||
|
// Jwt存储信息
|
||||||
|
Map<String, Object> claimsMap = new HashMap<String, Object>();
|
||||||
|
claimsMap.put(SecurityConstants.USER_KEY, token);
|
||||||
|
claimsMap.put(SecurityConstants.DETAILS_USER_ID, customerId);
|
||||||
|
claimsMap.put(SecurityConstants.DETAILS_USERNAME, "userName");
|
||||||
|
|
||||||
|
// 接口返回信息
|
||||||
|
Map<String, Object> rspMap = new HashMap<String, Object>();
|
||||||
|
String token1 = JwtUtils.createToken(claimsMap);
|
||||||
|
rspMap.put("access_token", token1);
|
||||||
|
rspMap.put("expires_in", expireTime);
|
||||||
|
|
||||||
|
redisService.setCacheObject(RedisConstant.APP_CUSTOMER_USERNAME_KEY + token1, customerId, EXPIRE_TIME, TimeUnit.SECONDS);
|
||||||
|
redisService.setCacheObject(RedisConstant.APP_CUSTOMER_KEY + customerId, token1, EXPIRE_TIME, TimeUnit.SECONDS);
|
||||||
|
redisService.setCacheObject(RedisConstant.APP_CUSTOMER_CHANNEL_KEY + token1, channelId, EXPIRE_TIME, TimeUnit.SECONDS);
|
||||||
|
redisService.setCacheObject(RedisConstant.APP_CUSTOMER_TOKEN_KEY + token1, customerId, EXPIRE_TIME, TimeUnit.SECONDS);
|
||||||
|
redisService.setCacheObject( CacheConstants.LOGIN_TOKEN_KEY+token,customerId,EXPIRE_TIME,TimeUnit.SECONDS);
|
||||||
|
return token1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户身份信息
|
* 获取用户身份信息
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,7 @@ public class SysPublicHalfServiceImpl implements ISysPublicHalfService
|
||||||
if (customerInfoByPhoneMd5.getCode()==200){
|
if (customerInfoByPhoneMd5.getCode()==200){
|
||||||
remoteCustomerService.updateByPhoneMd5(customer,SecurityConstants.INNER);
|
remoteCustomerService.updateByPhoneMd5(customer,SecurityConstants.INNER);
|
||||||
}else {
|
}else {
|
||||||
return AjaxResult.error("今日未撞库");
|
remoteCustomerService.add(customer,SecurityConstants.INNER);
|
||||||
}
|
}
|
||||||
//匹配资质 造轮子 返回多个符合的商户
|
//匹配资质 造轮子 返回多个符合的商户
|
||||||
List<Merchant> merchants = matchMerchant(customer);
|
List<Merchant> merchants = matchMerchant(customer);
|
||||||
|
|
|
||||||
|
|
@ -152,8 +152,8 @@ public class CustomerController extends BaseController
|
||||||
* H5用户登录
|
* H5用户登录
|
||||||
*/
|
*/
|
||||||
@GetMapping("/customerLogin")
|
@GetMapping("/customerLogin")
|
||||||
public AjaxResult customerLogin(@RequestParam("phone")String phone,@RequestParam("code")Integer code){
|
public AjaxResult customerLogin(@RequestParam("phone")String phone,@RequestParam("code")Integer code,HttpServletRequest request){
|
||||||
return customerService.customerLogin(phone,code);
|
return customerService.customerLogin(phone,code,request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -90,9 +90,10 @@ public interface ICustomerService extends IService<Customer>
|
||||||
* h5用户登录
|
* h5用户登录
|
||||||
* @param phone
|
* @param phone
|
||||||
* @param code
|
* @param code
|
||||||
|
* @param request
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
AjaxResult customerLogin(String phone, Integer code);
|
AjaxResult customerLogin(String phone, Integer code,HttpServletRequest request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存用户留资信息
|
* 保存用户留资信息
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import com.ruoyi.common.core.utils.StringUtils;
|
||||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||||
import com.ruoyi.common.redis.service.RedisService;
|
import com.ruoyi.common.redis.service.RedisService;
|
||||||
import com.ruoyi.system.mapper.ChannelMapper;
|
import com.ruoyi.system.mapper.ChannelMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
|
@ -17,6 +18,8 @@ import com.ruoyi.common.core.domain.http.Channel;
|
||||||
import com.ruoyi.system.service.IChannelService;
|
import com.ruoyi.system.service.IChannelService;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 渠道配置Service业务层处理
|
* 渠道配置Service业务层处理
|
||||||
*
|
*
|
||||||
|
|
@ -24,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
* @date 2024-09-15
|
* @date 2024-09-15
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class ChannelServiceImpl implements IChannelService
|
public class ChannelServiceImpl implements IChannelService
|
||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
@ -31,6 +35,16 @@ public class ChannelServiceImpl implements IChannelService
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init(){
|
||||||
|
log.info("初始化渠道数据开始");
|
||||||
|
List<Channel> channels = channelMapper.selectList(new LambdaQueryWrapper<Channel>());
|
||||||
|
for (Channel channel:channels) {
|
||||||
|
redisService.setCacheObject(CacheConstants.CHANNEL_ID+channel.getId(),channel);
|
||||||
|
redisService.setCacheObject(CacheConstants.CHANNEL_SIGN+channel.getChannelSign(),channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询渠道配置
|
* 查询渠道配置
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,23 @@
|
||||||
package com.ruoyi.system.service.impl;
|
package com.ruoyi.system.service.impl;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdcardUtil;
|
||||||
|
import cn.hutool.crypto.digest.MD5;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.ruoyi.common.core.constant.CacheConstants;
|
||||||
import com.ruoyi.common.core.constant.RedisConstant;
|
import com.ruoyi.common.core.constant.RedisConstant;
|
||||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.common.core.domain.http.Merchant;
|
import com.ruoyi.common.core.domain.http.Channel;
|
||||||
import com.ruoyi.common.core.utils.DateUtils;
|
import com.ruoyi.common.core.utils.DateUtils;
|
||||||
import com.ruoyi.common.core.utils.EncryptUtil;
|
import com.ruoyi.common.core.utils.EncryptUtil;
|
||||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||||
import com.ruoyi.common.redis.service.CustomerTokenService;
|
import com.ruoyi.common.redis.service.CustomerTokenService;
|
||||||
import com.ruoyi.common.redis.service.RedisService;
|
import com.ruoyi.common.redis.service.RedisService;
|
||||||
|
import com.ruoyi.common.security.service.TokenService;
|
||||||
import com.ruoyi.system.config.SystemConfig;
|
import com.ruoyi.system.config.SystemConfig;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -43,6 +43,8 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
||||||
private final SystemConfig systemConfig;
|
private final SystemConfig systemConfig;
|
||||||
private final CustomerTokenService customerTokenService;
|
private final CustomerTokenService customerTokenService;
|
||||||
private final RedisService redisService;
|
private final RedisService redisService;
|
||||||
|
private final TokenService tokenService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询客户信息
|
* 查询客户信息
|
||||||
*
|
*
|
||||||
|
|
@ -154,7 +156,33 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
||||||
String token = customerTokenService.getToken(customer.getId());
|
String token = customerTokenService.getToken(customer.getId());
|
||||||
if (StringUtils.isEmpty(token)) {
|
if (StringUtils.isEmpty(token)) {
|
||||||
//生成一个长60的token
|
//生成一个长60的token
|
||||||
token = customerTokenService.generateToken(customer.getId(), customer.getPhone(), "ANDROID", customer.getChannelId());
|
//token = customerTokenService.generateToken(customer.getId(), customer.getPhone(), "ANDROID", customer.getChannelId());
|
||||||
|
token = tokenService.createTokenApp(customer.getId(),customer.getChannelId());
|
||||||
|
}
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册并返回token
|
||||||
|
* @param phone
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String registAndretrunToken(String phone,Long channelId){
|
||||||
|
Customer customer = new Customer();
|
||||||
|
customer.setChannelId(channelId);
|
||||||
|
customer.setPhone(EncryptUtil.AESencode(phone, systemConfig.getAESkey()));
|
||||||
|
customer.setPhoneMd5(MD5.create().digestHex(phone).toLowerCase(Locale.ROOT));
|
||||||
|
customer.setIsAuth(false);
|
||||||
|
customer.setFirstLoginTime(new Date());
|
||||||
|
customer.setLastLoginTime(new Date());
|
||||||
|
customer.setStatus(1);
|
||||||
|
customer.setCreateTime(new Date());
|
||||||
|
customerMapper.insert(customer);
|
||||||
|
String token = customerTokenService.getToken(customer.getId());
|
||||||
|
if (StringUtils.isEmpty(token)) {
|
||||||
|
//生成一个长60的token
|
||||||
|
//token = customerTokenService.generateToken(customer.getId(), customer.getPhone(), "ANDROID", customer.getChannelId());
|
||||||
|
token = tokenService.createTokenApp(customer.getId(),channelId);
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
@ -163,10 +191,16 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
||||||
* H5用户登陆
|
* H5用户登陆
|
||||||
* @param phone
|
* @param phone
|
||||||
* @param code
|
* @param code
|
||||||
|
* @param request
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AjaxResult customerLogin(String phone, Integer code) {
|
public AjaxResult customerLogin(String phone, Integer code, HttpServletRequest request) {
|
||||||
|
String sign = request.getHeader("sign");
|
||||||
|
if (StringUtils.isEmpty(sign)){
|
||||||
|
return AjaxResult.error("渠道标识不存在");
|
||||||
|
}
|
||||||
|
Channel channel = redisService.getCacheObject(CacheConstants.CHANNEL_SIGN+sign);
|
||||||
Boolean aBoolean = redisService.hasKey(RedisConstant.H5_LOGIN_CACHE + phone);
|
Boolean aBoolean = redisService.hasKey(RedisConstant.H5_LOGIN_CACHE + phone);
|
||||||
if (!aBoolean){
|
if (!aBoolean){
|
||||||
return AjaxResult.error("验证码不存在");
|
return AjaxResult.error("验证码不存在");
|
||||||
|
|
@ -175,7 +209,7 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
||||||
if (cacheCode!=code){
|
if (cacheCode!=code){
|
||||||
return AjaxResult.success("验证码错误");
|
return AjaxResult.success("验证码错误");
|
||||||
}
|
}
|
||||||
String customerToken = getCustomerToken(phone);
|
String customerToken = registAndretrunToken(phone,channel.getId());
|
||||||
|
|
||||||
return AjaxResult.success("登录成功",customerToken);
|
return AjaxResult.success("登录成功",customerToken);
|
||||||
}
|
}
|
||||||
|
|
@ -190,10 +224,32 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
||||||
public AjaxResult saveCustomerInfo(Customer customer, HttpServletRequest request) {
|
public AjaxResult saveCustomerInfo(Customer customer, HttpServletRequest request) {
|
||||||
String authorization = request.getHeader("Authorization");
|
String authorization = request.getHeader("Authorization");
|
||||||
Long customerId = customerTokenService.getCustomerId(authorization, false);
|
Long customerId = customerTokenService.getCustomerId(authorization, false);
|
||||||
|
String sign = request.getHeader("sign");
|
||||||
|
if (StringUtils.isEmpty(sign)){
|
||||||
|
return AjaxResult.error("渠道标识不存在");
|
||||||
|
}
|
||||||
|
Channel channel = redisService.getCacheObject(CacheConstants.CHANNEL_SIGN+sign);
|
||||||
if (customerId==null){
|
if (customerId==null){
|
||||||
return AjaxResult.error("用户不存在或未登录");
|
return AjaxResult.error("用户不存在或未登录");
|
||||||
}
|
}
|
||||||
|
if (StringUtils.isEmpty(customer.getIdCard())){
|
||||||
|
return AjaxResult.error("身份证好不能为空");
|
||||||
|
}
|
||||||
|
boolean validCard = IdcardUtil.isValidCard(customer.getIdCard());
|
||||||
|
if (validCard){
|
||||||
|
return AjaxResult.error("身份证号码异常");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(customer.getActurlName())){
|
||||||
|
return AjaxResult.error("姓名不能为空");
|
||||||
|
}
|
||||||
|
int ageByIdCard = IdcardUtil.getAgeByIdCard(customer.getIdCard());
|
||||||
|
customer.setAge(ageByIdCard);
|
||||||
|
int genderByIdCard = IdcardUtil.getGenderByIdCard(customer.getIdCard());
|
||||||
|
customer.setSex(genderByIdCard==0?1:0);
|
||||||
customer.setId(customerId);
|
customer.setId(customerId);
|
||||||
|
customer.setChannelId(channel.getId());
|
||||||
|
customer.setIsAuth(true);
|
||||||
|
customer.setStatus(1);
|
||||||
updateById(customer);
|
updateById(customer);
|
||||||
return AjaxResult.success("保存成功");
|
return AjaxResult.success("保存成功");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -167,14 +167,14 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
|
||||||
for (Merchant merchant:listR.getData()) {
|
for (Merchant merchant:listR.getData()) {
|
||||||
//限量判定
|
//限量判定
|
||||||
Integer sum = customerApplyLogService.getApplySum(merchant.getId());
|
Integer sum = customerApplyLogService.getApplySum(merchant.getId());
|
||||||
if (merchant.getLimitType()==1&&merchant.getLimitNum()<=sum){
|
if (merchant.getLimitType()!=null&&merchant.getLimitType()==1&&merchant.getLimitNum()<=sum){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customer.getAge()<merchant.getAgeLimitStart()||customer.getAge()>merchant.getAgeLimitEnd()){
|
if (merchant.getAgeLimitStart()!=null&&merchant.getAgeLimitEnd()!=null&&(customer.getAge()<merchant.getAgeLimitStart()||customer.getAge()>merchant.getAgeLimitEnd())){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (merchant.getChannelLimitType()==1||merchant.getChannelLimitType()==2){
|
if (merchant.getChannelLimitType()!=null&&(merchant.getChannelLimitType()==1||merchant.getChannelLimitType()==2)){
|
||||||
|
|
||||||
List<Long> list = Arrays.asList(merchant.getChannelLimit().split(",")).stream().map(val->Long.parseLong(val)).collect(Collectors.toList());
|
List<Long> list = Arrays.asList(merchant.getChannelLimit().split(",")).stream().map(val->Long.parseLong(val)).collect(Collectors.toList());
|
||||||
if (merchant.getChannelLimitType()==1&& !list.contains(customer.getChannelId())){
|
if (merchant.getChannelLimitType()==1&& !list.contains(customer.getChannelId())){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue