TASK: 更换第三方access key获取方式,从系统变量中获取改为从配置文件中获取
This commit is contained in:
@@ -14,14 +14,14 @@ import org.springframework.stereotype.Component;
|
|||||||
public class SendRequestUtil {
|
public class SendRequestUtil {
|
||||||
|
|
||||||
@Value("${ALIYUN_API_KEY}")
|
@Value("${ALIYUN_API_KEY}")
|
||||||
private String AliYunAPIKey;
|
private String ALIYUN_API_KEY;
|
||||||
@Value("${FREEPIK_API_KEY}")
|
@Value("${FREEPIK_API_KEY}")
|
||||||
private String freepikAPIKey;
|
private String FREEPIK_API_KEY;
|
||||||
|
|
||||||
public String sendAliYunPostAsync(String apiUrl, String requestBody){
|
public String sendAliYunPostAsync(String apiUrl, String requestBody){
|
||||||
// 发送POST请求 todo 异常处理
|
// 发送POST请求 todo 异常处理
|
||||||
HttpResponse execute = HttpRequest.post(apiUrl)
|
HttpResponse execute = HttpRequest.post(apiUrl)
|
||||||
.header(Header.AUTHORIZATION, "Bearer " + AliYunAPIKey)
|
.header(Header.AUTHORIZATION, "Bearer " + ALIYUN_API_KEY)
|
||||||
.header("X-DashScope-Async", "enable")
|
.header("X-DashScope-Async", "enable")
|
||||||
.header(Header.CONTENT_TYPE, "application/json")
|
.header(Header.CONTENT_TYPE, "application/json")
|
||||||
.body(requestBody)
|
.body(requestBody)
|
||||||
@@ -42,7 +42,7 @@ public class SendRequestUtil {
|
|||||||
// 发送POST请求 todo 异常处理
|
// 发送POST请求 todo 异常处理
|
||||||
HttpResponse execute = HttpRequest.post(FREE_PIK)
|
HttpResponse execute = HttpRequest.post(FREE_PIK)
|
||||||
.header(Header.CONTENT_TYPE, "application/json")
|
.header(Header.CONTENT_TYPE, "application/json")
|
||||||
.header("x-freepik-api-key", freepikAPIKey)
|
.header("x-freepik-api-key", FREEPIK_API_KEY)
|
||||||
.body(requestBody)
|
.body(requestBody)
|
||||||
.timeout(20000) // 设置超时时间20秒
|
.timeout(20000) // 设置超时时间20秒
|
||||||
.execute();
|
.execute();
|
||||||
@@ -57,7 +57,7 @@ public class SendRequestUtil {
|
|||||||
public String sendAliYunGet(String fullUrl){
|
public String sendAliYunGet(String fullUrl){
|
||||||
// 发送GET请求 todo 异常处理
|
// 发送GET请求 todo 异常处理
|
||||||
HttpResponse httpResponse = HttpRequest.get(fullUrl)
|
HttpResponse httpResponse = HttpRequest.get(fullUrl)
|
||||||
.header(Header.AUTHORIZATION, "Bearer " + AliYunAPIKey)
|
.header(Header.AUTHORIZATION, "Bearer " + ALIYUN_API_KEY)
|
||||||
.timeout(20000) // 设置超时时间20秒
|
.timeout(20000) // 设置超时时间20秒
|
||||||
.execute();
|
.execute();
|
||||||
int status = httpResponse.getStatus();
|
int status = httpResponse.getStatus();
|
||||||
|
|||||||
@@ -119,6 +119,13 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
@Value("${ollama.url}")
|
@Value("${ollama.url}")
|
||||||
private String ollamaUrl;
|
private String ollamaUrl;
|
||||||
|
|
||||||
|
@Value("${ALIYUN_API_KEY}")
|
||||||
|
private String ALIYUN_API_KEY;
|
||||||
|
|
||||||
|
@Value("${FREEPIK_API_KEY}")
|
||||||
|
private String FREEPIK_API_KEY;
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private AccountService accountService;
|
private AccountService accountService;
|
||||||
|
|
||||||
@@ -1349,7 +1356,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
promptExtend.put("prompt_extend", false);
|
promptExtend.put("prompt_extend", false);
|
||||||
ImageSynthesisParam param =
|
ImageSynthesisParam param =
|
||||||
ImageSynthesisParam.builder()
|
ImageSynthesisParam.builder()
|
||||||
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
|
.apiKey(ALIYUN_API_KEY)
|
||||||
.model("wanx2.1-t2i-plus")
|
.model("wanx2.1-t2i-plus")
|
||||||
.prompt(prompt)
|
.prompt(prompt)
|
||||||
.n(1)
|
.n(1)
|
||||||
@@ -1449,7 +1456,6 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
private static final String TEMPLATE_ID_GEN = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/aa-template-generation/";
|
private static final String TEMPLATE_ID_GEN = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/aa-template-generation/";
|
||||||
private static final String GET_ASYNC_RESULT = "https://dashscope.aliyuncs.com/api/v1/tasks/";
|
private static final String GET_ASYNC_RESULT = "https://dashscope.aliyuncs.com/api/v1/tasks/";
|
||||||
private static final String ANIMATE = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis/";
|
private static final String ANIMATE = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis/";
|
||||||
private static final String API_KEY = System.getenv("DASHSCOPE_API_KEY"); // 替换为你的实际API密钥
|
|
||||||
public String animateAnyone(PoseTransformDTO poseTransformDTO, Long accountId){
|
public String animateAnyone(PoseTransformDTO poseTransformDTO, Long accountId){
|
||||||
|
|
||||||
accountId = 87L;
|
accountId = 87L;
|
||||||
@@ -1582,7 +1588,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
try {
|
try {
|
||||||
// 发送GET请求查询任务状态
|
// 发送GET请求查询任务状态
|
||||||
HttpResponse httpResponse = HttpRequest.get(GET_ASYNC_RESULT + taskId)
|
HttpResponse httpResponse = HttpRequest.get(GET_ASYNC_RESULT + taskId)
|
||||||
.header(Header.AUTHORIZATION, "Bearer " + API_KEY)
|
.header(Header.AUTHORIZATION, "Bearer " + ALIYUN_API_KEY)
|
||||||
.timeout(10000)
|
.timeout(10000)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user