Files
pqs/pqs-auth/src/main/java/com/njcn/auth/controller/JudgeThirdToken.java
2024-09-26 16:00:52 +08:00

80 lines
2.9 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.njcn.auth.controller;
import cn.hutool.json.JSONObject;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.DataStateEnum;
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;
import java.util.Objects;
/**
* @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有效性")
@ApiImplicitParam(name = "token", required = true)
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);
if (Objects.equals(resultJson.getInt("status"), DataStateEnum.ENABLE.getCode())) {
//成功
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
}
}
}