mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-09-29 16:06:36 +08:00
添加subStore接口
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user