小程序认证登录
This commit is contained in:
@@ -134,4 +134,11 @@ public interface SysUserMapper
|
||||
public SysUser checkEmailUnique(String email);
|
||||
|
||||
List<SysUser> selectUserListByIds(@Param("idList") List<Long> idList);
|
||||
|
||||
/**
|
||||
* 根据身份证号查询用户信息
|
||||
* @param identityNo
|
||||
* @return
|
||||
*/
|
||||
SysUser selectUserByIdCard(@Param("idCard")String identityNo);
|
||||
}
|
||||
|
||||
+20
-1
@@ -3,9 +3,10 @@ package com.ruoyi.wisdomarbitrate.domain;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class IdentityAuthentication extends BaseEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -15,6 +16,20 @@ public class IdentityAuthentication extends BaseEntity {
|
||||
private String name;
|
||||
/** 身份证号 */
|
||||
private String identityNo;
|
||||
/**
|
||||
* 短信验证码
|
||||
*/
|
||||
private String VerifyCode;
|
||||
private String passWord;
|
||||
private String phone;
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
/**
|
||||
* 身份证地址
|
||||
*/
|
||||
private String idAddress;
|
||||
/** 认证时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date certificationTime;
|
||||
@@ -44,6 +59,10 @@ public class IdentityAuthentication extends BaseEntity {
|
||||
private Long userId;
|
||||
/** 用户账号 */
|
||||
private String userName;
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
private String nickName;
|
||||
|
||||
/** EID商户id */
|
||||
private String merchantId;
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.ruoyi.wisdomarbitrate.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.wisdomarbitrate.domain.Arbitrator;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 微信小程序用户注册登录
|
||||
*/
|
||||
@Data
|
||||
public class WeChatUserVO {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 微信用户唯一标识
|
||||
*/
|
||||
private String openId;
|
||||
/**
|
||||
* 微信授权的code,用户登录凭证
|
||||
*/
|
||||
private String wxCode;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
@NotEmpty(message = "姓名不能为空")
|
||||
private String name;
|
||||
/** 身份证号 */
|
||||
@NotEmpty(message = "身份证号不能为空")
|
||||
private String identityNo;
|
||||
/** 认证时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date certificationTime;
|
||||
/** 认证状态 */
|
||||
private Integer certificationStatus;
|
||||
private String password;
|
||||
/**
|
||||
* 电话
|
||||
*/
|
||||
@NotEmpty(message = "电话不能为空")
|
||||
private String phone;
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
private String verifyCode;
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@NotEmpty(message = "邮箱不能为空")
|
||||
private String email;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
private String updateBy;
|
||||
}
|
||||
+1
-2
@@ -8,6 +8,5 @@ public interface IdentityAuthenticationMapper {
|
||||
IdentityAuthentication selectIdentityAuthentication(IdentityAuthentication identityAuthentication);
|
||||
|
||||
|
||||
|
||||
|
||||
void updateIdentityAuthentication(IdentityAuthentication ientityAuthentication);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.ruoyi.wisdomarbitrate.mapper;
|
||||
|
||||
import com.ruoyi.wisdomarbitrate.domain.vo.WeChatUserVO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wangqiong
|
||||
* @description 微信小程序用户注册登录
|
||||
* @date 2023-10-16 11:45
|
||||
*/
|
||||
@Repository
|
||||
public interface WeChatUserMapper {
|
||||
int insertUser(WeChatUserVO userVO);
|
||||
int updateUser(WeChatUserVO userVO);
|
||||
List<WeChatUserVO> selectIdentityAuthentication(WeChatUserVO userVO);
|
||||
|
||||
WeChatUserVO selectUserByOppenId(@Param("oppenId") String openId);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.ruoyi.wisdomarbitrate.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
|
||||
import com.ruoyi.wisdomarbitrate.domain.vo.WeChatUserVO;
|
||||
|
||||
/**
|
||||
* 微信小程序用户注册登录
|
||||
*/
|
||||
public interface WeChatUserService {
|
||||
|
||||
|
||||
String sendCode(WeChatUserVO userVO);
|
||||
|
||||
|
||||
AjaxResult registerUser(IdentityAuthentication ientityAuthentication);
|
||||
}
|
||||
+15
-8
@@ -8,8 +8,10 @@ import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
|
||||
import com.ruoyi.wisdomarbitrate.mapper.IdentityAuthenticationMapper;
|
||||
import com.ruoyi.wisdomarbitrate.service.IdentityAuthenticationService;
|
||||
@@ -46,6 +48,7 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthentication
|
||||
|
||||
@Autowired
|
||||
private IdentityAuthenticationMapper identityAuthenticationMapper;
|
||||
private SysUserMapper sysUserMapper;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(IdentityAuthenticationServiceImpl.class);
|
||||
|
||||
@@ -147,7 +150,7 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthentication
|
||||
@Transactional
|
||||
public AjaxResult selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication) {
|
||||
String eidToken = ientityAuthentication.getEidToken();
|
||||
|
||||
IdentityAuthentication authentication = new IdentityAuthentication();
|
||||
try {
|
||||
Credential cred = new Credential(credentialSecretId, credentialSecretKey);
|
||||
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
||||
@@ -181,8 +184,8 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthentication
|
||||
String idcardno = info.getString("idnum");
|
||||
String name = info.getString("name");
|
||||
//2.在用户认证表中插入用户认证记录
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
IdentityAuthentication authentication = new IdentityAuthentication();
|
||||
// LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
* 用户名id
|
||||
@@ -192,15 +195,17 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthentication
|
||||
* 认证状态0表示成功
|
||||
* 请求id
|
||||
*/
|
||||
authentication.setUserName(loginUser.getUsername());
|
||||
authentication.setUserId(loginUser.getUserId());
|
||||
// authentication.setUserName(loginUser.getUsername());
|
||||
// authentication.setUserId(loginUser.getUserId());
|
||||
authentication.setName(name);
|
||||
authentication.setIdentityNo(idcardno);
|
||||
authentication.setCertificationTime(new Date());
|
||||
authentication.setCertificationStatus(0);
|
||||
authentication.setCreateBy(loginUser.getUsername());
|
||||
authentication.setCreateBy(name);
|
||||
// authentication.setCreateBy(loginUser.getUsername());
|
||||
try {
|
||||
identityAuthenticationMapper.insertIdentityAuthentication(authentication);
|
||||
authentication.setId(authentication.getId());
|
||||
} catch (Exception e) {
|
||||
System.out.println("认证记录新增失败");
|
||||
}
|
||||
@@ -210,12 +215,14 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthentication
|
||||
}
|
||||
}
|
||||
}
|
||||
return AjaxResult.success();
|
||||
return AjaxResult.success(authentication);
|
||||
} catch (TencentCloudSDKException e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
return null;
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
package com.ruoyi.wisdomarbitrate.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.SysDictData;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.SmsUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
|
||||
import com.ruoyi.wisdomarbitrate.domain.vo.WeChatUserVO;
|
||||
import com.ruoyi.wisdomarbitrate.mapper.IdentityAuthenticationMapper;
|
||||
import com.ruoyi.wisdomarbitrate.mapper.WeChatUserMapper;
|
||||
import com.ruoyi.wisdomarbitrate.service.WeChatUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author wangqiong
|
||||
* @description 微信小程序用户注册登录
|
||||
* @date 2023-10-16 11:45
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class WeChatUserServiceImpl implements WeChatUserService {
|
||||
String appid="wx91cb8459dca561b4";//自行获取
|
||||
//小程序secret
|
||||
String secret="190aaa3bda96a65d25318fbb0e133fc6";//自己去公众号后台获取
|
||||
// 获取openId
|
||||
String openIdUrl = "https://api.weixin.qq.com/sns/jscode2session";
|
||||
@Autowired
|
||||
private WeChatUserMapper weChatUserMapper;
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
@Autowired
|
||||
private IdentityAuthenticationMapper identityAuthenticationMapper;
|
||||
|
||||
@Override
|
||||
public String sendCode(WeChatUserVO userVO) {
|
||||
Random random = new Random();
|
||||
String code = "";
|
||||
for (int i = 0; i < 6; i++) {
|
||||
|
||||
code += random.nextInt(10);
|
||||
}
|
||||
SmsUtils.SendSmsRequest request = new SmsUtils.SendSmsRequest();
|
||||
request.setTemplateId("1952136");
|
||||
// 1948332 普通短信 开庭审理房间号通知 尊敬的{1}用户,您的{2}仲裁案件,开庭审理房间号为{3},请知晓,如非本人操作,请忽略本短信。
|
||||
request.setPhone(userVO.getPhone());
|
||||
request.setTemplateParamSet(new String[]{"王琼", "验证码", code});
|
||||
Boolean flag = SmsUtils.sendSms(request);
|
||||
if(flag){
|
||||
setCodeCache(userVO.getPhone(),code);
|
||||
}
|
||||
return "短信发送成功";
|
||||
}
|
||||
/**
|
||||
* 设置字典缓存
|
||||
*
|
||||
* @param key 参数键
|
||||
* @param code 字典数据列表
|
||||
*/
|
||||
public static void setCodeCache(String key, String code)
|
||||
{
|
||||
SpringUtils.getBean(RedisCache.class).setCacheObject(getVerifyCodeCacheKey(key), code, 5,TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取字典缓存
|
||||
*
|
||||
* @param key 参数键
|
||||
* @return dictDatas 字典数据列表
|
||||
*/
|
||||
public static String getCodeCache(String key)
|
||||
{
|
||||
String codeCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getVerifyCodeCacheKey(key));
|
||||
if (StringUtils.isNotNull(codeCache))
|
||||
{
|
||||
return codeCache;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getVerifyCodeCacheKey(String key) {
|
||||
return CacheConstants.WE_CHAT_SMS_VERIFY_CODE_KEY + key;
|
||||
}
|
||||
@Transactional
|
||||
@Override
|
||||
public AjaxResult registerUser(IdentityAuthentication ientityAuthentication) {
|
||||
// 校验短信验证码
|
||||
// if(StrUtil.isEmpty(getCodeCache(ientityAuthentication.getPhone()))){
|
||||
// return AjaxResult.success("验证码校验失败");
|
||||
// }
|
||||
// 根据身份证查询系统用户表中是否存在该用户,存在则同步已认证的信息,不存在则新增
|
||||
SysUser sysUser=sysUserMapper.selectUserByIdCard(ientityAuthentication.getIdentityNo());
|
||||
|
||||
if(sysUser!=null){
|
||||
sysUser.setIdCard(ientityAuthentication.getIdentityNo());
|
||||
sysUser.setNickName(ientityAuthentication.getName());
|
||||
sysUser.setUserName(ientityAuthentication.getUserName());
|
||||
sysUser.setPhonenumber(ientityAuthentication.getPhone());
|
||||
sysUser.setEmail(ientityAuthentication.getEmail());
|
||||
sysUser.setPassword(SecurityUtils.encryptPassword(ientityAuthentication.getPassWord()));
|
||||
sysUserMapper.updateUser(sysUser);
|
||||
ientityAuthentication.setUserId(sysUser.getUserId());
|
||||
}else {
|
||||
sysUser=new SysUser();
|
||||
// 用户名设为电话号
|
||||
sysUser.setUserName(ientityAuthentication.getPhone());
|
||||
sysUser.setIdCard(ientityAuthentication.getIdentityNo());
|
||||
sysUser.setNickName(ientityAuthentication.getName());
|
||||
sysUser.setUserName(ientityAuthentication.getUserName());
|
||||
sysUser.setPhonenumber(ientityAuthentication.getPhone());
|
||||
sysUser.setEmail(ientityAuthentication.getEmail());
|
||||
sysUser.setCreateBy(ientityAuthentication.getPhone());
|
||||
sysUser.setPassword(SecurityUtils.encryptPassword(ientityAuthentication.getPassWord()));
|
||||
int row = sysUserMapper.insertUser(sysUser);
|
||||
if(row<1) {
|
||||
return AjaxResult.success("注册失败");
|
||||
}
|
||||
}
|
||||
|
||||
ientityAuthentication.setUserId(sysUser.getUserId());
|
||||
ientityAuthentication.setUserName(sysUser.getUserName());
|
||||
// 已经认证过的用户才能注册,认证表中已经有该数据
|
||||
identityAuthenticationMapper.updateIdentityAuthentication(ientityAuthentication);
|
||||
return AjaxResult.success("注册成功");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user