#消息推送相关

This commit is contained in:
2026-10-29 09:10:26 +08:00
parent 965b38158f
commit e501d58563
8 changed files with 123 additions and 65 deletions

View File

@@ -7,13 +7,14 @@ import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;
import com.maibu.constant.Constants;
@Service
public class HttpService {
@Autowired
private RestTemplate restTemplate;
/**
* 通用 GET 请求(手动传入 Token,每次可传不同值)
*
@@ -32,8 +33,7 @@ public class HttpService {
apiUrl,
HttpMethod.GET,
httpEntity,
String.class
);
String.class);
// 校验响应状态并返回结果
if (response.getStatusCode().is2xxSuccessful()) {
return response.getBody() == null ? "" : response.getBody();
@@ -68,8 +68,7 @@ public class HttpService {
apiUrl,
HttpMethod.POST,
httpEntity,
String.class
);
String.class);
// 校验响应状态并返回结果
if (response.getStatusCode().is2xxSuccessful()) {
return response.getBody() == null ? "" : response.getBody();
@@ -93,18 +92,18 @@ public class HttpService {
*/
private HttpHeaders buildHeadersWithToken(String token) {
HttpHeaders headers = new HttpHeaders();
// 设置默认 Content-Type 为 JSON 格式
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("Accept", "application/json");
// 若 Token 不为空,添加 Authorization 头(默认 Bearer 格式,可按需修改)
// 与 LanguageInterceptor 读取的请求头保持一致
headers.set(Constants.LANGUAGE, "zh-CN");
if (token != null && !token.trim().isEmpty()) {
// 如需去掉 Bearer 前缀,直接改为 headers.set("Authorization", token.trim())
headers.set("Authorization", "Bearer " + token.trim());
}
// 可按需添加其他通用请求头(如 User-Agent)
// headers.set("User-Agent", "RestTemplate-Common/1.0");
return headers;
}
}