This commit is contained in:
D 2024-03-02 00:28:24 +08:00
parent da9c38f476
commit f13712509e
6 changed files with 155 additions and 105 deletions

View File

@ -1,10 +1,24 @@
package com.ruoyi.oauth.phone.controller; package com.ruoyi.oauth.phone.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
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 com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.oauth.phone.service.DySmsService;
@RestController @RestController
@Anonymous
@RequestMapping("/oauth/phone") @RequestMapping("/oauth/phone")
public class DySmsController { public class DySmsController {
@Autowired
public DySmsService dySmsService;
@PostMapping("/login")
public String postMethodName() {
dySmsService.doLogin("17854126030");
return null;
}
} }

View File

@ -6,12 +6,14 @@ import java.util.concurrent.TimeUnit;
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 com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.framework.web.service.UserDetailsServiceImpl; import com.ruoyi.framework.web.service.UserDetailsServiceImpl;
import com.ruoyi.oauth.phone.enums.DySmsTemplate;
import com.ruoyi.oauth.phone.service.DySmsService; import com.ruoyi.oauth.phone.service.DySmsService;
import com.ruoyi.oauth.phone.utils.DySmsUtil; import com.ruoyi.oauth.phone.utils.DySmsUtil;
import com.ruoyi.system.service.ISysUserService; import com.ruoyi.system.service.ISysUserService;
@ -31,7 +33,7 @@ public class DySmsServiceImpl implements DySmsService {
private TokenService tokenService; private TokenService tokenService;
public static String generateRandomString(int n) { public static String generateRandomString(int n) {
String characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; String characters = "0123456789"; //ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
Random random = new Random(); Random random = new Random();
@ -55,7 +57,9 @@ public class DySmsServiceImpl implements DySmsService {
throw new ServiceException("该手机号未绑定用户"); throw new ServiceException("该手机号未绑定用户");
} }
try { try {
dySmsUtil.sendSms(null, null, phone); JSONObject templateParams = new JSONObject();
templateParams.put("code", code);
dySmsUtil.sendSms(DySmsTemplate.Test_TEMPLATE_CODE, templateParams, phone);
redisCache.setCacheObject("phone_codes_login" + phone, code, 1, TimeUnit.MINUTES); redisCache.setCacheObject("phone_codes_login" + phone, code, 1, TimeUnit.MINUTES);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -76,8 +76,11 @@ public class DySmsUtil {
try { try {
// 复制代码运行请自行打印 API 的返回值 // 复制代码运行请自行打印 API 的返回值
SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, new RuntimeOptions()); SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, new RuntimeOptions());
logger.info("短信接口返回的数据----------------"); if (sendSmsResponse.getBody().getCode().equals("OK")) {
logger.info(sendSmsResponse.toString()); logger.info("短信接口返回的数据---", sendSmsResponse.getBody().getMessage());
} else {
logger.error("短信接口返回的数据---", sendSmsResponse.getBody().getMessage());
}
} catch (TeaException error) { } catch (TeaException error) {
// 错误 message // 错误 message
System.out.println(error.getMessage()); System.out.println(error.getMessage());

View File

@ -23,6 +23,11 @@
<artifactId>ruoyi-common</artifactId> <artifactId>ruoyi-common</artifactId>
</dependency> </dependency>
<!-- 系统框架 -->
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-framework</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -16,10 +16,14 @@ import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Anonymous; import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.service.PermissionService;
import com.ruoyi.online.domain.OnlineMb; import com.ruoyi.online.domain.OnlineMb;
import com.ruoyi.online.service.IOnlineMbService; import com.ruoyi.online.service.IOnlineMbService;
import com.ruoyi.online.utils.SqlMapper; import com.ruoyi.online.utils.SqlMapper;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
@ -31,9 +35,13 @@ public class OnLineController extends BaseController {
private SqlSessionFactory sqlSessionFactory; private SqlSessionFactory sqlSessionFactory;
@Autowired @Autowired
private IOnlineMbService onlineMbService; private IOnlineMbService onlineMbService;
@Resource(name = "ss")
private PermissionService permissionService;
@RequestMapping("/api/**") @RequestMapping("/api/**")
public Object api(@RequestParam(required = false) HashMap<String,Object> params,@RequestBody(required = false) HashMap<String,Object> data,HttpServletRequest request,HttpServletResponse response) { public Object api(@RequestParam(required = false) HashMap<String, Object> params,
@RequestBody(required = false) HashMap<String, Object> data, HttpServletRequest request,
HttpServletResponse response) {
OnlineMb selectOnlineMb = new OnlineMb(); OnlineMb selectOnlineMb = new OnlineMb();
selectOnlineMb.setPath(request.getRequestURI().replace("/online/api", "")); selectOnlineMb.setPath(request.getRequestURI().replace("/online/api", ""));
selectOnlineMb.setMethod(request.getMethod()); selectOnlineMb.setMethod(request.getMethod());
@ -59,13 +67,35 @@ public class OnLineController extends BaseController {
object.putAll(data); object.putAll(data);
} }
object.put("params", object_params); object.put("params", object_params);
List<OnlineMb> selectOnlineMbList = onlineMbService.selectOnlineMbList(selectOnlineMb); List<OnlineMb> selectOnlineMbList = onlineMbService.selectOnlineMbList(selectOnlineMb);
if (selectOnlineMbList.size() == 0) { if (selectOnlineMbList.size() == 0) {
return error("没有相关接口"); return AjaxResult.error("没有资源"+selectOnlineMb.getPath());
} else if (selectOnlineMbList.size() > 1) { } else if (selectOnlineMbList.size() > 1) {
return error("存在多个接口"); return AjaxResult.error(500,"系统错误,在线接口重复");
} else { } else {
OnlineMb onlineMb = selectOnlineMbList.get(0); OnlineMb onlineMb = selectOnlineMbList.get(0);
boolean permissionFlag = true;
if (onlineMb.getPermissionType() != null) {
switch (onlineMb.getPermissionType()) {
case "hasPermi" -> permissionFlag = permissionService.hasPermi(onlineMb.getPermissionValue());
case "lacksPermi" -> permissionFlag = !permissionService.lacksPermi(onlineMb.getPermissionValue());
case "hasAnyPermi" -> permissionFlag = permissionService.hasAnyPermi(onlineMb.getPermissionValue());
case "hasRole" -> permissionFlag = permissionService.hasRole(onlineMb.getPermissionValue());
case "lacksRole" -> permissionFlag = !permissionService.lacksRole(onlineMb.getPermissionValue());
case "hasAnyRoles" -> permissionFlag = permissionService.hasAnyRoles(onlineMb.getPermissionValue());
}
}
if (!permissionFlag) {
return AjaxResult.error(403,"没有权限,请联系管理员授权");
}
if (onlineMb.getDeptId() != null && onlineMb.getDeptId().equals("1")) {
object.put("deptId", SecurityUtils.getDeptId());
}
if (onlineMb.getUserId() != null && onlineMb.getUserId().equals("1")) {
object.put("userId", SecurityUtils.getUserId());
}
String sql = "<script>\n" + onlineMb.getSql() + "\n</script>"; String sql = "<script>\n" + onlineMb.getSql() + "\n</script>";
SqlSession sqlSession = sqlSessionFactory.openSession(); SqlSession sqlSession = sqlSessionFactory.openSession();
SqlMapper sqlMapper = new SqlMapper(sqlSession); SqlMapper sqlMapper = new SqlMapper(sqlSession);
@ -75,7 +105,7 @@ public class OnLineController extends BaseController {
case "selectOne" -> success(sqlMapper.selectOne(sql, object)); case "selectOne" -> success(sqlMapper.selectOne(sql, object));
case "update" -> toAjax(sqlMapper.update(sql, object)); case "update" -> toAjax(sqlMapper.update(sql, object));
case "delete" -> toAjax(sqlMapper.delete(sql, object)); case "delete" -> toAjax(sqlMapper.delete(sql, object));
default -> error("错误的执行器"); default -> AjaxResult.error(500,"系统错误,执行器错误");
}; };
} }
} }

View File

@ -15,200 +15,190 @@ import io.swagger.v3.oas.annotations.media.Schema;
* @date 2024-01-26 * @date 2024-01-26
*/ */
@Schema(description = "mybatis在线接口对象") @Schema(description = "mybatis在线接口对象")
public class OnlineMb extends BaseEntity public class OnlineMb extends BaseEntity {
{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 主键 */ /** 主键 */
@Schema(defaultValue = "主键") @Schema(defaultValue = "主键")
private Long mbId; private Long mbId;
/** 标签名 */ /** 标签名 */
@Schema(defaultValue = "标签名") @Schema(defaultValue = "标签名")
@Excel(name = "标签名") @Excel(name = "标签名")
private String tag; private String tag;
/** 标签id */ /** 标签id */
@Schema(defaultValue = "标签id") @Schema(defaultValue = "标签id")
@Excel(name = "标签id") @Excel(name = "标签id")
private String tagId; private String tagId;
/** 参数类型 */ /** 参数类型 */
@Schema(defaultValue = "参数类型") @Schema(defaultValue = "参数类型")
@Excel(name = "参数类型") @Excel(name = "参数类型")
private String parameterType; private String parameterType;
/** 结果类型 */ /** 结果类型 */
@Schema(defaultValue = "结果类型") @Schema(defaultValue = "结果类型")
@Excel(name = "结果类型") @Excel(name = "结果类型")
private String resultMap; private String resultMap;
/** sql语句 */ /** sql语句 */
@Schema(defaultValue = "sql语句") @Schema(defaultValue = "sql语句")
@Excel(name = "sql语句") @Excel(name = "sql语句")
private String sql; private String sql;
/** 请求路径 */ /** 请求路径 */
@Schema(defaultValue = "请求路径") @Schema(defaultValue = "请求路径")
@Excel(name = "请求路径") @Excel(name = "请求路径")
private String path; private String path;
/** 请求方式 */ /** 请求方式 */
@Schema(defaultValue = "请求方式") @Schema(defaultValue = "请求方式")
@Excel(name = "请求方式") @Excel(name = "请求方式")
private String method; private String method;
/** 响应类型 */ /** 响应类型 */
@Schema(defaultValue = "响应类型") @Schema(defaultValue = "响应类型")
@Excel(name = "响应类型") @Excel(name = "响应类型")
private String resultType; private String resultType;
/** 执行器 */ /** 执行器 */
@Schema(defaultValue = "执行器") @Schema(defaultValue = "执行器")
@Excel(name = "执行器") @Excel(name = "执行器")
private String actuator; private String actuator;
/** 是否需要userId */
@Schema(defaultValue = "是否需要userId")
@Excel(name = "是否需要userId")
private String userId;
/** 是否需要deptId */
@Schema(defaultValue = "是否需要deptId")
@Excel(name = "是否需要deptId")
private String deptId;
public void setMbId(Long mbId) /** 许可类型 */
{ @Schema(defaultValue = "许可类型")
@Excel(name = "许可类型")
private String permissionType;
/** 许可值 */
@Schema(defaultValue = "许可值")
@Excel(name = "许可值")
private String permissionValue;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getDeptId() {
return deptId;
}
public void setDeptId(String deptId) {
this.deptId = deptId;
}
public String getPermissionType() {
return permissionType;
}
public void setPermissionType(String permissionType) {
this.permissionType = permissionType;
}
public String getPermissionValue() {
return permissionValue;
}
public void setPermissionValue(String permissionValue) {
this.permissionValue = permissionValue;
}
public void setMbId(Long mbId) {
this.mbId = mbId; this.mbId = mbId;
} }
public Long getMbId() public Long getMbId() {
{
return mbId; return mbId;
} }
public void setTag(String tag) {
public void setTag(String tag)
{
this.tag = tag; this.tag = tag;
} }
public String getTag() public String getTag() {
{
return tag; return tag;
} }
public void setTagId(String tagId) {
public void setTagId(String tagId)
{
this.tagId = tagId; this.tagId = tagId;
} }
public String getTagId() public String getTagId() {
{
return tagId; return tagId;
} }
public void setParameterType(String parameterType) {
public void setParameterType(String parameterType)
{
this.parameterType = parameterType; this.parameterType = parameterType;
} }
public String getParameterType() public String getParameterType() {
{
return parameterType; return parameterType;
} }
public void setResultMap(String resultMap) {
public void setResultMap(String resultMap)
{
this.resultMap = resultMap; this.resultMap = resultMap;
} }
public String getResultMap() public String getResultMap() {
{
return resultMap; return resultMap;
} }
public void setSql(String sql) {
public void setSql(String sql)
{
this.sql = sql; this.sql = sql;
} }
public String getSql() public String getSql() {
{
return sql; return sql;
} }
public void setPath(String path) {
public void setPath(String path)
{
this.path = path; this.path = path;
} }
public String getPath() public String getPath() {
{
return path; return path;
} }
public void setMethod(String method) {
public void setMethod(String method)
{
this.method = method; this.method = method;
} }
public String getMethod() public String getMethod() {
{
return method; return method;
} }
public void setResultType(String resultType) {
public void setResultType(String resultType)
{
this.resultType = resultType; this.resultType = resultType;
} }
public String getResultType() public String getResultType() {
{
return resultType; return resultType;
} }
public void setActuator(String actuator) {
public void setActuator(String actuator)
{
this.actuator = actuator; this.actuator = actuator;
} }
public String getActuator() public String getActuator() {
{
return actuator; return actuator;
} }
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
@ -222,6 +212,10 @@ public class OnlineMb extends BaseEntity
.append("method", getMethod()) .append("method", getMethod())
.append("resultType", getResultType()) .append("resultType", getResultType())
.append("actuator", getActuator()) .append("actuator", getActuator())
.append("userId",getUserId())
.append("deptId",getDeptId())
.append("permissionType",getPermissionType())
.append("permissionValue",getPermissionValue())
.toString(); .toString();
} }
} }