1、不同模块登录之后,租户ID的处理,2、新增绑定短信接口
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package com.starry.admin.modules.weichat.controller;
|
||||
|
||||
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.starry.admin.common.aspect.ClerkUserLogin;
|
||||
import com.starry.admin.common.conf.ThreadLocalRequestDetail;
|
||||
import com.starry.admin.common.exception.CustomException;
|
||||
import com.starry.admin.modules.clear.module.entity.PlayClerkUserInfoEntity;
|
||||
import com.starry.admin.modules.clear.service.impl.PlayClerkUserInfoServiceImpl;
|
||||
import com.starry.admin.modules.weichat.entity.PlayClerkUserAddVo;
|
||||
import com.starry.admin.modules.weichat.entity.PlayClerkUserBindCodeVo;
|
||||
import com.starry.admin.modules.weichat.entity.PlayClerkUserSendCodeVo;
|
||||
import com.starry.admin.utils.SecurityUtils;
|
||||
import com.starry.common.redis.RedisCache;
|
||||
import com.starry.common.result.R;
|
||||
import com.starry.common.utils.VerificationCodeUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/wx/clerk/")
|
||||
public class WxClerkController {
|
||||
|
||||
|
||||
@Resource
|
||||
RedisCache redisCache;
|
||||
|
||||
@Resource
|
||||
private PlayClerkUserInfoServiceImpl playClerkUserInfoService;
|
||||
|
||||
@ClerkUserLogin
|
||||
@PostMapping("/user/sendCode")
|
||||
public R sendCode(@VisibleForTesting @RequestBody PlayClerkUserSendCodeVo vo) {
|
||||
String codeKey = "login_codes:" + SecurityUtils.getTenantId() + "_" + SecureUtil.md5(vo.getAreaCode() + vo.getPhone());
|
||||
String code = VerificationCodeUtils.getVerificationCode(4);
|
||||
redisCache.setCacheObject(codeKey, code, 5L, TimeUnit.MINUTES);
|
||||
// 发送验证码,
|
||||
return R.ok(code);
|
||||
}
|
||||
|
||||
@ClerkUserLogin
|
||||
@PostMapping("/user/bindCode")
|
||||
public R bindCode(@VisibleForTesting @RequestBody PlayClerkUserBindCodeVo vo) {
|
||||
String codeKey = "login_codes:" + SecurityUtils.getTenantId() + "_" + SecureUtil.md5(vo.getAreaCode() + vo.getPhone());
|
||||
String code = redisCache.getCacheObject(codeKey);
|
||||
if (code == null || !code.equals(vo.getCode())) {
|
||||
throw new CustomException("验证码错误");
|
||||
}
|
||||
redisCache.deleteObject(codeKey);
|
||||
// 账号绑定操作
|
||||
return R.ok("成功");
|
||||
}
|
||||
|
||||
@ClerkUserLogin
|
||||
@PostMapping("/user/add")
|
||||
public R userAdd(@Valid @RequestBody PlayClerkUserAddVo vo) {
|
||||
PlayClerkUserInfoEntity entity = ThreadLocalRequestDetail.getClerkUserInfo();
|
||||
BeanUtils.copyProperties(vo, entity);
|
||||
entity.setPlayUserId("0001");
|
||||
playClerkUserInfoService.update(entity);
|
||||
return R.ok("申请成功");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.starry.admin.modules.weichat.controller;
|
||||
|
||||
import com.starry.admin.modules.system.service.ISysAdministrativeAreaDictInfoService;
|
||||
import com.starry.common.result.R;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author 杭州世平信息科技有限公司-xuhq
|
||||
* @since 2024/4/10 16:18
|
||||
**/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/wx/common/")
|
||||
public class WxCommonController {
|
||||
|
||||
@Resource
|
||||
private ISysAdministrativeAreaDictInfoService areaDictInfoService;
|
||||
|
||||
|
||||
@GetMapping("area/tree")
|
||||
public R list() {
|
||||
return R.ok(areaDictInfoService.selectTree("2"));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.starry.admin.modules.weichat.controller;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
@@ -14,6 +15,7 @@ import com.starry.admin.modules.weichat.entity.WxUserLoginVo;
|
||||
import com.starry.admin.modules.weichat.entity.WxUserQueryAddressVo;
|
||||
import com.starry.admin.modules.weichat.service.WxOauthService;
|
||||
import com.starry.admin.modules.weichat.service.WxTokenService;
|
||||
import com.starry.admin.utils.SecurityUtils;
|
||||
import com.starry.common.result.R;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
@@ -53,7 +55,7 @@ public class WxOauthController {
|
||||
private WxOauthService wxOauthService;
|
||||
|
||||
|
||||
@GetMapping("/getClerkLoginAddress")
|
||||
@PostMapping("/getClerkLoginAddress")
|
||||
public R getClerkLoginAddress(@RequestBody WxUserQueryAddressVo vo) {
|
||||
// 默认回调地址
|
||||
String defaultAddress = "http://july.hucs.top/api/wx/oauth2/clerkLoginCallback";
|
||||
@@ -70,19 +72,32 @@ public class WxOauthController {
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/clark/login")
|
||||
@PostMapping("/clark/login")
|
||||
public R clerkLogin(@Valid @RequestBody WxUserLoginVo vo) {
|
||||
String userId = wxOauthService.clarkUserLogin(vo.getCode());
|
||||
PlayClerkUserInfoEntity entity = clerkUserInfoService.selectPlayClerkUserInfoById(userId);
|
||||
PlayClerkUserInfoEntity entity = clerkUserInfoService.selectById(userId);
|
||||
// 线程塞入租户ID
|
||||
SecurityUtils.setTenantId(Convert.toStr(entity.getTenantId()));
|
||||
JSONObject jsonObject = JSONObject.from(entity);
|
||||
String tokenForMiniUser = tokenService.createMiniUserToken(entity.getId());
|
||||
String tokenForMiniUser = tokenService.createWxUserToken(entity.getId());
|
||||
jsonObject.put("tokenValue", TOKEN_PREFIX + tokenForMiniUser);
|
||||
jsonObject.put("tokenName", CLERK_USER_LOGIN_TOKEN);
|
||||
jsonObject.put("accountRole", "user");
|
||||
jsonObject.put("loginDate", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
return R.ok(jsonObject);
|
||||
}
|
||||
|
||||
@PostMapping("/clark/loginById")
|
||||
public R loginById(@Valid @RequestBody WxUserLoginVo vo) {
|
||||
PlayClerkUserInfoEntity entity = clerkUserInfoService.selectById(vo.getCode());
|
||||
JSONObject jsonObject = JSONObject.from(entity);
|
||||
String tokenValue = tokenService.createWxUserToken(entity.getId());
|
||||
jsonObject.put("tokenValue", tokenValue);
|
||||
jsonObject.put("tokenName", TOKEN_PREFIX + CLERK_USER_LOGIN_TOKEN);
|
||||
jsonObject.put("loginDate", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
clerkUserInfoService.updateTokenById(entity.getId(), tokenValue);
|
||||
return R.ok(jsonObject);
|
||||
}
|
||||
|
||||
@ClerkUserLogin
|
||||
@GetMapping("/clark/logout")
|
||||
public R clerkLogout() {
|
||||
@@ -91,7 +106,7 @@ public class WxOauthController {
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/getCustomLoginAddress")
|
||||
@PostMapping("/getCustomLoginAddress")
|
||||
public R getCustomLoginAddress(@RequestBody WxUserQueryAddressVo vo) {
|
||||
// 默认回调地址
|
||||
String defaultAddress = "http://july.hucs.top/api/wx/oauth2/customLoginCallback";
|
||||
@@ -108,23 +123,23 @@ public class WxOauthController {
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/custom/login")
|
||||
@PostMapping("/custom/login")
|
||||
public R customLogin(@Valid @RequestBody WxUserLoginVo vo) {
|
||||
String userId = wxOauthService.customUserLogin(vo.getCode());
|
||||
PlayCustomUserInfoEntity entity = customUserInfoService.selectPlayCustomUserInfoById(userId);
|
||||
PlayCustomUserInfoEntity entity = customUserInfoService.selectById(userId);
|
||||
JSONObject jsonObject = JSONObject.from(entity);
|
||||
String tokenForMiniUser = tokenService.createMiniUserToken(entity.getId());
|
||||
jsonObject.put("tokenValue", TOKEN_PREFIX + tokenForMiniUser);
|
||||
String tokenValue = tokenService.createWxUserToken(entity.getId());
|
||||
jsonObject.put("tokenValue", TOKEN_PREFIX + tokenValue);
|
||||
jsonObject.put("tokenName", CUSTOM_USER_LOGIN_TOKEN);
|
||||
jsonObject.put("accountRole", "user");
|
||||
jsonObject.put("loginDate", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
customUserInfoService.updateTokenById(entity.getId(), tokenValue);
|
||||
return R.ok(jsonObject);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/custom/logout")
|
||||
@CustomUserLogin
|
||||
public R customLogout(@Valid @RequestBody WxUserLoginVo vo) {
|
||||
public R customLogout() {
|
||||
wxOauthService.customUserLogout(ThreadLocalRequestDetail.getCustomUserInfo());
|
||||
return R.ok("登出成功");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.starry.admin.modules.weichat.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
*/
|
||||
@Data
|
||||
public class PlayClerkUserAddVo {
|
||||
|
||||
|
||||
/**
|
||||
* 店员昵称
|
||||
*/
|
||||
@NotBlank(message = "昵称不能为空")
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 店员等级
|
||||
*/
|
||||
@NotBlank(message = "等级不能为空")
|
||||
private String levelId;
|
||||
|
||||
/**
|
||||
* 店员性别(1:男:0:女)
|
||||
*/
|
||||
@NotNull(message = "性别不能为空")
|
||||
private Integer sex;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
@NotBlank(message = "头像不能为空")
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 音频
|
||||
*/
|
||||
@NotBlank(message = "音频不能为空")
|
||||
private String audioFrequency;
|
||||
|
||||
/**
|
||||
* 星座
|
||||
*/
|
||||
@NotBlank(message = "星座不能为空")
|
||||
private String constellation;
|
||||
|
||||
/**
|
||||
* 标签
|
||||
*/
|
||||
private String label;
|
||||
|
||||
/**
|
||||
* 个性签名
|
||||
*/
|
||||
@NotBlank(message = "签名不能为空")
|
||||
private String signature;
|
||||
|
||||
/**
|
||||
* 年龄
|
||||
*/
|
||||
@NotNull(message = "年龄不能为空")
|
||||
private Long age;
|
||||
|
||||
/**
|
||||
* 所在国家
|
||||
*/
|
||||
@NotBlank(message = "国家不能为空")
|
||||
private String country;
|
||||
|
||||
/**
|
||||
* 所在省份
|
||||
*/
|
||||
@NotBlank(message = "省份不能为空")
|
||||
private String province;
|
||||
|
||||
/**
|
||||
* 所在城市
|
||||
*/
|
||||
@NotBlank(message = "城市不能为空")
|
||||
private String city;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.starry.admin.modules.weichat.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
*/
|
||||
@Data
|
||||
public class PlayClerkUserBindCodeVo {
|
||||
|
||||
|
||||
/**
|
||||
* 手机号码区号
|
||||
*/
|
||||
@NotBlank(message = "手机号码区号不能为空")
|
||||
private String areaCode;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
@NotBlank(message = "手机号码不能为空")
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
@NotBlank(message = "验证码不能为空")
|
||||
private String code;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.starry.admin.modules.weichat.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
*/
|
||||
@Data
|
||||
public class PlayClerkUserSendCodeVo {
|
||||
|
||||
|
||||
/**
|
||||
* 手机号码区号
|
||||
*/
|
||||
@NotBlank(message = "手机号码区号不能为空")
|
||||
private String areaCode;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
@NotBlank(message = "手机号码不能为空")
|
||||
private String phone;
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.starry.admin.modules.weichat.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.starry.admin.modules.weichat.entity.PlayWxUserInfoEntity;
|
||||
|
||||
/**
|
||||
* 微信用户Mapper接口
|
||||
*
|
||||
* @author admin
|
||||
* @since 2024-04-07
|
||||
*/
|
||||
public interface PlayWxUserInfoMapper extends BaseMapper<PlayWxUserInfoEntity> {
|
||||
|
||||
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class Constants
|
||||
* 令牌前缀
|
||||
*/
|
||||
public static final String LOGIN_USER_KEY = "login_user_key";
|
||||
public static final String LOGIN_USER_KEY_MINI = "login_user_key_mini";
|
||||
public static final String LOGIN_USER_KEY_WX = "login_user_key_wx";
|
||||
public static final String LOGIN_USER_KEY_COSER = "login_user_key_coser";
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.starry.admin.modules.weichat.service;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.starry.admin.common.exception.CustomException;
|
||||
import com.starry.admin.common.exception.ServiceException;
|
||||
import com.starry.admin.modules.clear.module.entity.PlayClerkUserInfoEntity;
|
||||
import com.starry.admin.modules.clear.service.IPlayClerkUserInfoService;
|
||||
import com.starry.admin.modules.custom.module.entity.PlayCustomUserInfoEntity;
|
||||
@@ -72,8 +72,7 @@ public class WxOauthService {
|
||||
WxOAuth2AccessToken token = getWxOAuth2AccessToken(code);
|
||||
String openId = getOpenId(token);
|
||||
WxOAuth2UserInfo userInfo = getWxOAuth2UserInfo(token);
|
||||
PlayCustomUserInfoEntity entity = new PlayCustomUserInfoEntity();
|
||||
ConvertUtil.entityToVo(userInfo, PlayClerkUserInfoEntity.class);
|
||||
PlayCustomUserInfoEntity entity = ConvertUtil.entityToVo(userInfo, PlayCustomUserInfoEntity.class);
|
||||
entity.setAvatar(userInfo.getHeadImgUrl());
|
||||
PlayCustomUserInfoEntity item = customUserInfoService.selectByOpenid(openId);
|
||||
entity.setId(item != null ? item.getId() : IdUtil.fastSimpleUUID());
|
||||
@@ -92,7 +91,7 @@ public class WxOauthService {
|
||||
**/
|
||||
public WxOAuth2AccessToken getWxOAuth2AccessToken(String code) {
|
||||
if (StrUtil.isBlankIfStr(code)) {
|
||||
throw new CustomException("不能为空");
|
||||
throw new ServiceException("不能为空");
|
||||
}
|
||||
synchronized (code.intern()) {
|
||||
try {
|
||||
@@ -113,11 +112,11 @@ public class WxOauthService {
|
||||
**/
|
||||
public String getOpenId(WxOAuth2AccessToken token) {
|
||||
if (token == null) {
|
||||
throw new CustomException("获取微信授权异常,WxOAuth2AccessToken不能为空");
|
||||
throw new ServiceException("获取微信授权异常,WxOAuth2AccessToken不能为空");
|
||||
}
|
||||
String openId = token.getOpenId();
|
||||
if (StrUtil.isBlankIfStr(openId)) {
|
||||
throw new CustomException("获取微信授权异常,openId不能为空");
|
||||
throw new ServiceException("获取微信授权异常,openId不能为空");
|
||||
}
|
||||
return openId;
|
||||
}
|
||||
@@ -132,7 +131,7 @@ public class WxOauthService {
|
||||
**/
|
||||
public WxOAuth2UserInfo getWxOAuth2UserInfo(WxOAuth2AccessToken token) {
|
||||
if (token == null) {
|
||||
throw new CustomException("获取微信授权异常,WxOAuth2AccessToken不能为空");
|
||||
throw new ServiceException("获取微信授权异常,WxOAuth2AccessToken不能为空");
|
||||
}
|
||||
try {
|
||||
return wxMpService.getOAuth2Service().getUserInfo(token, null);
|
||||
|
||||
@@ -22,104 +22,95 @@ import java.util.Objects;
|
||||
@Slf4j
|
||||
@Service
|
||||
public class WxTokenService {
|
||||
// 令牌自定义标识
|
||||
/**
|
||||
* 令牌自定义标识
|
||||
*
|
||||
* @since 2024/4/10 11:20
|
||||
**/
|
||||
@Value("${token.header}")
|
||||
private String header;
|
||||
|
||||
// 令牌秘钥
|
||||
/**
|
||||
* 令牌秘钥
|
||||
*
|
||||
* @since 2024/4/10 11:20
|
||||
**/
|
||||
@Value("${token.secret}")
|
||||
private String secret;
|
||||
|
||||
// 令牌有效期(默认30分钟)
|
||||
/**
|
||||
* 令牌有效期(默认30分钟)
|
||||
*
|
||||
* @since 2024/4/10 11:20
|
||||
**/
|
||||
@Value("${token.expireTime}")
|
||||
private int expireTime;
|
||||
|
||||
protected static final long MILLIS_SECOND = 1000;
|
||||
|
||||
protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND;
|
||||
|
||||
private static final Long MILLIS_MINUTE_TEN = 20 * 60 * 1000L;
|
||||
//
|
||||
// @Autowired
|
||||
// private RedisCache redisCache;
|
||||
|
||||
// /**
|
||||
// * 获取用户身份信息
|
||||
// *
|
||||
// * @return 用户信息
|
||||
// */
|
||||
// public LoginUser getLoginUser(HttpServletRequest request) {
|
||||
// // 获取请求携带的令牌
|
||||
// String token = getToken(request);
|
||||
// if (StringUtils.isNotEmpty(token)) {
|
||||
// try {
|
||||
// Claims claims = parseToken(token);
|
||||
// // 解析对应的权限以及用户信息
|
||||
// String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
|
||||
// String userKey = getTokenKey(uuid);
|
||||
// LoginUser user = redisCache.getCacheObject(userKey);
|
||||
// return user;
|
||||
// } catch (Exception e) {
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 设置用户身份信息
|
||||
// */
|
||||
// public void setLoginUser(LoginUser loginUser) {
|
||||
// if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) {
|
||||
// refreshToken(loginUser);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 删除用户身份信息
|
||||
// */
|
||||
// public void delLoginUser(String token) {
|
||||
// if (StringUtils.isNotEmpty(token)) {
|
||||
// String userKey = getTokenKey(token);
|
||||
// redisCache.deleteObject(userKey);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 创建令牌
|
||||
// *
|
||||
// * @param loginUser 用户信息
|
||||
// * @return 令牌
|
||||
// */
|
||||
// public String createToken(LoginUser loginUser) {
|
||||
// String token = IdUtils.fastUUID();
|
||||
// loginUser.setToken(token);
|
||||
// setUserAgent(loginUser);
|
||||
// refreshToken(loginUser);
|
||||
//
|
||||
// Map<String, Object> claims = new HashMap<>();
|
||||
// claims.put(Constants.LOGIN_USER_KEY, token);
|
||||
// return createToken(claims);
|
||||
// }
|
||||
|
||||
// 小程序端-委托人
|
||||
public String createMiniUserToken(String miniUserId) {
|
||||
if (Objects.isNull(miniUserId)) {
|
||||
/**
|
||||
* 根据微信用户id创建token
|
||||
*
|
||||
* @param userId 微信用户ID
|
||||
* @return String token
|
||||
* @author 杭州世平信息科技有限公司-xuhq
|
||||
* @since 2024/4/10 11:21
|
||||
**/
|
||||
public String createWxUserToken(String userId) {
|
||||
if (Objects.isNull(userId)) {
|
||||
throw new RuntimeException("用户id不能为空");
|
||||
}
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
claims.put(Constants.LOGIN_USER_KEY_MINI, miniUserId);
|
||||
Map<String, Object> claims = new HashMap<>(16);
|
||||
claims.put(Constants.LOGIN_USER_KEY_WX, userId);
|
||||
return Jwts.builder().setClaims(claims).setExpiration(DateUtil.offsetMinute(new Date(), expireTime)).signWith(SignatureAlgorithm.HS512, secret).compact();
|
||||
}
|
||||
|
||||
// 小程序端-委托人
|
||||
public String getMiniUserIdByToken(String token) {
|
||||
|
||||
/**
|
||||
* 根据token获取微信用户ID
|
||||
*
|
||||
* @param token token
|
||||
* @return String 微信用户ID
|
||||
* @author 杭州世平信息科技有限公司-xuhq
|
||||
* @since 2024/4/10 11:24
|
||||
**/
|
||||
public String getWxUserIdByToken(String token) {
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
throw new RuntimeException("token不能为空");
|
||||
}
|
||||
Claims claims = parseToken(token);
|
||||
return claims.get(Constants.LOGIN_USER_KEY_MINI).toString();
|
||||
return claims.get(Constants.LOGIN_USER_KEY_WX).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据token获取微信用户TenantId
|
||||
*
|
||||
* @param token token
|
||||
* @param identity 用户身份(0:租户,1:顾客)
|
||||
* @return String 微信用户租户ID
|
||||
* @author 杭州世平信息科技有限公司-xuhq
|
||||
* @since 2024/4/10 11:24
|
||||
**/
|
||||
public String getWxUserTenantIdByToken(String token, String identity) {
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
throw new RuntimeException("token不能为空");
|
||||
}
|
||||
Claims claims = parseToken(token);
|
||||
return claims.get(Constants.LOGIN_USER_KEY_WX).toString();
|
||||
}
|
||||
|
||||
|
||||
// public String getTenantId(String token) {
|
||||
// if (StringUtils.isEmpty(token)) {
|
||||
// throw new RuntimeException("token不能为空");
|
||||
// }
|
||||
// Map<String, Object> claims = new HashMap<>();
|
||||
// claims.put(Constants.LOGIN_USER_KEY_MINI, miniUserId);
|
||||
// return Jwts.builder().setClaims(claims).setExpiration(DateUtil.offsetMinute(new Date(), expireTime)).signWith(SignatureAlgorithm.HS512, secret).compact();
|
||||
// }
|
||||
//
|
||||
// // 小程序端-coser
|
||||
// public String createMiniCoserToken(Long miniCoserId) {
|
||||
|
||||
Reference in New Issue
Block a user