Merge branch 'cc_20250918_cp_token' into 'master'
fix:菜品市场免登短期token接口;短期token换用户信息接口 See merge request hangzhou/java/custom_zxjp!168
This commit is contained in:
@@ -26,6 +26,11 @@ public class CommonConstants {
|
||||
|
||||
public static final int NORMAL_LOCK_TIMES = 60 * 1000;
|
||||
|
||||
/**
|
||||
* 短期token过期时间,单位秒
|
||||
*/
|
||||
public static final int SHORT_TERM_TOKEN_EXPIRE = 60 * 5;
|
||||
|
||||
public static final int AN_HOUR_SECONDS = 3600;
|
||||
//十秒
|
||||
public static final int TEN_SECONDS = 10000;
|
||||
@@ -55,6 +60,11 @@ public class CommonConstants {
|
||||
|
||||
public static final String ZXJP_MINI_PROGRAM_LOGIN_FLAG = "zxjp_mini_program_login_flag:{0}";
|
||||
|
||||
/**
|
||||
* 小程序短期token key
|
||||
*/
|
||||
public static final String ZXJP_MIN_PROGRAM_SHORT_TERM_LOGIN_FLAG = "zxjp_mini_program_short_term_login_flag:{0}";
|
||||
|
||||
public static final String ROOT_DEPT_ID_STR = "1";
|
||||
|
||||
public static final Integer DEAL_RECORD_MAX_SIZE = 1000;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.cool.store.dto.wx;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 小程序免登DTO
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/9/18
|
||||
*/
|
||||
@Data
|
||||
public class MiniProgramFreeLoginDTO {
|
||||
@ApiModelProperty("手机号")
|
||||
@NotBlank(message = "手机号不能为空")
|
||||
private String mobile;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
import com.cool.store.dto.wx.MiniAppUrlLinkReqDTO;
|
||||
import com.cool.store.dto.wx.MiniProgramFreeLoginDTO;
|
||||
import com.cool.store.dto.wx.MiniProgramLoginDTO;
|
||||
import com.cool.store.request.MobileUpdateRequest;
|
||||
import com.cool.store.vo.PartnerUserInfoVO;
|
||||
@@ -28,4 +29,18 @@ public interface WechatMiniAppService {
|
||||
String getMiniAppUrl();
|
||||
|
||||
String getMiniAppUrlLink(MiniAppUrlLinkReqDTO miniAppUrlLinkReqDTO);
|
||||
|
||||
/**
|
||||
* 通过手机号获取短期token
|
||||
* @param param 小程序免登DTO
|
||||
* @return Token
|
||||
*/
|
||||
String getShortTermTokenByMobile(MiniProgramFreeLoginDTO param);
|
||||
|
||||
/**
|
||||
* 通过短期token获取用户信息
|
||||
* @param token 短期token
|
||||
* @return 用户信息VO
|
||||
*/
|
||||
PartnerUserInfoVO getUserInfoByShortTermToken(String token);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.cool.store.utils.UUIDUtils;
|
||||
import com.cool.store.vo.PartnerUserInfoVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -252,4 +253,30 @@ public class WechatMiniAppServiceImpl implements WechatMiniAppService {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getShortTermTokenByMobile(MiniProgramFreeLoginDTO param) {
|
||||
HyPartnerUserInfoDO hyPartnerUserInfoDO = hyPartnerUserInfoDAO.selectByMobile(param.getMobile());
|
||||
if (Objects.isNull(hyPartnerUserInfoDO)) {
|
||||
return "";
|
||||
}
|
||||
PartnerUserInfoVO userInfoVO = BeanUtil.toBean(hyPartnerUserInfoDO, PartnerUserInfoVO.class);
|
||||
fillLineInfo(userInfoVO, hyPartnerUserInfoDO.getPartnerId());
|
||||
String token = new SecureRandomNumberGenerator().nextBytes().toHex();
|
||||
String key = MessageFormat.format(CommonConstants.ZXJP_MIN_PROGRAM_SHORT_TERM_LOGIN_FLAG, token);
|
||||
redisUtilPool.setString(key, JSONObject.toJSONString(userInfoVO), CommonConstants.SHORT_TERM_TOKEN_EXPIRE);
|
||||
return token;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartnerUserInfoVO getUserInfoByShortTermToken(String token) {
|
||||
String key = MessageFormat.format(CommonConstants.ZXJP_MIN_PROGRAM_SHORT_TERM_LOGIN_FLAG, token);
|
||||
String userStr = redisUtilPool.getString(key);
|
||||
if (StringUtils.isNotBlank(userStr)) {
|
||||
PartnerUserInfoVO userInfoVO = JSONObject.parseObject(userStr, PartnerUserInfoVO.class);
|
||||
redisUtilPool.delKey(key);
|
||||
return userInfoVO;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -59,7 +59,8 @@ public class SignValidateFilter implements Filter {
|
||||
"/zxjp/mini/program/v1/partnerManage/openArea/areaApplyQuery",
|
||||
"/zxjp/**/api/audit/result",
|
||||
"/zxjp/**/api/license",
|
||||
"/zxjp/mini/line/getRegionPayPic"
|
||||
"/zxjp/mini/line/getRegionPayPic",
|
||||
"/zxjp/mini/miniProgram/getUserInfoByToken"
|
||||
|
||||
);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.context.PartnerUserHolder;
|
||||
import com.cool.store.dto.*;
|
||||
import com.cool.store.dto.store.StoreUserPositionDTO;
|
||||
import com.cool.store.dto.wx.MiniProgramFreeLoginDTO;
|
||||
import com.cool.store.request.OpenApiStoreRequest;
|
||||
import com.cool.store.request.StoreCodeDTO;
|
||||
import com.cool.store.request.*;
|
||||
@@ -49,6 +50,8 @@ public class OpenApiController {
|
||||
StoreService storeService;
|
||||
@Resource
|
||||
MessageTemplateService messageTemplateService;
|
||||
@Resource
|
||||
WechatMiniAppService wechatMiniAppService;
|
||||
|
||||
@PostMapping("/statusRefresh")
|
||||
public ApiResponse<Boolean> statusRefresh(@RequestBody StatusRefreshDTO statusRefreshDTO){
|
||||
@@ -176,4 +179,10 @@ public class OpenApiController {
|
||||
public ApiResponse<Boolean> handleMessage(@RequestBody @Validated ThirdHandleMessageRequest request) {
|
||||
return messageTemplateService.thirdHandleMessage(request);
|
||||
}
|
||||
|
||||
@ApiOperation("根据手机号获取短期token")
|
||||
@PostMapping("/getShortTermToken")
|
||||
public ApiResponse<String> getTokenByMobile(@RequestBody @Validated MiniProgramFreeLoginDTO param) {
|
||||
return ApiResponse.success(wechatMiniAppService.getShortTermTokenByMobile(param));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.cool.store.response.ResponseResult;
|
||||
import com.cool.store.service.WechatMiniAppService;
|
||||
import com.cool.store.vo.PartnerUserInfoVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -65,4 +66,11 @@ public class MiniProgramAppController {
|
||||
PartnerUserInfoVO userInfoVO = PartnerUserHolder.getUser();
|
||||
return ResponseResult.success(userInfoVO);
|
||||
}
|
||||
|
||||
@ApiOperation("根据短期token获取用户信息")
|
||||
@ApiImplicitParam(name = "token", value = "短期token", required = true, dataType = "String", paramType = "query")
|
||||
@GetMapping("/getUserInfoByToken")
|
||||
public ResponseResult<PartnerUserInfoVO> getUserInfoByToken(String token) {
|
||||
return ResponseResult.success(wechatMiniAppService.getUserInfoByShortTermToken(token));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user