TicketController.java
1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.meishu.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.meishu.model.AuthTicket;
import com.meishu.service.AuthTicketService;
import com.meishu.util.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
/**
* 三方验证ticket
*/
@RestController
@RequestMapping("/auth")
public class TicketController {
@Resource
private AuthTicketService ticketService;
@GetMapping("/verifyTicket")
public Result verifyTicket(String ticket) {
LambdaQueryWrapper<AuthTicket> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AuthTicket::getTicket, ticket);
AuthTicket t = ticketService.getOne(wrapper);
if (t == null) return Result.fail("Ticket不存在");
if (t.getUsed() == 1) return Result.fail("Ticket已使用");
if (t.getExpireTime().isBefore(LocalDateTime.now())) return Result.fail("Ticket已过期");
// 标记已使用
t.setUsed(1);
ticketService.updateById(t);
Map<String, String> map = new HashMap<>();
map.put("username", t.getUsername());
map.put("platform", t.getPlatform());
return Result.success(map);
}
}