Merge branch 'main' of https://dd3skj.picp.vip/zhaoxinyu/hmc_gbhd
# Conflicts: # frontend/vite.config.js
This commit is contained in:
@@ -7,6 +7,7 @@ import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.client.auth.models.Client_user;
|
||||
import com.budwk.app.client.auth.service.ClientAuthService;
|
||||
import com.budwk.app.client.auth.vo.ClientLoginBody;
|
||||
import com.budwk.app.client.auth.vo.ClientRegisterBody;
|
||||
import com.budwk.app.sys.services.SysMsgService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import com.budwk.app.web.commons.auth.satoken.StpClientUtil;
|
||||
@@ -59,6 +60,22 @@ public class ClientAuthController {
|
||||
public void login(HttpServletRequest req, HttpSession session) {
|
||||
}
|
||||
|
||||
|
||||
@At("/register")
|
||||
@Ok("json")
|
||||
@AdaptBy(type = JsonAdaptor.class)
|
||||
@ApiOperation(value = "注册", nickname = "/register", httpMethod = "POST")
|
||||
public Result register(ClientRegisterBody registerBody) {
|
||||
try {
|
||||
// String token = clientAuthService.doRegister(registerBody);
|
||||
// return Result.success().addData(token);
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信登录
|
||||
*/
|
||||
@@ -76,6 +93,23 @@ public class ClientAuthController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@At("/send-reg-code/?")
|
||||
@Ok("json")
|
||||
@ApiOperation(value = "发送注册验证码", nickname = "/send-reg-code", httpMethod = "POST")
|
||||
public Result sendRegCode(String phone) {
|
||||
try {
|
||||
int count = dao.count(Client_user.class, Cnd.where("phone", "=", phone));
|
||||
if (count > 0) {
|
||||
return Result.error("手机号码已注册,请直接登录");
|
||||
}
|
||||
validateService.getSmsCode(phone);
|
||||
return Result.success(NutMap.NEW().addv("key", RedisConstant.UCENTER_SMSCODE + phone)).addMsg("发送成功");
|
||||
} catch (BaseException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信验证码
|
||||
*/
|
||||
|
||||
@@ -43,6 +43,11 @@ public class Client_user extends BaseModel implements Serializable {
|
||||
@Comment("头像")
|
||||
private String avatar;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@Comment("单位ID")
|
||||
private String unitId;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
@Comment("openId")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.budwk.app.client.auth.service;
|
||||
|
||||
import com.budwk.app.client.auth.vo.ClientLoginBody;
|
||||
import com.budwk.app.client.auth.vo.ClientRegisterBody;
|
||||
|
||||
public interface ClientAuthService {
|
||||
|
||||
@@ -11,4 +12,10 @@ public interface ClientAuthService {
|
||||
*/
|
||||
String doSmsLogin(ClientLoginBody loginBody);
|
||||
|
||||
/**
|
||||
* 注册
|
||||
* @param registerBody 注册信息
|
||||
* @return token
|
||||
*/
|
||||
String doRegister(ClientRegisterBody registerBody);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.budwk.app.client.auth.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.client.auth.vo.ClientLoginBody;
|
||||
import com.budwk.app.client.auth.models.Client_user;
|
||||
import com.budwk.app.client.auth.vo.ClientRegisterBody;
|
||||
import com.budwk.app.web.commons.auth.satoken.StpClientUtil;
|
||||
import com.budwk.app.web.commons.auth.service.ValidateService;
|
||||
import org.nutz.dao.Cnd;
|
||||
@@ -23,11 +25,12 @@ public class ClientAuthServiceImpl implements ClientAuthService {
|
||||
Client_user user = null;
|
||||
int count = dao.count(Client_user.class, Cnd.where(Client_user::getPhone, "=", loginBody.getPhone()));
|
||||
if (count == 0) {
|
||||
// 自动注册
|
||||
user = new Client_user();
|
||||
user.setPhone(loginBody.getPhone());
|
||||
user.setUserName("用户" + loginBody.getPhone());
|
||||
dao.insert(user);
|
||||
// // 自动注册
|
||||
// user = new Client_user();
|
||||
// user.setPhone(loginBody.getPhone());
|
||||
// user.setUserName("用户" + loginBody.getPhone());
|
||||
// dao.insert(user);
|
||||
throw new BaseException("手机号码不存在");
|
||||
}
|
||||
|
||||
validateService.checkSMSCode(loginBody.getPhone(), loginBody.getSmsCode());
|
||||
@@ -39,4 +42,20 @@ public class ClientAuthServiceImpl implements ClientAuthService {
|
||||
StpClientUtil.STP.checkLogin();
|
||||
return StpClientUtil.STP.getTokenValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String doRegister(ClientRegisterBody registerBody) {
|
||||
int count = dao.count(Client_user.class, Cnd.where(Client_user::getPhone, "=", registerBody.getPhone()));
|
||||
if (count > 0) {
|
||||
throw new BaseException("手机号码已注册,请直接登录");
|
||||
}
|
||||
|
||||
validateService.checkSMSCode(registerBody.getPhone(), registerBody.getSmsCode());
|
||||
|
||||
Client_user user = BeanUtil.copyProperties(registerBody, Client_user.class);
|
||||
dao.insert(user);
|
||||
StpClientUtil.STP.login(user.getId());
|
||||
StpClientUtil.STP.checkLogin();
|
||||
return StpClientUtil.STP.getTokenValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.budwk.app.client.auth.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ClientRegisterBody {
|
||||
|
||||
private String userName;
|
||||
|
||||
private String sex;
|
||||
|
||||
private String phone;
|
||||
|
||||
private String idCard;
|
||||
|
||||
private String avatar;
|
||||
|
||||
private String unitId;
|
||||
|
||||
private String smsCode;
|
||||
}
|
||||
@@ -50,8 +50,8 @@ public class ValidateService {
|
||||
if (Strings.isNotBlank(codeFromRedis)) {
|
||||
// throw new BaseException("请1分钟之后再试");
|
||||
}
|
||||
ThreadUtil.execute(()->{
|
||||
smsSendServer.sendMsg(mobile, "验证码为:"+text);
|
||||
ThreadUtil.execute(() -> {
|
||||
smsSendServer.sendCode(mobile, "验证码为:" + text);
|
||||
log.debug("sms code:::" + text);
|
||||
redisService.setex(RedisConstant.UCENTER_SMSCODE + mobile, 300, text);
|
||||
redisService.setex(RedisConstant.UCENTER_SMSCODE + mobile + ":LOCK", 60, text);
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
package com.budwk.app.web.commons.ext.sms;
|
||||
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.tencentcloudapi.common.Credential;
|
||||
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
||||
import com.tencentcloudapi.common.profile.ClientProfile;
|
||||
import com.tencentcloudapi.common.profile.HttpProfile;
|
||||
import com.tencentcloudapi.sms.v20190711.SmsClient;
|
||||
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
|
||||
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.ioc.impl.PropertiesProxy;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
@@ -14,27 +21,124 @@ import org.nutz.log.Logs;
|
||||
* @author wizzer@qq.com
|
||||
*/
|
||||
@IocBean
|
||||
@Slf4j
|
||||
public class SmsService {
|
||||
private static final Log log = Logs.get();
|
||||
|
||||
@Inject
|
||||
private PropertiesProxy conf;
|
||||
|
||||
@Inject
|
||||
private BaseService baseService;
|
||||
/**
|
||||
* 发送短信验证码
|
||||
*
|
||||
* @param mobile 手机号
|
||||
* @param text 验证码
|
||||
* @return true发送成功
|
||||
* @throws BaseException
|
||||
*/
|
||||
public boolean sendCode(String mobile, String text) throws BaseException {
|
||||
try {
|
||||
if (!conf.getBoolean("sms.enabled")) {
|
||||
return true;
|
||||
}
|
||||
Credential cred = new Credential(conf.get("sms.tencent.secret-id"), conf.get("sms.tencent.secret-key"));
|
||||
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("sms.tencentcloudapi.com");
|
||||
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
|
||||
SmsClient client = new SmsClient(cred, "", clientProfile);
|
||||
|
||||
SendSmsRequest req = new SendSmsRequest();
|
||||
String[] phoneNumberSet1 = {"+86" + mobile};
|
||||
req.setPhoneNumberSet(phoneNumberSet1);
|
||||
String[] templateParamSet1 = {text, "5"};
|
||||
req.setTemplateParamSet(templateParamSet1);
|
||||
req.setTemplateID(conf.get("sms.tencent.tpl.login_code"));
|
||||
req.setSmsSdkAppid(conf.get("sms.tencent.appid"));
|
||||
req.setSign(conf.get("sms.tencent.sign"));
|
||||
SendSmsResponse resp = client.SendSms(req);
|
||||
log.debug(SendSmsResponse.toJsonString(resp));
|
||||
return true;
|
||||
} catch (TencentCloudSDKException tencentCloudSDKException) {
|
||||
throw new BaseException(tencentCloudSDKException.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送注册验证码
|
||||
* @param mobile 手机号码
|
||||
* @param text 验证码
|
||||
* @return true发送成功
|
||||
* @throws BaseException
|
||||
*/
|
||||
public boolean sendRegCode(String mobile,String text) throws BaseException {
|
||||
try {
|
||||
if (!conf.getBoolean("sms.enabled")) {
|
||||
return true;
|
||||
}
|
||||
Credential cred = new Credential(conf.get("sms.tencent.secret-id"), conf.get("sms.tencent.secret-key"));
|
||||
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("sms.tencentcloudapi.com");
|
||||
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
|
||||
SmsClient client = new SmsClient(cred, "", clientProfile);
|
||||
|
||||
SendSmsRequest req = new SendSmsRequest();
|
||||
String[] phoneNumberSet1 = {"+86" + mobile};
|
||||
req.setPhoneNumberSet(phoneNumberSet1);
|
||||
String[] templateParamSet1 = {text, "5"};
|
||||
req.setTemplateParamSet(templateParamSet1);
|
||||
req.setTemplateID(conf.get("sms.tencent.tpl.reg_code"));
|
||||
req.setSmsSdkAppid(conf.get("sms.tencent.appid"));
|
||||
req.setSign(conf.get("sms.tencent.sign"));
|
||||
SendSmsResponse resp = client.SendSms(req);
|
||||
log.debug(SendSmsResponse.toJsonString(resp));
|
||||
return true;
|
||||
} catch (TencentCloudSDKException tencentCloudSDKException) {
|
||||
throw new BaseException(tencentCloudSDKException.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送短信通知
|
||||
*
|
||||
* @param mobile 手机号码(最多200)
|
||||
* @param text 模板参数值
|
||||
* @param param 模板参数值
|
||||
* @return
|
||||
* @throws BaseException
|
||||
*/
|
||||
public boolean sendMsg(String mobile, String text) throws BaseException {
|
||||
public boolean sendMsg(String[] mobile, String[] param) throws BaseException {
|
||||
try {
|
||||
if (!conf.getBoolean("sms.enabled")) {
|
||||
return true;
|
||||
}
|
||||
Credential cred = new Credential(conf.get("sms.tencent.secret-id"), conf.get("sms.tencent.secret-key"));
|
||||
|
||||
return true;
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("sms.tencentcloudapi.com");
|
||||
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
|
||||
SmsClient client = new SmsClient(cred, "", clientProfile);
|
||||
|
||||
SendSmsRequest req = new SendSmsRequest();
|
||||
req.setPhoneNumberSet(mobile);
|
||||
req.setTemplateParamSet(param);
|
||||
req.setTemplateID(conf.get("sms.tencent.tpl.msg"));
|
||||
req.setSmsSdkAppid(conf.get("sms.tencent.appid"));
|
||||
req.setSign(conf.get("sms.tencent.sign"));
|
||||
SendSmsResponse resp = client.SendSms(req);
|
||||
log.debug(SendSmsResponse.toJsonString(resp));
|
||||
return true;
|
||||
} catch (TencentCloudSDKException tencentCloudSDKException) {
|
||||
throw new BaseException(tencentCloudSDKException.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.budwk.app.web.controllers.open;
|
||||
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@IocBean
|
||||
@At("/open/common")
|
||||
@Ok("json")
|
||||
public class OpenCommonController {
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
|
||||
@At
|
||||
public Result units() {
|
||||
List<Sys_unit> units = dao.query(Sys_unit.class, Cnd.where(Sys_unit::getIsEnable, "=", 1).asc(Sys_unit::getId));
|
||||
return Result.success(units);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@ jetty:
|
||||
|
||||
security:
|
||||
tokenName: token
|
||||
timeout: 3600
|
||||
timeout: 86400
|
||||
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
||||
# 允许同一账号并发登录,则系统参数 SessionOnlyOne 有效,亦可踢人下线并多了弹框提示功能
|
||||
isConcurrent: true
|
||||
@@ -141,18 +141,24 @@ quartz:
|
||||
connectionProvider:
|
||||
class: com.budwk.app.task.conn.NutConnectionProvider
|
||||
|
||||
swagger:
|
||||
info:
|
||||
title: 趣味运动会系统
|
||||
description: 趣味运动会系统
|
||||
|
||||
sms:
|
||||
enabled: false
|
||||
#腾讯云短信配置
|
||||
tencent:
|
||||
secret-id: 1
|
||||
secret-key: 2
|
||||
appid: 1 #应用ID
|
||||
sign: '萌发开源' #短信签名
|
||||
secret-id: 1301383032
|
||||
secret-key: AKIDMZWDepjNnxqSotiHZeU6SYOyIMAj24rO
|
||||
appid: 1400934413 #应用ID
|
||||
sign: '武汉地大三思科技' #短信签名
|
||||
tpl:
|
||||
#验证码模板ID
|
||||
code: 1
|
||||
#登录验证码模板ID
|
||||
login_code: 2422443
|
||||
#注册验证码模板ID
|
||||
reg_code: 2422440
|
||||
#短信通知模板ID
|
||||
msg: 2
|
||||
msg: '?'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user