|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+package com.ruoyi.wisdomarbitrate.service.impl;
|
|
|
2
|
+
|
|
|
3
|
+import cn.hutool.core.util.StrUtil;
|
|
|
4
|
+import cn.hutool.http.HttpUtil;
|
|
|
5
|
+import cn.hutool.json.JSONUtil;
|
|
|
6
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
7
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
8
|
+import com.ruoyi.common.constant.CacheConstants;
|
|
|
9
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
10
|
+import com.ruoyi.common.core.domain.entity.SysDictData;
|
|
|
11
|
+import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
12
|
+import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
13
|
+import com.ruoyi.common.core.redis.RedisCache;
|
|
|
14
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
15
|
+import com.ruoyi.common.utils.SmsUtils;
|
|
|
16
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
17
|
+import com.ruoyi.common.utils.http.HttpUtils;
|
|
|
18
|
+import com.ruoyi.common.utils.spring.SpringUtils;
|
|
|
19
|
+import com.ruoyi.system.mapper.SysUserMapper;
|
|
|
20
|
+import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
|
|
|
21
|
+import com.ruoyi.wisdomarbitrate.domain.vo.WeChatUserVO;
|
|
|
22
|
+import com.ruoyi.wisdomarbitrate.mapper.IdentityAuthenticationMapper;
|
|
|
23
|
+import com.ruoyi.wisdomarbitrate.mapper.WeChatUserMapper;
|
|
|
24
|
+import com.ruoyi.wisdomarbitrate.service.WeChatUserService;
|
|
|
25
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
26
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
27
|
+import org.springframework.stereotype.Service;
|
|
|
28
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
29
|
+
|
|
|
30
|
+import java.util.HashMap;
|
|
|
31
|
+import java.util.List;
|
|
|
32
|
+import java.util.Random;
|
|
|
33
|
+import java.util.concurrent.TimeUnit;
|
|
|
34
|
+
|
|
|
35
|
+/**
|
|
|
36
|
+ * @author wangqiong
|
|
|
37
|
+ * @description 微信小程序用户注册登录
|
|
|
38
|
+ * @date 2023-10-16 11:45
|
|
|
39
|
+ */
|
|
|
40
|
+@Service
|
|
|
41
|
+@Slf4j
|
|
|
42
|
+public class WeChatUserServiceImpl implements WeChatUserService {
|
|
|
43
|
+ String appid="wx91cb8459dca561b4";//自行获取
|
|
|
44
|
+ //小程序secret
|
|
|
45
|
+ String secret="190aaa3bda96a65d25318fbb0e133fc6";//自己去公众号后台获取
|
|
|
46
|
+ // 获取openId
|
|
|
47
|
+ String openIdUrl = "https://api.weixin.qq.com/sns/jscode2session";
|
|
|
48
|
+ @Autowired
|
|
|
49
|
+ private WeChatUserMapper weChatUserMapper;
|
|
|
50
|
+ @Autowired
|
|
|
51
|
+ private SysUserMapper sysUserMapper;
|
|
|
52
|
+ @Autowired
|
|
|
53
|
+ private IdentityAuthenticationMapper identityAuthenticationMapper;
|
|
|
54
|
+
|
|
|
55
|
+ @Override
|
|
|
56
|
+ public String sendCode(WeChatUserVO userVO) {
|
|
|
57
|
+ Random random = new Random();
|
|
|
58
|
+ String code = "";
|
|
|
59
|
+ for (int i = 0; i < 6; i++) {
|
|
|
60
|
+
|
|
|
61
|
+ code += random.nextInt(10);
|
|
|
62
|
+ }
|
|
|
63
|
+ SmsUtils.SendSmsRequest request = new SmsUtils.SendSmsRequest();
|
|
|
64
|
+ request.setTemplateId("1952136");
|
|
|
65
|
+ // 1948332 普通短信 开庭审理房间号通知 尊敬的{1}用户,您的{2}仲裁案件,开庭审理房间号为{3},请知晓,如非本人操作,请忽略本短信。
|
|
|
66
|
+ request.setPhone(userVO.getPhone());
|
|
|
67
|
+ request.setTemplateParamSet(new String[]{"王琼", "验证码", code});
|
|
|
68
|
+ Boolean flag = SmsUtils.sendSms(request);
|
|
|
69
|
+ if(flag){
|
|
|
70
|
+ setCodeCache(userVO.getPhone(),code);
|
|
|
71
|
+ }
|
|
|
72
|
+ return "短信发送成功";
|
|
|
73
|
+ }
|
|
|
74
|
+ /**
|
|
|
75
|
+ * 设置字典缓存
|
|
|
76
|
+ *
|
|
|
77
|
+ * @param key 参数键
|
|
|
78
|
+ * @param code 字典数据列表
|
|
|
79
|
+ */
|
|
|
80
|
+ public static void setCodeCache(String key, String code)
|
|
|
81
|
+ {
|
|
|
82
|
+ SpringUtils.getBean(RedisCache.class).setCacheObject(getVerifyCodeCacheKey(key), code, 5,TimeUnit.MILLISECONDS);
|
|
|
83
|
+ }
|
|
|
84
|
+
|
|
|
85
|
+
|
|
|
86
|
+ /**
|
|
|
87
|
+ * 获取字典缓存
|
|
|
88
|
+ *
|
|
|
89
|
+ * @param key 参数键
|
|
|
90
|
+ * @return dictDatas 字典数据列表
|
|
|
91
|
+ */
|
|
|
92
|
+ public static String getCodeCache(String key)
|
|
|
93
|
+ {
|
|
|
94
|
+ String codeCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getVerifyCodeCacheKey(key));
|
|
|
95
|
+ if (StringUtils.isNotNull(codeCache))
|
|
|
96
|
+ {
|
|
|
97
|
+ return codeCache;
|
|
|
98
|
+ }
|
|
|
99
|
+ return null;
|
|
|
100
|
+ }
|
|
|
101
|
+
|
|
|
102
|
+ private static String getVerifyCodeCacheKey(String key) {
|
|
|
103
|
+ return CacheConstants.WE_CHAT_SMS_VERIFY_CODE_KEY + key;
|
|
|
104
|
+ }
|
|
|
105
|
+ @Transactional
|
|
|
106
|
+ @Override
|
|
|
107
|
+ public AjaxResult registerUser(IdentityAuthentication ientityAuthentication) {
|
|
|
108
|
+ // 校验短信验证码
|
|
|
109
|
+// if(StrUtil.isEmpty(getCodeCache(ientityAuthentication.getPhone()))){
|
|
|
110
|
+// return AjaxResult.success("验证码校验失败");
|
|
|
111
|
+// }
|
|
|
112
|
+ // 根据身份证查询系统用户表中是否存在该用户,存在则同步已认证的信息,不存在则新增
|
|
|
113
|
+ SysUser sysUser=sysUserMapper.selectUserByIdCard(ientityAuthentication.getIdentityNo());
|
|
|
114
|
+
|
|
|
115
|
+ if(sysUser!=null){
|
|
|
116
|
+ sysUser.setIdCard(ientityAuthentication.getIdentityNo());
|
|
|
117
|
+ sysUser.setNickName(ientityAuthentication.getName());
|
|
|
118
|
+ sysUser.setUserName(ientityAuthentication.getUserName());
|
|
|
119
|
+ sysUser.setPhonenumber(ientityAuthentication.getPhone());
|
|
|
120
|
+ sysUser.setEmail(ientityAuthentication.getEmail());
|
|
|
121
|
+ sysUser.setPassword(SecurityUtils.encryptPassword(ientityAuthentication.getPassWord()));
|
|
|
122
|
+ sysUserMapper.updateUser(sysUser);
|
|
|
123
|
+ ientityAuthentication.setUserId(sysUser.getUserId());
|
|
|
124
|
+ }else {
|
|
|
125
|
+ sysUser=new SysUser();
|
|
|
126
|
+ // 用户名设为电话号
|
|
|
127
|
+ sysUser.setUserName(ientityAuthentication.getPhone());
|
|
|
128
|
+ sysUser.setIdCard(ientityAuthentication.getIdentityNo());
|
|
|
129
|
+ sysUser.setNickName(ientityAuthentication.getName());
|
|
|
130
|
+ sysUser.setUserName(ientityAuthentication.getUserName());
|
|
|
131
|
+ sysUser.setPhonenumber(ientityAuthentication.getPhone());
|
|
|
132
|
+ sysUser.setEmail(ientityAuthentication.getEmail());
|
|
|
133
|
+ sysUser.setCreateBy(ientityAuthentication.getPhone());
|
|
|
134
|
+ sysUser.setPassword(SecurityUtils.encryptPassword(ientityAuthentication.getPassWord()));
|
|
|
135
|
+ int row = sysUserMapper.insertUser(sysUser);
|
|
|
136
|
+ if(row<1) {
|
|
|
137
|
+ return AjaxResult.success("注册失败");
|
|
|
138
|
+ }
|
|
|
139
|
+ }
|
|
|
140
|
+
|
|
|
141
|
+ ientityAuthentication.setUserId(sysUser.getUserId());
|
|
|
142
|
+ ientityAuthentication.setUserName(sysUser.getUserName());
|
|
|
143
|
+ // 已经认证过的用户才能注册,认证表中已经有该数据
|
|
|
144
|
+ identityAuthenticationMapper.updateIdentityAuthentication(ientityAuthentication);
|
|
|
145
|
+ return AjaxResult.success("注册成功");
|
|
|
146
|
+ }
|
|
|
147
|
+
|
|
|
148
|
+}
|