package com.fzzy.gateway.hx2023.controller;
|
|
import com.alibaba.fastjson2.JSONObject;
|
import com.fzzy.api.utils.ContextUtil;
|
import com.fzzy.api.utils.RedisConst;
|
import com.fzzy.api.utils.RedisUtil;
|
import com.fzzy.gateway.hx2023.data.GatewayAuthData;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
|
/**
|
*
|
*/
|
@Slf4j
|
@Controller
|
@RequestMapping("/sc2023/gateway")
|
public class GatewayController {
|
|
@Resource
|
private RedisUtil redisUtil;
|
|
/**
|
* 鉴权接口
|
*
|
* @return {
|
* "message": "成功",
|
* "result": {
|
* "token":"b2919bed493eca1ee1efb8d3cfa08a"
|
* },
|
* "status": 0,
|
* "code": 200,
|
* "timestamp": 0
|
* }
|
*/
|
@PostMapping("/authorize/login")
|
public @ResponseBody
|
JSONObject authorize(@RequestBody GatewayAuthData data) {
|
|
log.debug("============鉴权==========={}--{}", data.getUsername(), data.getPassword());
|
|
|
//TODO 验证用户名和密码
|
|
|
String token = ContextUtil.getUUID();
|
|
this.updateGatewayToken(token, data.getUsername());
|
|
JSONObject json = new JSONObject();
|
|
JSONObject result = new JSONObject();
|
|
result.put("token", token);
|
|
json.put("result", result);
|
json.put("message", "成功");
|
json.put("status", 0);
|
json.put("code", 200);
|
json.put("timestamp", System.currentTimeMillis());
|
|
return json;
|
}
|
|
public void updateGatewayToken(String token, String username) {
|
String key = RedisConst.buildKey(RedisConst.KYE_GATE_TOKEN, username);
|
redisUtil.set(key, token);
|
}
|
|
public String getGatewayToken(String username) {
|
String key = RedisConst.buildKey(RedisConst.KYE_GATE_TOKEN, username);
|
return (String) redisUtil.get(key);
|
}
|
}
|