提交修改
This commit is contained in:
parent
6c13b4ccac
commit
53e63c876d
@ -53,8 +53,7 @@ public class RedisUtils {
|
|||||||
/**
|
/**
|
||||||
* 默认过期时长,单位:秒
|
* 默认过期时长,单位:秒
|
||||||
*/
|
*/
|
||||||
public final static long DEFAULT_EXPIRE = 60 * 60 * 24;
|
public final static long DEFAULT_EXPIRE = 7 * 60 * 60 * 24;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认过期时长,单位:秒
|
* 默认过期时长,单位:秒
|
||||||
*/
|
*/
|
||||||
@ -64,9 +63,7 @@ public class RedisUtils {
|
|||||||
/**
|
/**
|
||||||
* 默认过期时长,单位:秒
|
* 默认过期时长,单位:秒
|
||||||
*/
|
*/
|
||||||
public final static long one_hours = 1* 60 * 60;
|
public final static long one_hours = 1 * 60 * 60;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不设置过期时长
|
* 不设置过期时长
|
||||||
|
|||||||
@ -15,7 +15,6 @@ public class VvActivityDTO{
|
|||||||
private Long buyerId;
|
private Long buyerId;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* 活动id
|
* 活动id
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import com.heyu.api.data.dao.vv.VvActivityDao;
|
|||||||
import com.heyu.api.data.dao.vv.VvPromoterCodeDao;
|
import com.heyu.api.data.dao.vv.VvPromoterCodeDao;
|
||||||
import com.heyu.api.data.entity.vv.VvActivityEntity;
|
import com.heyu.api.data.entity.vv.VvActivityEntity;
|
||||||
import com.heyu.api.data.entity.vv.VvPromoterCodeEntity;
|
import com.heyu.api.data.entity.vv.VvPromoterCodeEntity;
|
||||||
|
import com.heyu.api.data.utils.DateUtils;
|
||||||
import com.heyu.api.data.utils.R;
|
import com.heyu.api.data.utils.R;
|
||||||
import com.heyu.api.data.utils.RedisUtils;
|
import com.heyu.api.data.utils.RedisUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -19,6 +20,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/app")
|
@RequestMapping("/app")
|
||||||
@ -52,6 +55,10 @@ public class AppPromoterCodeParseController {
|
|||||||
log.info("vvActivityEntity is null");
|
log.info("vvActivityEntity is null");
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Date time = DateUtils.addMinutes(new Date(),30);
|
||||||
|
vvActivityDTO.setActivityExpiredTime(time.getTime());
|
||||||
|
|
||||||
redisUtils.set(ApiConstants.token_activity + request.getToken(), JSON.toJSONString(vvActivityDTO), RedisUtils.thirty_minute);
|
redisUtils.set(ApiConstants.token_activity + request.getToken(), JSON.toJSONString(vvActivityDTO), RedisUtils.thirty_minute);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSON;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.heyu.api.alibaba.request.mm.VvAnonymousUserLoginRequest;
|
import com.heyu.api.alibaba.request.mm.VvAnonymousUserLoginRequest;
|
||||||
import com.heyu.api.alibaba.request.mm.VvAppBuyerInfoRequest;
|
import com.heyu.api.alibaba.request.mm.VvAppBuyerInfoRequest;
|
||||||
import com.heyu.api.alibaba.request.mm.VvAppLoginRequest;
|
|
||||||
import com.heyu.api.alibaba.request.mm.order.VvActivityDTO;
|
import com.heyu.api.alibaba.request.mm.order.VvActivityDTO;
|
||||||
import com.heyu.api.alibaba.request.vv.AppUserLoginRequest;
|
import com.heyu.api.alibaba.request.vv.AppUserLoginRequest;
|
||||||
import com.heyu.api.common.annotation.Describe;
|
import com.heyu.api.common.annotation.Describe;
|
||||||
@ -19,8 +18,6 @@ import com.heyu.api.data.dto.WeiChatLoginDTO;
|
|||||||
import com.heyu.api.data.entity.vv.VvBuyerEntity;
|
import com.heyu.api.data.entity.vv.VvBuyerEntity;
|
||||||
import com.heyu.api.data.entity.vv.VvPromoterBuyerEntity;
|
import com.heyu.api.data.entity.vv.VvPromoterBuyerEntity;
|
||||||
import com.heyu.api.data.entity.vv.VvPromoterEntity;
|
import com.heyu.api.data.entity.vv.VvPromoterEntity;
|
||||||
import com.heyu.api.data.enums.UserLoginFlagEnums;
|
|
||||||
import com.heyu.api.data.service.impl.AppBaseRequest;
|
|
||||||
import com.heyu.api.data.utils.*;
|
import com.heyu.api.data.utils.*;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -28,9 +25,9 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@ -78,10 +75,12 @@ public class AppUserLoginController {
|
|||||||
target.setSessionKey(weiChatLoginDTO.getSessionKey());
|
target.setSessionKey(weiChatLoginDTO.getSessionKey());
|
||||||
vvBuyerDao.insertOrUpdateVvBuyer(target);
|
vvBuyerDao.insertOrUpdateVvBuyer(target);
|
||||||
// 默认24 小时
|
// 默认24 小时
|
||||||
BuyerDTO buyerDTO = buildBuyerLoginInfoCacheRedisDB(target, RedisUtils.DEFAULT_EXPIRE, null);
|
BuyerDTO buyerDTO = buildBuyerLoginInfoCacheRedisDB(target, RedisUtils.DEFAULT_EXPIRE, null,1);
|
||||||
|
insertPromoter(request.getToken(),buyerDTO);
|
||||||
return R.ok().put("buyer", buyerDTO);
|
return R.ok().put("buyer", buyerDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// http://localhost:8888/app/user/anonymous/login
|
// http://localhost:8888/app/user/anonymous/login
|
||||||
@RequestMapping("/anonymous/login")
|
@RequestMapping("/anonymous/login")
|
||||||
@Describe("匿名用户登录")
|
@Describe("匿名用户登录")
|
||||||
@ -92,42 +91,66 @@ public class AppUserLoginController {
|
|||||||
log.info("AnonymousUserLoginAesPassword anonymous value:{}", JSON.toJSONString(request));
|
log.info("AnonymousUserLoginAesPassword anonymous value:{}", JSON.toJSONString(request));
|
||||||
return R.error("设备号不对");
|
return R.error("设备号不对");
|
||||||
}
|
}
|
||||||
Random random = new Random(100000000L);
|
BuyerDTO buyerDTO = null;
|
||||||
VvBuyerEntity target = new VvBuyerEntity();
|
String activityInfoStr = redisUtils.get(request.getToken());
|
||||||
target.setIsTest(UserLoginFlagEnums.anonymous_user.getFlag());
|
if (StringUtils.isNotEmpty(activityInfoStr)) {
|
||||||
target.setId(random.nextLong());
|
buyerDTO = JSONObject.parseObject(activityInfoStr, BuyerDTO.class);
|
||||||
BuyerDTO buyerDTO = buildBuyerLoginInfoCacheRedisDB(target, RedisUtils.thirty_minute, request.getDeviceId());
|
// 真实用户登录
|
||||||
replaceActivityInfo(request, "/app/user/anonymous/login");
|
if(buyerDTO.getBuyerId() > 0 ){
|
||||||
|
VvBuyerEntity target = vvBuyerDao.selectVvBuyerById(buyerDTO.getBuyerId());
|
||||||
|
buyerDTO = buildBuyerLoginInfoCacheRedisDB(target, RedisUtils.DEFAULT_EXPIRE, null,1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 假登陆
|
||||||
|
if(buyerDTO == null){
|
||||||
|
VvBuyerEntity target = new VvBuyerEntity();
|
||||||
|
target.setId(0L);
|
||||||
|
target.setIsTest(0);
|
||||||
|
buyerDTO = buildBuyerLoginInfoCacheRedisDB(target, RedisUtils.thirty_minute, request.getDeviceId(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
insertPromoter(request.getToken(),buyerDTO);
|
||||||
return R.ok().put("buyer", buyerDTO);
|
return R.ok().put("buyer", buyerDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void insert(String token,Long wasBuyerId) {
|
public void insertPromoter(String requestToken ,BuyerDTO buyerDTO) {
|
||||||
|
String activityInfo = redisUtils.get(ApiConstants.token_activity + requestToken);
|
||||||
String activityInfo = redisUtils.get(ApiConstants.token_activity + token);
|
|
||||||
|
|
||||||
VvActivityDTO vvActivityDTO = null;
|
|
||||||
if (StringUtils.isNotEmpty(activityInfo)) {
|
if (StringUtils.isNotEmpty(activityInfo)) {
|
||||||
vvActivityDTO = JSONObject.parseObject(activityInfo, VvActivityDTO.class);
|
VvActivityDTO vvActivityDTO = JSONObject.parseObject(activityInfo, VvActivityDTO.class);
|
||||||
VvBuyerEntity wasBuyerEntity = vvBuyerDao.selectVvBuyerById(wasBuyerId);
|
VvBuyerEntity wasBuyerEntity = vvBuyerDao.selectVvBuyerById(buyerDTO.getBuyerId());
|
||||||
|
if(wasBuyerEntity ==null ){
|
||||||
|
wasBuyerEntity = new VvBuyerEntity();
|
||||||
|
wasBuyerEntity.setId(0L);
|
||||||
|
wasBuyerEntity.setBuyerName("");
|
||||||
|
wasBuyerEntity.setBuyerPhone("");
|
||||||
|
wasBuyerEntity.setBuyerWeixin("");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 换token
|
||||||
|
Date endTime = new Date(vvActivityDTO.getActivityExpiredTime());
|
||||||
|
int second = DateUtils.betweenSecond(new Date(),endTime);
|
||||||
|
redisUtils.set(ApiConstants.token_activity + buyerDTO.getToken(), JSON.toJSONString(vvActivityDTO),second);
|
||||||
|
|
||||||
|
|
||||||
List<Long> promoterBuyerIdList = new LinkedList<>();
|
List<Long> promoterBuyerIdList = new LinkedList<>();
|
||||||
promoterBuyerIdList.add(vvActivityDTO.getBuyerId());
|
promoterBuyerIdList.add(vvActivityDTO.getBuyerId());
|
||||||
|
|
||||||
List<VvBuyerEntity> promoterBuyerList = vvBuyerDao.selectVvBuyerByIdList(promoterBuyerIdList);
|
List<VvBuyerEntity> promoterBuyerList = vvBuyerDao.selectVvBuyerByIdList(promoterBuyerIdList);
|
||||||
VvPromoterEntity vvPromoter = new VvPromoterEntity();
|
VvPromoterEntity vvPromoter = new VvPromoterEntity();
|
||||||
vvPromoter.setActivityId(vvActivityDTO.getActivityId());
|
vvPromoter.setActivityId(vvActivityDTO.getActivityId());
|
||||||
|
vvPromoter.setPromoterCode(vvActivityDTO.getPromoterCode());
|
||||||
|
vvPromoter.setBuyerInfo(JSONObject.toJSONString(vvActivityDTO));
|
||||||
|
vvPromoterDao.insertVvPromoter(vvPromoter);
|
||||||
for (VvBuyerEntity promoterBuyerEntity : promoterBuyerList) {
|
for (VvBuyerEntity promoterBuyerEntity : promoterBuyerList) {
|
||||||
VvPromoterBuyerEntity vvPromoterBuyerEntity = new VvPromoterBuyerEntity();
|
VvPromoterBuyerEntity vvPromoterBuyerEntity = new VvPromoterBuyerEntity();
|
||||||
vvPromoterBuyerEntity.setPromoterId(null);
|
vvPromoterBuyerEntity.setPromoterId(vvPromoter.getId());
|
||||||
vvPromoterBuyerEntity.setPromoterBuyerId(promoterBuyerEntity.getId());
|
vvPromoterBuyerEntity.setPromoterBuyerId(promoterBuyerEntity.getId());
|
||||||
vvPromoterBuyerEntity.setPromoterBuyerName(promoterBuyerEntity.getBuyerName());
|
vvPromoterBuyerEntity.setPromoterBuyerName(promoterBuyerEntity.getBuyerName());
|
||||||
vvPromoterBuyerEntity.setPromoterBuyerPhone(promoterBuyerEntity.getBuyerPhone());
|
vvPromoterBuyerEntity.setPromoterBuyerPhone(promoterBuyerEntity.getBuyerPhone());
|
||||||
vvPromoterBuyerEntity.setPromoterBuyerWeixin(promoterBuyerEntity.getBuyerWeixin());
|
vvPromoterBuyerEntity.setPromoterBuyerWeixin(promoterBuyerEntity.getBuyerWeixin());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
vvPromoterBuyerEntity.setWasBuyerId(wasBuyerEntity.getId());
|
vvPromoterBuyerEntity.setWasBuyerId(wasBuyerEntity.getId());
|
||||||
vvPromoterBuyerEntity.setWasBuyerName(wasBuyerEntity.getBuyerName());
|
vvPromoterBuyerEntity.setWasBuyerName(wasBuyerEntity.getBuyerName());
|
||||||
vvPromoterBuyerEntity.setWasBuyerPhone(wasBuyerEntity.getBuyerPhone());
|
vvPromoterBuyerEntity.setWasBuyerPhone(wasBuyerEntity.getBuyerPhone());
|
||||||
@ -135,32 +158,8 @@ public class AppUserLoginController {
|
|||||||
vvPromoterBuyerDao.insertOrUpdateVvPromoterBuyer(vvPromoterBuyerEntity);
|
vvPromoterBuyerDao.insertOrUpdateVvPromoterBuyer(vvPromoterBuyerEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// http://localhost:8888/app/user/target/login
|
|
||||||
@RequestMapping("/target/login")
|
|
||||||
@Describe("目标用户登录")
|
|
||||||
public R targetLogin(@RequestBody VvAppLoginRequest request) {
|
|
||||||
VvBuyerEntity vvBuyerEntity = vvBuyerDao.selectVvBuyerIsTestById(request.getBuyerId(), 1);
|
|
||||||
if (vvBuyerEntity == null) {
|
|
||||||
return R.error("你不是内部用户");
|
|
||||||
}
|
|
||||||
|
|
||||||
VvBuyerEntity target = vvBuyerDao.selectVvBuyerInfo(
|
|
||||||
request.getTargetBuyer(),
|
|
||||||
request.getTargetBuyer(),
|
|
||||||
request.getTargetBuyer());
|
|
||||||
|
|
||||||
// 默认24 小时
|
|
||||||
BuyerDTO buyerDTO = buildBuyerLoginInfoCacheRedisDB(target, RedisUtils.DEFAULT_EXPIRE, null);
|
|
||||||
replaceActivityInfo(request, "/app/user/target/login");
|
|
||||||
return R.ok().put("buyer", buyerDTO);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// http://localhost:8888/app/buyer/info/update
|
// http://localhost:8888/app/buyer/info/update
|
||||||
@RequestMapping("/buyer/info/update")
|
@RequestMapping("/buyer/info/update")
|
||||||
@Describe("目标用户登录")
|
@Describe("目标用户登录")
|
||||||
@ -176,28 +175,15 @@ public class AppUserLoginController {
|
|||||||
return R.ok().put("buyer", vvBuyerEntity);
|
return R.ok().put("buyer", vvBuyerEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BuyerDTO buildBuyerLoginInfoCacheRedisDB(VvBuyerEntity target, Long expireTime, String deviceId,Integer loginType) {
|
||||||
public void replaceActivityInfo(AppBaseRequest request, String uri) {
|
|
||||||
String activityTokenInfo = redisUtils.get(ApiConstants.token_activity + request.getToken());
|
|
||||||
if (StringUtils.isNotEmpty(activityTokenInfo)) {
|
|
||||||
log.info("AppUserLoginController replaceActivityInfo uri :{}, activityTokenInfo:{}", uri, activityTokenInfo);
|
|
||||||
VvActivityDTO vvActivityDTO = JSONObject.parseObject(activityTokenInfo, VvActivityDTO.class);
|
|
||||||
Long activityExpiredTime = (vvActivityDTO.getActivityExpiredTime() - System.currentTimeMillis()) / 1000;
|
|
||||||
if (activityExpiredTime > 0) {
|
|
||||||
redisUtils.set(ApiConstants.token_activity + request.getToken(), JSON.toJSONString(vvActivityDTO), activityExpiredTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BuyerDTO buildBuyerLoginInfoCacheRedisDB(VvBuyerEntity target, Long expireTime, String deviceId) {
|
|
||||||
BuyerDTO buyerDTO = new BuyerDTO();
|
BuyerDTO buyerDTO = new BuyerDTO();
|
||||||
buyerDTO.setBuyerId(target.getId());
|
buyerDTO.setBuyerId(target.getId());
|
||||||
buyerDTO.setBuyerName(target.getBuyerName());
|
buyerDTO.setBuyerName(target.getBuyerName());
|
||||||
buyerDTO.setIsTest(target.getIsTest());
|
buyerDTO.setIsTest(target.getIsTest());
|
||||||
buyerDTO.setAvatar(target.getAvatar());
|
buyerDTO.setAvatar(target.getAvatar());
|
||||||
|
buyerDTO.setLoginType(loginType);
|
||||||
buyerDTO.setBuyerPhone(target.getBuyerPhone());
|
buyerDTO.setBuyerPhone(target.getBuyerPhone());
|
||||||
buyerDTO.setBuyerWeixin(target.getBuyerWeixin());
|
buyerDTO.setBuyerWeixin(target.getBuyerWeixin());
|
||||||
|
|
||||||
String token = TokenUtils.generateToken(target.getId() + deviceId);
|
String token = TokenUtils.generateToken(target.getId() + deviceId);
|
||||||
redisUtils.set(token, JSON.toJSONString(buyerDTO), expireTime);
|
redisUtils.set(token, JSON.toJSONString(buyerDTO), expireTime);
|
||||||
buyerDTO.setToken(token);
|
buyerDTO.setToken(token);
|
||||||
@ -205,21 +191,6 @@ public class AppUserLoginController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("/getPhoneNumber")
|
|
||||||
public Object getPhoneNumber(@RequestBody VvAppLoginRequest request) {
|
|
||||||
|
|
||||||
// String sessionKey = userRepository.findByOpenId(request.getOpenId()).getSessionKey(); // 从数据库中获取 sessionKey
|
|
||||||
|
|
||||||
|
|
||||||
// JSONObject phoneInfo = JSONObject.parseObject(WxMaCryptUtils.decrypt(sessionKey, request.getEncryptedData(), request.getIv())); // 解密获取手机号信息
|
|
||||||
// String phoneNumber = phoneInfo.getString("phoneNumber");
|
|
||||||
// 更新用户信息并存储到数据库
|
|
||||||
|
|
||||||
// 返回给前端的手机号信息
|
|
||||||
JSONObject result = new JSONObject();
|
|
||||||
result.put("phoneNumber", null);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user