add: 短信登陆接口.
This commit is contained in:
parent
0c2b886de6
commit
1585ca80e5
|
@ -40,7 +40,7 @@ public class SysMobileServiceImpl implements SysMobileService {
|
||||||
private SmsClient smsClient;
|
private SmsClient smsClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送手机验证码 TODO: 调用短信网关发送验证码,测试返回前端
|
* 发送手机验证码
|
||||||
* @param mobile mobile
|
* @param mobile mobile
|
||||||
* @return code
|
* @return code
|
||||||
*/
|
*/
|
||||||
|
@ -63,7 +63,9 @@ public class SysMobileServiceImpl implements SysMobileService {
|
||||||
|
|
||||||
String code = RandomUtil.randomNumbers(Integer.parseInt(SecurityConstants.CODE_SIZE));
|
String code = RandomUtil.randomNumbers(Integer.parseInt(SecurityConstants.CODE_SIZE));
|
||||||
log.debug("手机号生成验证码成功:{},{}", mobile, code);
|
log.debug("手机号生成验证码成功:{},{}", mobile, code);
|
||||||
|
// 调用短信服务发送验证码
|
||||||
smsClient.sendCode(code, mobile);
|
smsClient.sendCode(code, mobile);
|
||||||
|
// 保存验证码到redis, 有效期60s
|
||||||
redisTemplate.opsForValue()
|
redisTemplate.opsForValue()
|
||||||
.set(CacheConstants.DEFAULT_CODE_KEY + mobile, code, SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
|
.set(CacheConstants.DEFAULT_CODE_KEY + mobile, code, SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
|
||||||
return R.ok(Boolean.TRUE, code);
|
return R.ok(Boolean.TRUE, code);
|
||||||
|
|
|
@ -4,11 +4,15 @@ import com.alibaba.fastjson.JSONObject;
|
||||||
import com.rax.vital.timer.AIMedicineTimer;
|
import com.rax.vital.timer.AIMedicineTimer;
|
||||||
import com.rax.vital.timer.VitalSignTimerWS;
|
import com.rax.vital.timer.VitalSignTimerWS;
|
||||||
import com.rax.vital.util.DatabaseNameUtil;
|
import com.rax.vital.util.DatabaseNameUtil;
|
||||||
|
import com.rax.vital.util.GetHttpParamUtil;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
||||||
|
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
|
||||||
import org.springframework.web.socket.*;
|
import org.springframework.web.socket.*;
|
||||||
|
|
||||||
|
import java.net.URLDecoder;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
@ -42,11 +46,11 @@ public class AddMedicineHandler implements WebSocketHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
|
||||||
// String decode = URLDecoder.decode(session.getUri().getQuery());
|
String decode = URLDecoder.decode(session.getUri().getQuery());
|
||||||
// Map params = GetHttpParamUtil.getParams(decode);
|
Map params = GetHttpParamUtil.getParams(decode);
|
||||||
// String token = (String) params.get("token");
|
String token = (String) params.get("token");
|
||||||
// OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
||||||
// String username = authorization.getPrincipalName();
|
String username = authorization.getPrincipalName();
|
||||||
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
JSONObject jsonObject = JSONObject.parseObject((String) message.getPayload());
|
||||||
String msgType = jsonObject.getString("msgType");
|
String msgType = jsonObject.getString("msgType");
|
||||||
|
@ -68,13 +72,13 @@ public class AddMedicineHandler implements WebSocketHandler {
|
||||||
if ("webResponseConnection".equals(msgType)) {
|
if ("webResponseConnection".equals(msgType)) {
|
||||||
String webConnectionFlag = jsonObject.getString("webConnectionFlag");
|
String webConnectionFlag = jsonObject.getString("webConnectionFlag");
|
||||||
// 给unity端发送网页端拒绝连接
|
// 给unity端发送网页端拒绝连接
|
||||||
aiMedicineTimer.sendConnectionResponseToUnity(patientName,idNum,date,databaseName, webConnectionFlag);
|
aiMedicineTimer.sendConnectionResponseToUnity(patientName, idNum, date, databaseName, webConnectionFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理web端请求或断开连接
|
// 处理web端请求或断开连接
|
||||||
if ("webRequestConnection".equals(msgType)) {
|
if ("webRequestConnection".equals(msgType)) {
|
||||||
String webRequestFlag = jsonObject.getString("webConnectionFlag");
|
String webRequestFlag = jsonObject.getString("webConnectionFlag");
|
||||||
aiMedicineTimer.sendWebRequestConnectionMsg(patientName,idNum,date,databaseName, webRequestFlag);
|
aiMedicineTimer.sendWebRequestConnectionMsg(patientName, idNum, date, databaseName, webRequestFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aiMedicineTimer.getUnitySession(databaseName) != null) {
|
if (aiMedicineTimer.getUnitySession(databaseName) != null) {
|
||||||
|
@ -105,7 +109,7 @@ public class AddMedicineHandler implements WebSocketHandler {
|
||||||
&& aiMedicineTimer.isReady(databaseName)) {
|
&& aiMedicineTimer.isReady(databaseName)) {
|
||||||
// todo 注意修改
|
// todo 注意修改
|
||||||
// flag 0 代表人工给药, 1代表AI给药
|
// flag 0 代表人工给药, 1代表AI给药
|
||||||
vitalSignTimerWS.changeWSAIFlag(databaseName, "admin", session, jsonObject.getString("flag"),
|
vitalSignTimerWS.changeWSAIFlag(databaseName, username, session, jsonObject.getString("flag"),
|
||||||
jsonObject.getString("medicine"), jsonObject.getString("value"));
|
jsonObject.getString("medicine"), jsonObject.getString("value"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -121,7 +125,6 @@ public class AddMedicineHandler implements WebSocketHandler {
|
||||||
session.sendMessage(new TextMessage(result.toJSONString().getBytes()));
|
session.sendMessage(new TextMessage(result.toJSONString().getBytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user