合并微信小程序和支付宝小程序登录入口

This commit is contained in:
谭凯凯
2024-09-24 09:53:14 +08:00
committed by Tankaikai
parent 05efa142e9
commit 3ee4ea9870
5 changed files with 148 additions and 92 deletions

View File

@@ -1,14 +1,14 @@
package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.entity.TbShopOpenId;
import com.chaozhanggui.system.cashierservice.entity.TbShopUser;
import com.chaozhanggui.system.cashierservice.entity.TbUserInfo;
import com.chaozhanggui.system.cashierservice.entity.TbUserShopMsg;
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
@@ -141,34 +141,72 @@ public class LoginService {
}
private void buildNewUserInfo(TbUserInfo userInfo) {
userInfo = new TbUserInfo();
userInfo.setAmount(BigDecimal.ZERO);
userInfo.setChargeAmount(BigDecimal.ZERO);
userInfo.setLineOfCredit(BigDecimal.ZERO);
userInfo.setConsumeNumber(0);
userInfo.setConsumeAmount(BigDecimal.ZERO);
userInfo.setTotalScore(0);
userInfo.setLockScore(0);
userInfo.setHeadImg("");
userInfo.setNickName("");
userInfo.setTelephone("");
userInfo.setStatus(Byte.parseByte("1"));
userInfo.setParentType("PERSON");
userInfo.setIsResource(Byte.parseByte("0"));
userInfo.setIsOnline(Byte.parseByte("0"));
userInfo.setIsVip(Byte.parseByte("0"));
userInfo.setIsAttentionMp(Byte.parseByte("0"));
userInfo.setIsPwd("0");
userInfo.setPwd(MD5Utils.md5("123456"));
userInfo.setCreatedAt(System.currentTimeMillis());
userInfo.setLastLogInAt(System.currentTimeMillis());
userInfo.setUpdatedAt(System.currentTimeMillis());
}
public Result wxCustomLogin(String openId, String headImage, String nickName, String telephone, String ip) {
TbUserInfo userInfo = tbUserInfoMapper.selectByOpenId(openId);
if (ObjectUtil.isNull(userInfo)) {
userInfo = new TbUserInfo();
userInfo.setAmount(BigDecimal.ZERO);
userInfo.setChargeAmount(BigDecimal.ZERO);
userInfo.setLineOfCredit(BigDecimal.ZERO);
userInfo.setConsumeNumber(0);
userInfo.setConsumeAmount(BigDecimal.ZERO);
userInfo.setTotalScore(0);
userInfo.setLockScore(0);
buildNewUserInfo(userInfo);
userInfo.setHeadImg(ObjectUtil.isNotNull(headImage) ? headImage : "");
userInfo.setNickName(ObjectUtil.isNotNull(nickName) ? nickName : "微信用户");
userInfo.setTelephone(ObjectUtil.isNotNull(telephone) ? telephone : "");
userInfo.setMiniAppOpenId(openId);
userInfo.setStatus(Byte.parseByte("1"));
userInfo.setParentType("PERSON");
userInfo.setIsResource(Byte.parseByte("0"));
userInfo.setIsOnline(Byte.parseByte("0"));
userInfo.setIsVip(Byte.parseByte("0"));
userInfo.setSourcePath("WECHAT-APP");
userInfo.setIsAttentionMp(Byte.parseByte("0"));
userInfo.setSearchWord("||微信用户");
userInfo.setIsPwd("0");
userInfo.setPwd(MD5Utils.md5("123456"));
userInfo.setCreatedAt(System.currentTimeMillis());
userInfo.setLastLogInAt(System.currentTimeMillis());
userInfo.setMiniAppOpenId(openId);
tbUserInfoMapper.insert(userInfo);
} else {
userInfo.setUpdatedAt(System.currentTimeMillis());
userInfo.setLastLogInAt(System.currentTimeMillis());
tbUserInfoMapper.updateByPrimaryKeySelective(userInfo);
}
//生成token 信息
String token = TokenUtil.generateToken(userInfo.getId(), userInfo.getMiniAppOpenId(), userInfo.getTelephone(), userInfo.getNickName());
Map<String, Object> map = new HashMap<>();
map.put("token", token);
map.put("userInfo", userInfo);
redisUtil.saveMessage(RedisCst.ONLINE_USER.concat(openId), JSON.toJSONString(map), 60 * 60 * 24 * 30L);
log.info("登录传参 结果:" + JSONUtil.toJSONString(map));
return Result.success(CodeEnum.SUCCESS, map);
}
/**
* 支付宝用户登录
* @param openId
* @return
*/
public Result alipayCustomLogin(String openId) {
TbUserInfo userInfo = tbUserInfoMapper.selectByOpenId(openId);
if (ObjectUtil.isNull(userInfo)) {
userInfo = new TbUserInfo();
buildNewUserInfo(userInfo);
userInfo.setNickName("支付宝用户");
userInfo.setSourcePath("ALIPAY-APP");
userInfo.setSearchWord("||支付宝用户");
userInfo.setMiniAppOpenId(openId);
tbUserInfoMapper.insert(userInfo);
} else {
userInfo.setUpdatedAt(System.currentTimeMillis());