用户结构修改以及openai获取客户端令牌

This commit is contained in:
2025-11-01 23:40:44 +08:00
parent ac4b144ad5
commit db72d08b98
20 changed files with 250 additions and 502 deletions

View File

@@ -13,6 +13,7 @@ import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
/**
* 共同 信息 服务实现类
@@ -24,13 +25,21 @@ import java.util.Map;
@Service
public class CommonServiceImpl implements ICommonService {
// OpenAI API密钥需要替换为你自己的密钥
@Value("${chatGpt.apiKey}")
private String apiKey;
// API端点URL
@Value("${chatGpt.apiClientTokenUrl}")
@Value("${whisper.apiClientTokenUrl}")
private String apiClientTokenUrl;
@Value("${whisper.model}")
private String MODEL;
@Value("${whisper.apiKey}")
private String apiKey;
@Value("${whisper.language}")
private String language;
@Value("${whisper.prompt}")
private String prompt;
/**
* 获取openAi客户端临时Key
* @return
@@ -46,8 +55,13 @@ public class CommonServiceImpl implements ICommonService {
.build();
// 2. 构建请求体(空 JSON 对象)
ObjectMapper objectMapper = new ObjectMapper();
String requestBody = "";
Map<String,Object> params = new HashMap<>();
Map<String, String> bodyEntity = new HashMap<>();
bodyEntity.put("model",MODEL);
bodyEntity.put("prompt",prompt);
bodyEntity.put("language",language);
params.put("input_audio_transcription",bodyEntity);
String requestBody = JSONUtil.toJsonStr(params);
// 3. 构建 HTTP 请求
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(apiClientTokenUrl))
@@ -65,8 +79,11 @@ public class CommonServiceImpl implements ICommonService {
// 解析响应为实体类
System.out.println(JSONUtil.toJsonStr(response.body()));
Map entity = JSONUtil.toBean(response.body(), Map.class);
dto.setClientSecret(entity.get("id").toString());
// dto.setExpiresAt(Long.valueOf(entity.get("expires_at").toString()));
if(entity.get("client_secret") != null) {
Map data = (Map) entity.get("client_secret");
dto.setClientSecret(data.get("value").toString());
dto.setExpiresAt(Long.valueOf(data.get("expires_at").toString()));
}
}
} catch (Exception e) {
e.printStackTrace();