mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-09-29 16:06:36 +08:00
添加subStore接口
This commit is contained in:
@@ -57,6 +57,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
registry.addInterceptor(jwtInterceptor())
|
||||
.addPathPatterns("/api/**")
|
||||
.excludePathPatterns("/flow/**")
|
||||
.excludePathPatterns("/api/v1/open_api/**")
|
||||
.excludePathPatterns("/api/v1/config/get")
|
||||
.excludePathPatterns("/api/v1/user/login");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.admin.controller;
|
||||
|
||||
|
||||
import com.admin.common.aop.LogAnnotation;
|
||||
import com.admin.common.lang.R;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.admin.common.utils.Md5Util;
|
||||
import com.admin.entity.User;
|
||||
import com.admin.entity.UserTunnel;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/v1/open_api")
|
||||
public class OpenApiController extends BaseController {
|
||||
|
||||
@LogAnnotation
|
||||
@GetMapping("/sub_store")
|
||||
public R create(
|
||||
@RequestParam("user") String user,
|
||||
@RequestParam("pwd") String pwd,
|
||||
@RequestParam(value = "tunnel", required = false, defaultValue = "-1") String tunnel,
|
||||
HttpServletResponse response) {
|
||||
|
||||
// 校验 user 是否为空
|
||||
if (user == null || user.isEmpty()) {
|
||||
return R.err("用户不能为空");
|
||||
}
|
||||
if (pwd == null || pwd.isEmpty()) {
|
||||
return R.err("密码不能为空");
|
||||
}
|
||||
|
||||
User userInfo = userService.getOne(new QueryWrapper<User>().eq("user", user));
|
||||
if (userInfo == null) {
|
||||
return R.err("鉴权失败");
|
||||
}
|
||||
|
||||
String pwdMd5 = Md5Util.md5(pwd);
|
||||
if (!Objects.equals(pwdMd5, userInfo.getPwd())) {
|
||||
return R.err("鉴权失败");
|
||||
}
|
||||
|
||||
final long GIGA = 1024L * 1024L * 1024L;
|
||||
String headerValue;
|
||||
|
||||
if ("-1".equals(tunnel)) {
|
||||
headerValue = buildSubscriptionHeader(
|
||||
userInfo.getOutFlow(),
|
||||
userInfo.getInFlow(),
|
||||
userInfo.getFlow() * GIGA,
|
||||
userInfo.getExpTime() / 1000
|
||||
);
|
||||
} else {
|
||||
UserTunnel tunnelInfo = userTunnelService.getById(tunnel);
|
||||
if (tunnelInfo == null) return R.err("隧道不存在");
|
||||
if (!tunnelInfo.getUserId().toString().equals(userInfo.getId().toString())) return R.err("隧道不存在");
|
||||
headerValue = buildSubscriptionHeader(
|
||||
tunnelInfo.getOutFlow(),
|
||||
tunnelInfo.getInFlow(),
|
||||
tunnelInfo.getFlow() * GIGA,
|
||||
tunnelInfo.getExpTime() / 1000
|
||||
);
|
||||
}
|
||||
|
||||
response.setHeader("ubscription-userinfo", headerValue);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String buildSubscriptionHeader(long upload, long download, long total, long expire) {
|
||||
return String.format("upload=%d;download=%d;total=%d;expire=%d", upload, download, total, expire);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.admin.entity;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@@ -18,6 +20,27 @@ public class User extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 创建时间(时间戳)
|
||||
*/
|
||||
private Long createdTime;
|
||||
|
||||
/**
|
||||
* 更新时间(时间戳)
|
||||
*/
|
||||
private Long updatedTime;
|
||||
|
||||
/**
|
||||
* 状态(0:正常,1:删除)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
private String user;
|
||||
|
||||
private String pwd;
|
||||
|
||||
Reference in New Issue
Block a user