diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/MidjourneyProxyClient.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/MidjourneyProxyClient.java index efba5234b..b68310700 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/MidjourneyProxyClient.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/MidjourneyProxyClient.java @@ -1,10 +1,12 @@ package cn.iocoder.yudao.module.ai.client; +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.ai.client.vo.MidjourneyImagineReqVO; import cn.iocoder.yudao.module.ai.client.vo.MidjourneySubmitRespVO; import jakarta.validation.constraints.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.*; import org.springframework.stereotype.Component; import org.springframework.validation.annotation.Validated; import org.springframework.web.client.RestTemplate; @@ -35,7 +37,15 @@ public class MidjourneyProxyClient { * @return */ public MidjourneySubmitRespVO imagine(@Validated @NotNull MidjourneyImagineReqVO imagineReqVO) { - return restTemplate.postForObject(url.concat(URI_IMAGINE), imagineReqVO, MidjourneySubmitRespVO.class); + // 创建 HttpHeaders 对象 + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.set("Authorization", "Bearer sk-c3qxUCVKsPfdQiYU8440E3Fc8dE5424d9cB124A4Ee2489E3"); + // 创建 HttpEntity 对象,将 HttpHeaders 和请求体传递给它 + HttpEntity requestEntity = new HttpEntity<>(JsonUtils.toJsonString(imagineReqVO), headers); + // 发送 post 请求 + ResponseEntity response = restTemplate.exchange(url.concat(URI_IMAGINE), HttpMethod.POST, requestEntity, String.class); + return JsonUtils.parseObject(response.getBody(), MidjourneySubmitRespVO.class); } } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/vo/MidjourneyNotifyReqVO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/vo/MidjourneyNotifyReqVO.java index 3cc92c719..4398a8272 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/vo/MidjourneyNotifyReqVO.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/vo/MidjourneyNotifyReqVO.java @@ -19,7 +19,7 @@ public class MidjourneyNotifyReqVO { @Schema(description = "任务类型") private MidjourneyTaskActionEnum action; @Schema(description = "任务状态") - private MidjourneyTaskStatusEnum status = MidjourneyTaskStatusEnum.NOT_START; + private MidjourneyTaskStatusEnum status; @Schema(description = "提示词") private String prompt; diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java index 0f2116a0f..32e2e73fa 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java @@ -15,6 +15,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; +import jakarta.annotation.security.PermitAll; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -70,10 +71,10 @@ public class AiImageController { return success(imageService.midjourneyImagine(getLoginUserId(), req)); } - // TODO @芋艿:不拦截 @Operation(summary = "midjourney proxy - 回调通知") - @RequestMapping("/midjourney-notify") - public CommonResult midjourneyNotify(MidjourneyNotifyReqVO notifyReqVO) { + @PostMapping("/midjourney-notify") + @PermitAll + public CommonResult midjourneyNotify( @RequestBody MidjourneyNotifyReqVO notifyReqVO) { return success(imageService.midjourneyNotify(getLoginUserId(), notifyReqVO)); } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java index ea52dd42b..208427bc0 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java @@ -212,7 +212,6 @@ public class AiImageServiceImpl implements AiImageService { .setId(image.getId()) .setStatus(imageStatus) .setPicUrl(filePath) -// .setOriginalPicUrl(notifyReqVO.getImageUrl()) TODO @fan:就不存原始的图片地址啦 ); return true; } diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index 99c888f31..d4b7530d6 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -76,6 +76,13 @@ server: enabled: true charset: UTF-8 force: true +# ai +ai: + midjourney-proxy: + url: https://api.holdai.top/mj + notifyUrl: http://7b1aada4.r26.cpolar.top/admin-api/ai/image/midjourney-notify + + --- #################### 定时任务相关配置 #################### # Quartz 配置项,对应 QuartzProperties 配置类