diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/interactions/MjClient.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/interactions/MjClient.java index 87b68b909..67ce684f2 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/interactions/MjClient.java +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/interactions/MjClient.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.framework.ai.midjourney.interactions; +import cn.iocoder.yudao.framework.ai.midjourney.MidjourneyConfig; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -18,16 +19,18 @@ public class MjClient { private static RestTemplate restTemplate = new RestTemplate(); private static HttpHeaders headers = new HttpHeaders(); + private static final String HEADER_REFERER = "https://discord.com/channels/%s/%s"; + static { headers.setContentType(MediaType.APPLICATION_JSON); // 设置内容类型为JSON - headers.set("Referer", "https://discord.com/channels/1221445697157468200/1221445862962630706"); headers.set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"); headers.set("Cookie", "__dcfduid=6ca536c0e3fa11eeb7cbe34c31b49caf; __sdcfduid=6ca536c1e3fa11eeb7cbe34c31b49caf52cce5ffd8983d2a052cf6aba75fe5fe566f2c265902e283ce30dbf98b8c9c93; _gcl_au=1.1.245923998.1710853617; _ga=GA1.1.111061823.1710853617; __cfruid=6385bb3f48345a006b25992db7dcf984e395736d-1712124666; _cfuvid=O09la5ms0ypNptiG0iD8A6BKWlTxz1LG0WR7qRStD7o-1712124666575-0.0.1.1-604800000; locale=zh-CN; cf_clearance=l_YGod1_SUtYxpDVeZXiX7DLLPl1DYrquZe8WVltvYs-1712124668-1.0.1.1-Hl2.fToel23EpF2HCu9J20rB4D7OhhCzoajPSdo.9Up.wPxhvq22DP9RHzEBKuIUlKyH.kJLxXJfAt2N.LD5WQ; OptanonConsent=isIABGlobal=false&datestamp=Wed+Apr+03+2024+14%3A11%3A15+GMT%2B0800+(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)&version=6.33.0&hosts=&landingPath=https%3A%2F%2Fdiscord.com%2F&groups=C0001%3A1%2CC0002%3A1%2CC0003%3A1; _ga_Q149DFWHT7=GS1.1.1712124668.4.1.1712124679.0.0.0"); } - public static String post(String url, String token, String body) { - // 设置token - headers.set("Authorization", token); + public static String post(String url, MidjourneyConfig config, String body) { + // 设置 header + headers.set("Referer", String.format(HEADER_REFERER, config.getGuildId(), config.getChannelId())); + headers.set("Authorization", config.getToken()); // 封装请求体和头部信息 HttpEntity requestEntity = new HttpEntity<>(body, headers); // 发送请求 diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/interactions/MjInteractions.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/interactions/MjInteractions.java index 81bb749cd..1a4d0d817 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/interactions/MjInteractions.java +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/interactions/MjInteractions.java @@ -40,7 +40,7 @@ public class MjInteractions { // 设置参数 String requestBody = MjClient.setParams(requestTemplate, requestParams); // 发送请求 - String res = MjClient.post(url, midjourneyConfig.getToken(), requestBody); + String res = MjClient.post(url, midjourneyConfig, requestBody); // 这个 res 只要不返回值,就是成功! boolean isSuccess = StrUtil.isBlank(res); if (isSuccess) { @@ -64,7 +64,7 @@ public class MjInteractions { // 设置参数 String requestBody = MjClient.setParams(requestTemplate, requestParams); // 发送请求 - String res = MjClient.post(url, midjourneyConfig.getToken(), requestBody); + String res = MjClient.post(url, midjourneyConfig, requestBody); // 这个 res 只要不返回值,就是成功! boolean isSuccess = StrUtil.isBlank(res); if (isSuccess) {