2022-06-21 20:47:46 +08:00
|
|
|
|
package com.njcn.auth.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
|
|
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
2024-09-26 16:00:52 +08:00
|
|
|
|
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
2022-06-21 20:47:46 +08:00
|
|
|
|
import com.njcn.common.pojo.enums.common.LogEnum;
|
|
|
|
|
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
|
|
|
|
|
import com.njcn.common.pojo.response.HttpResult;
|
|
|
|
|
|
import com.njcn.common.utils.HttpResultUtil;
|
|
|
|
|
|
import com.njcn.common.utils.LogUtil;
|
|
|
|
|
|
import com.njcn.web.controller.BaseController;
|
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
2024-09-26 16:00:52 +08:00
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
2022-06-21 20:47:46 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @author hongawen
|
|
|
|
|
|
* @version 1.0.0
|
|
|
|
|
|
* @date 2022年04月27日 11:22
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
|
@RestController
|
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
|
@Api(tags = "校验第三方token")
|
|
|
|
|
|
@RequestMapping("/judgeToken")
|
|
|
|
|
|
public class JudgeThirdToken extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 校验广州超高压token有效性
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param token token数据
|
|
|
|
|
|
*/
|
|
|
|
|
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
|
|
|
|
|
@PostMapping("/guangZhou")
|
|
|
|
|
|
@ApiOperation("校验广州超高压token有效性")
|
2024-09-26 16:00:52 +08:00
|
|
|
|
@ApiImplicitParam(name = "token", required = true)
|
2022-06-21 20:47:46 +08:00
|
|
|
|
public HttpResult<Object> guangZhou(String token) {
|
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
|
String methodDescribe = getMethodDescribe("guangZhou");
|
|
|
|
|
|
LogUtil.njcnDebug(log, "{},token:{}", methodDescribe, token);
|
|
|
|
|
|
|
|
|
|
|
|
// 请求地址
|
|
|
|
|
|
String url = "http://10.121.17.9:9080/ehv/auth_valid";
|
|
|
|
|
|
|
|
|
|
|
|
// 请求头设置,x-www-form-urlencoded格式的数据
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
|
|
|
|
|
|
|
|
|
|
//提交参数设置
|
|
|
|
|
|
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
|
|
|
|
|
map.add("token", token);
|
|
|
|
|
|
|
|
|
|
|
|
// 组装请求体
|
|
|
|
|
|
HttpEntity<MultiValueMap<String, String>> request =
|
|
|
|
|
|
new HttpEntity<>(map, headers);
|
|
|
|
|
|
|
|
|
|
|
|
// 发送post请求,并打印结果,以String类型接收响应结果JSON字符串
|
|
|
|
|
|
String result = restTemplate.postForObject(url, request, String.class);
|
|
|
|
|
|
JSONObject resultJson = new JSONObject(result);
|
2024-09-26 16:00:52 +08:00
|
|
|
|
if (Objects.equals(resultJson.getInt("status"), DataStateEnum.ENABLE.getCode())) {
|
2022-06-21 20:47:46 +08:00
|
|
|
|
//成功
|
|
|
|
|
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|