提交 626cb4a0 authored 作者: 李秋林's avatar 李秋林

小程序完成功能:注册、登录、获取手机验证码

上级 7a191ff3
...@@ -38,13 +38,6 @@ public class ControllerLogAspect { ...@@ -38,13 +38,6 @@ public class ControllerLogAspect {
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = sra.getRequest(); HttpServletRequest request = sra.getRequest();
/**
* 暂时使用这个判断是否登录
*/
String accessToken = request.getHeader("access_token");
// Signature signature = joinPoint.getSignature(); // Signature signature = joinPoint.getSignature();
// String name = signature.getName(); // String name = signature.getName();
......
...@@ -47,7 +47,9 @@ public class WeChatUserCoreController { ...@@ -47,7 +47,9 @@ public class WeChatUserCoreController {
throw new ParamException(RCode.ENROLL_PARAM_ERROR, null); throw new ParamException(RCode.ENROLL_PARAM_ERROR, null);
} }
// 手机号-验证码 校验 /**
* 手机号-验证码 校验
*/
String redisKey = RedisKeys.UserKeys.PHONE_VER_CODE.getKey() + wxTemporaryEnrollVo.getPhone(); String redisKey = RedisKeys.UserKeys.PHONE_VER_CODE.getKey() + wxTemporaryEnrollVo.getPhone();
String phoneCodeOld = redisCache.get(redisKey); String phoneCodeOld = redisCache.get(redisKey);
if (StringUtils.isBlank(phoneCodeOld) || !phoneCodeOld.equals(wxTemporaryEnrollVo.getPhoneCode())){ if (StringUtils.isBlank(phoneCodeOld) || !phoneCodeOld.equals(wxTemporaryEnrollVo.getPhoneCode())){
......
...@@ -31,25 +31,19 @@ public class WeChatUserQueryController { ...@@ -31,25 +31,19 @@ public class WeChatUserQueryController {
* @return 非null则登录成功 * @return 非null则登录成功
*/ */
@PostMapping("/temporary/login/phone_openid") @PostMapping("/temporary/login/phone_openid")
public WxTemporaryInfoDto temporaryLoginByPhoneAndOpenId(@RequestBody WxTemporaryLoginVo wxTemporaryLoginVo) { public boolean temporaryLoginByPhoneAndOpenId(@RequestBody WxTemporaryLoginVo wxTemporaryLoginVo) {
if (!DataUtils.phonePattern(wxTemporaryLoginVo.getPhone())) { if (!DataUtils.phonePattern(wxTemporaryLoginVo.getPhone())) {
throw new ParamException(RCode.PHONE_PARAM_ERROR, null); throw new ParamException(RCode.PHONE_PARAM_ERROR, null);
} }
WxTemporaryInfoDto wxTemDto = weChatUserQueryService.loginTemporaryByOpenIdAndPhone(wxTemporaryLoginVo.getOpenId(), wxTemporaryLoginVo.getPhone()); return weChatUserQueryService.loginTemporaryByOpenIdAndPhone(wxTemporaryLoginVo.getOpenId(), wxTemporaryLoginVo.getPhone());
if (Objects.isNull(wxTemDto)){
throw new ParamException(RCode.LOGIN_USER_IS_NULL_ERROR, null);
}
return wxTemDto;
} }
/** /**
* 需要改成:根据token查询人员详情 * 促销员信息查询
* 促销员查询
*/ */
@GetMapping("/temporary/openId") @GetMapping("/temporary/phone_openid")
public WxTemporaryInfoDto getTemporaryInfoByOpenId(String openId) { public WxTemporaryInfoDto getTemporaryInfoByOpenId(@RequestBody WxTemporaryLoginVo wxTemporaryLoginVo) {
return weChatUserQueryService.getTemporaryByToken(wxTemporaryLoginVo.getOpenId(),wxTemporaryLoginVo.getPhone());
return weChatUserQueryService.getTemporaryByToken(openId);
} }
} }
...@@ -76,9 +76,4 @@ public class WxTemporaryInfoDto { ...@@ -76,9 +76,4 @@ public class WxTemporaryInfoDto {
* 详细地址 * 详细地址
*/ */
String address; String address;
/**
* 登录token
*/
String token;
} }
...@@ -9,7 +9,9 @@ import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto; ...@@ -9,7 +9,9 @@ import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto;
*/ */
public interface WeChatUserQueryService { public interface WeChatUserQueryService {
WxTemporaryInfoDto loginTemporaryByOpenIdAndPhone(String openId,String phone); boolean loginTemporaryByOpenIdAndPhone(String openId,String phone);
WxTemporaryInfoDto getTemporaryByToken(String openId); WxTemporaryInfoDto getTemporaryByToken(String openId);
WxTemporaryInfoDto getTemporaryByToken(String openId,String phone);
} }
package com.wangxiaolu.promotion.service.wechat.impl; package com.wangxiaolu.promotion.service.wechat.impl;
import com.alibaba.fastjson.JSONObject;
import com.wangxiaolu.promotion.common.redis.RedisKeys; import com.wangxiaolu.promotion.common.redis.RedisKeys;
import com.wangxiaolu.promotion.common.redis.service.RedisCache; import com.wangxiaolu.promotion.common.redis.service.RedisCache;
import com.wangxiaolu.promotion.domain.user.dao.TemporaryInfoDao; import com.wangxiaolu.promotion.domain.user.dao.TemporaryInfoDao;
...@@ -35,22 +36,18 @@ public class WeChatUserQueryServiceImpl implements WeChatUserQueryService { ...@@ -35,22 +36,18 @@ public class WeChatUserQueryServiceImpl implements WeChatUserQueryService {
* 根据openId、手机号登录 * 根据openId、手机号登录
*/ */
@Override @Override
public WxTemporaryInfoDto loginTemporaryByOpenIdAndPhone(String openId, String phone) { public boolean loginTemporaryByOpenIdAndPhone(String openId, String phone) {
WxTemporaryInfoDto temDto = temporaryInfoDao.getUnimportantData(openId, phone); WxTemporaryInfoDto temDto = temporaryInfoDao.getUnimportantData(openId, phone);
boolean exist = !Objects.isNull(temDto);
if (Objects.isNull(temDto)) { if (exist) {
log.info("微信-促销员{}登录成功(openId、手机号),openId:{},phone:{}", temDto.getName(), openId, phone);
log.info(JSONObject.toJSONString(temDto));
} else {
log.info("微信-促销员登录失败,当前信息未注册(openId、手机号),openId:{},phone:{}", openId, phone); log.info("微信-促销员登录失败,当前信息未注册(openId、手机号),openId:{},phone:{}", openId, phone);
return null;
} }
// 生成登录token return exist;
String temToken = jwtUtils.getTemporaryToken(openId, phone);
temDto.setToken(temToken);
String key = RedisKeys.UserKeys.TEMPORARY_TOKEN.getKey();
redisCache.addToJsonToDays(key + temToken, temDto, 3);
log.info("微信-促销员{}登录成功(openId、手机号),openId:{},phone:{}\n生成登录token:{}", temDto.getName(), openId, phone, temToken);
return temDto;
} }
/** /**
...@@ -70,4 +67,9 @@ public class WeChatUserQueryServiceImpl implements WeChatUserQueryService { ...@@ -70,4 +67,9 @@ public class WeChatUserQueryServiceImpl implements WeChatUserQueryService {
return temporaryInfoDto; return temporaryInfoDto;
} }
@Override
public WxTemporaryInfoDto getTemporaryByToken(String openId, String phone) {
return null;
}
} }
...@@ -25,7 +25,7 @@ class WeChatUserQueryControllerTest { ...@@ -25,7 +25,7 @@ class WeChatUserQueryControllerTest {
@Test @Test
void temporaryLoginByPhoneAndOpenId() { void temporaryLoginByPhoneAndOpenId() {
WxTemporaryLoginVo loginVO = new WxTemporaryLoginVo().setOpenId("oCMt-66hnlY9-bQcZAAZKX0p3s6I").setPhone("15701654502"); WxTemporaryLoginVo loginVO = new WxTemporaryLoginVo().setOpenId("oCMt-66hnlY9-bQcZAAZKX0p3s6I").setPhone("15701654502");
WxTemporaryInfoDto b = weChatUserQueryController.temporaryLoginByPhoneAndOpenId(loginVO); boolean b = weChatUserQueryController.temporaryLoginByPhoneAndOpenId(loginVO);
System.out.println("temporaryLoginByPhoneAndOpenId 登录结果:" + b); System.out.println("temporaryLoginByPhoneAndOpenId 登录结果:" + b);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论