- 实现环境配置管理,支持外部和本地主机模式切换 - 集成Demo API接口,包含登录、注册、文件上传等功能 - 构建附件处理仓库,支持图片、视频、音频和文件发送 - 开发认证仓库,管理用户会话和IM令牌刷新机制 - 添加语音录制功能,支持实时音频消息录制 - 创建依赖注入容器,统一管理应用组件实例 - 实现登录界面,提供用户认证交互功能 - 开发聊天界面,集成消息收发和媒体处理功能
59 行
2.1 KiB
Java
59 行
2.1 KiB
Java
package com.xuqm.im.service;
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.http.HttpEntity;
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpMethod;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
@Component
|
|
public class ImFeatureConfigClient {
|
|
|
|
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
|
|
|
private final RestTemplate restTemplate;
|
|
|
|
@Value("${im.tenant-service-url:http://192.168.116.9:8081}")
|
|
private String tenantServiceUrl;
|
|
|
|
@Value("${im.internal-token:xuqm-internal-token}")
|
|
private String internalToken;
|
|
|
|
public ImFeatureConfigClient() {
|
|
this.restTemplate = new RestTemplate();
|
|
}
|
|
|
|
public boolean allowStrangerMessage(String appId) {
|
|
String url = UriComponentsBuilder.fromHttpUrl(tenantServiceUrl)
|
|
.path("/api/internal/sdk/apps/{appId}/services/{platform}/{serviceType}")
|
|
.buildAndExpand(appId, "ANDROID", "IM")
|
|
.toUriString();
|
|
HttpHeaders headers = new HttpHeaders();
|
|
headers.set("X-Internal-Token", internalToken);
|
|
try {
|
|
ResponseEntity<JsonNode> response = restTemplate.exchange(
|
|
url,
|
|
HttpMethod.GET,
|
|
new HttpEntity<>(headers),
|
|
JsonNode.class
|
|
);
|
|
JsonNode body = response.getBody();
|
|
if (response.getStatusCode().is2xxSuccessful() && body != null && body.path("code").asInt() == 200) {
|
|
String config = body.path("data").path("config").asText("");
|
|
if (config.isBlank()) {
|
|
return false;
|
|
}
|
|
return OBJECT_MAPPER.readTree(config).path("allowStrangerMessage").asBoolean(false);
|
|
}
|
|
} catch (Exception e) {
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
}
|