提交 fb800cfd authored 作者: lql-win's avatar lql-win

手机号校验

上级 63055f3e
package com.wangxiaolu.promotion.controller.wechat; package com.wangxiaolu.promotion.controller.wechat;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.wangxiaolu.promotion.exception.ParamException;
import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto; import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto;
import com.wangxiaolu.promotion.pojo.user.vo.WxJsUserInfoVo; import com.wangxiaolu.promotion.pojo.user.vo.WxJsUserInfoVo;
import com.wangxiaolu.promotion.result.basedata.RCode;
import com.wangxiaolu.promotion.service.wechat.WeChatUserCoreService; import com.wangxiaolu.promotion.service.wechat.WeChatUserCoreService;
import com.wangxiaolu.promotion.utils.UserUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -13,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -13,6 +16,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.Objects;
/** /**
* @author : liqiulin * @author : liqiulin
* @date : 2024-04-03 17 * @date : 2024-04-03 17
...@@ -31,6 +36,15 @@ public class WeChatUserCoreController { ...@@ -31,6 +36,15 @@ public class WeChatUserCoreController {
*/ */
@PostMapping("/temporary/enroll") @PostMapping("/temporary/enroll")
public boolean enrollUserInfo(@RequestBody @Validated WxJsUserInfoVo wxJsUserInfoVo) { public boolean enrollUserInfo(@RequestBody @Validated WxJsUserInfoVo wxJsUserInfoVo) {
// 人员信息校验
boolean isIden = UserUtils.idenCardPattern(wxJsUserInfoVo.getIdenNumber());
boolean isPhone = UserUtils.phonePattern(wxJsUserInfoVo.getPhone());
if (!isIden || !isPhone) {
throw new ParamException(RCode.ENROLL_PARAM_ERROR, null);
}
// todo 手机号校验 wxJsUserInfoVo.getPhoneCode()
log.info("微信-促销员注册:{}", JSONObject.toJSONString(wxJsUserInfoVo)); log.info("微信-促销员注册:{}", JSONObject.toJSONString(wxJsUserInfoVo));
WxTemporaryInfoDto temporaryDto = new WxTemporaryInfoDto(); WxTemporaryInfoDto temporaryDto = new WxTemporaryInfoDto();
......
package com.wangxiaolu.promotion.controller.wechat; package com.wangxiaolu.promotion.controller.wechat;
import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto;
import com.wangxiaolu.promotion.service.wechat.WeChatUserQueryService; import com.wangxiaolu.promotion.service.wechat.WeChatUserQueryService;
import com.wangxiaolu.promotion.utils.WxMaUtils; import com.wangxiaolu.promotion.utils.WxMaUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
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;
...@@ -40,4 +40,15 @@ public class WeChatUserQueryController { ...@@ -40,4 +40,15 @@ public class WeChatUserQueryController {
} }
return false; return false;
} }
/**
* 根据openId查询人员详情
* 促销员查询
*/
@GetMapping("/temporary/openId")
public WxTemporaryInfoDto getTemporaryInfoByOpenId(String openId) {
return weChatUserQueryService.getTemporaryByOpenId(openId);
}
} }
...@@ -16,7 +16,7 @@ public interface TemporaryInfoDao { ...@@ -16,7 +16,7 @@ public interface TemporaryInfoDao {
int saveWxTemporaryInfo(WxTemporaryInfoDto temporaryDto); int saveWxTemporaryInfo(WxTemporaryInfoDto temporaryDto);
/** /**
* 根据OpenId查询人员是否存在 * 根据OpenId查询人员是否存在(非保密信息)
*/ */
TemporaryInfoDO queryOneTemporaryByOpenId(String openId); WxTemporaryInfoDto getUnimportantData(String openId);
} }
...@@ -11,6 +11,8 @@ import org.springframework.beans.BeanUtils; ...@@ -11,6 +11,8 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Objects;
/** /**
* @author : liqiulin * @author : liqiulin
* @date : 2024-04-08 16 * @date : 2024-04-08 16
...@@ -33,14 +35,16 @@ public class TemporaryInfoDaoImpl implements TemporaryInfoDao { ...@@ -33,14 +35,16 @@ public class TemporaryInfoDaoImpl implements TemporaryInfoDao {
} }
@Override @Override
public TemporaryInfoDO queryOneTemporaryByOpenId(String openId) { public WxTemporaryInfoDto getUnimportantData(String openId) {
TemporaryWrapper tw = new TemporaryWrapper().setOpenId(openId); TemporaryInfoDO temDo = temporaryInfoMapper.getUnimportantData(openId);
LambdaQueryWrapper<TemporaryInfoDO> qw = buildQueryList(tw);
TemporaryInfoDO temDo = temporaryInfoMapper.selectOne(qw); WxTemporaryInfoDto temporaryDto = null;
WxTemporaryInfoDto temporaryDto = new WxTemporaryInfoDto(); if (!Objects.isNull(temDo)){
temporaryDto = new WxTemporaryInfoDto();
BeanUtils.copyProperties(temDo, temporaryDto); BeanUtils.copyProperties(temDo, temporaryDto);
return temDo; }
return temporaryDto;
} }
private LambdaQueryWrapper<TemporaryInfoDO> buildQueryList(TemporaryWrapper tw){ private LambdaQueryWrapper<TemporaryInfoDO> buildQueryList(TemporaryWrapper tw){
......
...@@ -3,18 +3,22 @@ package com.wangxiaolu.promotion.domain.user.mapper; ...@@ -3,18 +3,22 @@ package com.wangxiaolu.promotion.domain.user.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wangxiaolu.promotion.domain.user.mapper.entity.TemporaryInfoDO; import com.wangxiaolu.promotion.domain.user.mapper.entity.TemporaryInfoDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
/** /**
* @author a02200059 * @author a02200059
* @description 针对表【temporary_info】的数据库操作Mapper * @description 针对表【temporary_info】的数据库操作Mapper
* @createDate 2024-04-09 18:34:54 * @createDate 2024-04-09 18:34:54
* @Entity com.wangxiaolu.promotion.domain.user.mapper.entity.TemporaryInfo * @Entity com.wangxiaolu.promotion.domain.user.mapper.entity.TemporaryInfo
*/ */
@Mapper @Mapper
@Repository @Repository
public interface TemporaryInfoMapper extends BaseMapper<TemporaryInfoDO> { public interface TemporaryInfoMapper extends BaseMapper<TemporaryInfoDO> {
// 根据openId查询非保密数据,保密数据不返回:身份证号、身份证照片等信息
TemporaryInfoDO getUnimportantData(@Param("openId") String openId);
} }
......
...@@ -15,6 +15,11 @@ import lombok.experimental.Accessors; ...@@ -15,6 +15,11 @@ import lombok.experimental.Accessors;
@NoArgsConstructor @NoArgsConstructor
@Accessors(chain = true) @Accessors(chain = true)
public class WxTemporaryInfoDto { public class WxTemporaryInfoDto {
/**
* temporary_info表id
*/
private Integer id;
/** /**
* openId * openId
*/ */
...@@ -71,9 +76,4 @@ public class WxTemporaryInfoDto { ...@@ -71,9 +76,4 @@ public class WxTemporaryInfoDto {
* 详细地址 * 详细地址
*/ */
String address; String address;
/**
* 手机验证码
*/
String phoneCode;
} }
...@@ -43,6 +43,7 @@ public class WxJsUserInfoVo { ...@@ -43,6 +43,7 @@ public class WxJsUserInfoVo {
/** /**
* 头像 * 头像
*/ */
@NotBlank(message = "请上传头像")
String avatarUrl; String avatarUrl;
......
...@@ -25,10 +25,11 @@ public enum RCode implements StatusCode { ...@@ -25,10 +25,11 @@ public enum RCode implements StatusCode {
API_ERROR(2000, "业务异常"), API_ERROR(2000, "业务异常"),
/** /**
* user模块 * user
* 3000+ * 3000+
*/ */
LOGIN_PARAM_ERROR(3000, "登录信息错误"); LOGIN_PARAM_ERROR(3000, "登录信息错误"),
ENROLL_PARAM_ERROR(3001, "注册信息错误");
; ;
......
package com.wangxiaolu.promotion.service.wechat; package com.wangxiaolu.promotion.service.wechat;
import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto;
/** /**
* @author : liqiulin * @author : liqiulin
* @date : 2024-04-09 18 * @date : 2024-04-09 18
...@@ -7,4 +9,6 @@ package com.wangxiaolu.promotion.service.wechat; ...@@ -7,4 +9,6 @@ package com.wangxiaolu.promotion.service.wechat;
*/ */
public interface WeChatUserQueryService { public interface WeChatUserQueryService {
boolean loginTemporaryByOpenId(String userOpenId); boolean loginTemporaryByOpenId(String userOpenId);
WxTemporaryInfoDto getTemporaryByOpenId(String openId);
} }
...@@ -3,6 +3,9 @@ package com.wangxiaolu.promotion.service.wechat.impl; ...@@ -3,6 +3,9 @@ package com.wangxiaolu.promotion.service.wechat.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.wangxiaolu.promotion.domain.user.dao.TemporaryInfoDao; import com.wangxiaolu.promotion.domain.user.dao.TemporaryInfoDao;
import com.wangxiaolu.promotion.domain.user.mapper.entity.TemporaryInfoDO; import com.wangxiaolu.promotion.domain.user.mapper.entity.TemporaryInfoDO;
import com.wangxiaolu.promotion.exception.ParamException;
import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto;
import com.wangxiaolu.promotion.result.basedata.RCode;
import com.wangxiaolu.promotion.service.wechat.WeChatUserQueryService; import com.wangxiaolu.promotion.service.wechat.WeChatUserQueryService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -25,15 +28,35 @@ public class WeChatUserQueryServiceImpl implements WeChatUserQueryService { ...@@ -25,15 +28,35 @@ public class WeChatUserQueryServiceImpl implements WeChatUserQueryService {
@Override @Override
public boolean loginTemporaryByOpenId(String userOpenId) { public boolean loginTemporaryByOpenId(String userOpenId) {
TemporaryInfoDO temDo = temporaryInfoDao.queryOneTemporaryByOpenId(userOpenId); WxTemporaryInfoDto temDto = temporaryInfoDao.getUnimportantData(userOpenId);
boolean exist = !Objects.isNull(temDo); boolean exist = !Objects.isNull(temDto);
// todo 查询到时,将个人信息放到reids中进行保存 // todo 查询到时,将个人信息放到reids中进行保存
if (exist) { if (exist) {
log.info("{}登录成功,openId:{}", temDo.getName(), userOpenId); log.info("微信-促销员{}登录成功,openId:{}", temDto.getName(), userOpenId);
log.info(JSONObject.toJSONString(temDo)); log.info(JSONObject.toJSONString(temDto));
} else {
log.info("微信-促销员登录失败,登录openId:{}", userOpenId);
} }
return exist; return exist;
} }
/**
* 根据openId查询人员详情
* @param openId 微信openId
* @return 不返回身份证照片等重要信息,详情请查看sql语句
*/
@Override
public WxTemporaryInfoDto getTemporaryByOpenId(String openId) {
// todo 先查询redis中是否有缓存数据
// todo redis中没有缓存数据,则进行查询
WxTemporaryInfoDto temporaryInfoDto = temporaryInfoDao.getUnimportantData(openId);
if (Objects.isNull(temporaryInfoDto)){
throw new ParamException(RCode.LOGIN_PARAM_ERROR,null);
}
return temporaryInfoDto;
}
} }
package com.wangxiaolu.promotion.utils;
import java.util.regex.Pattern;
/**
* 人员信息校验
*/
public class UserUtils {
private static final String ID_CARD_PATTERN = "^[1-9]\\d{5}(19|20)\\d{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2]\\d|3[0-1])|(04|06|09|11)(0[1-9]|[1-2]\\d|30)|02(0[1-9]|[1-2]\\d))\\d{3}[\\dXx]$";
private static final String PHONE_NUMBER_PATTERN = "^1[3-9]\\d{9}$";
/**
* 身份证号检验
*/
public static boolean idenCardPattern(String idCard) {
return Pattern.matches(ID_CARD_PATTERN, idCard);
}
public static boolean phonePattern(String phoneNumber) {
return phoneNumber.matches(PHONE_NUMBER_PATTERN);
}
}
...@@ -21,10 +21,20 @@ ...@@ -21,10 +21,20 @@
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id,name,phone, id
,name,phone,
iden_number,open_id,avatar_url, iden_number,open_id,avatar_url,
avatar_url_field_id,iden_front_photo_url,iden_front_photo_field_id, avatar_url_field_id,iden_front_photo_url,iden_front_photo_field_id,
iden_reverse_photo_url,iden_reverse_photo_field_id,create_time, iden_reverse_photo_url,iden_reverse_photo_field_id,create_time,
modify_time modify_time
</sql> </sql>
<sql id="Base_Column_Unimportant">
id,name,phone,open_id,avatar_url,create_time,modify_time
</sql>
<select id="getUnimportantData" resultMap="BaseResultMap">
select <include refid="Base_Column_Unimportant"/> from temporary_info where open_id = #{openId}
</select>
</mapper> </mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论