Java调用Midjourney进行AI画图原生版抓包实现支持中文( 三 )

readNowList(RoomInfo roomInfo, Discord discord) {OkHttpClient client = new OkHttpClient().newBuilder().build();Request request = new Request.Builder().url("https://discord.com/api/v9/channels/" + roomInfo.getDiscordChannelId() + "/messages?limit=50").get().addHeader("authority", "discord.com").addHeader("accept", "*/*").addHeader("accept-language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6").addHeader("authorization", discord.getAuthorization()).addHeader("cache-control", "no-cache").addHeader("cookie", discord.getCookie()).addHeader("pragma", "no-cache").addHeader("referer", "https://discord.com/channels/" + roomInfo.getDiscordGuildId() +"/" + roomInfo.getDiscordChannelId()).addHeader("sec-ch-ua", "\"Not_A Brand\";v=\"99\", \"Microsoft Edge\";v=\"109\", \"Chromium\";v=\"109\"").addHeader("sec-ch-ua-mobile", "?0").addHeader("sec-ch-ua-platform", "\"Windows\"").addHeader("sec-fetch-dest", "empty").addHeader("sec-fetch-mode", "cors").addHeader("sec-fetch-site", "same-origin").addHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.70").addHeader("x-debug-options", "bugReporterEnabled").addHeader("x-discord-locale", "zh-CN").addHeader("x-super-properties", discord.getSuperProperties()).build();try {Response response = client.newCall(request).execute();String string = Objects.requireNonNull(response.body()).string();response.close();return JSON.parseArray(string, MidMsg.class);} catch (Throwable t) {log.error("[发生意外 读取消息失败] room: {}", roomInfo);}return Lists.newArrayList();}@SneakyThrowspublic boolean sendMsg(String msg, RoomInfo roomInfo) {Discord discord = discordService.findById(roomInfo.getDiscordId());bigDecimal = bigDecimal.add(new BigDecimal(1000));OkHttpClient client = new OkHttpClient().newBuilder().build();RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("payload_json", "{\"type\":2,\"application_id\":\"936929561302675456\"," +"\"guild_id\":\"" + roomInfo.getDiscordGuildId() + "\"," +"\"channel_id\":\"" + roomInfo.getDiscordChannelId() + "\"," +"\"session_id\":\"" + discord.getSessionId() + "\"," +"\"data\":{\"version\":\"1077969938624553050\"," +"\"id\":\"938956540159881230\"," +"\"name\":\"imagine\"," +"\"type\":1,\"options\":[" +"{\"type\":3,\"name\":\"prompt\"," +"\"value\":\"" + TextUtil.cleanString(msg) + "\"}]," +"\"application_command\":" +"{\"id\":\"938956540159881230\",\"application_id\":\"936929561302675456\",\"version\":" +"\"1077969938624553050\",\"default_member_permissions\":null,\"type\":1,\"nsfw\":false," +"\"name\":\"imagine\",\"description\":\"Create images with Midjourney\",\"dm_permission\":true," +"\"contexts\":null,\"options\":[{\"type\":3,\"name\":\"prompt\"," +"\"description\":\"The prompt to imagine\",\"required\":true}]}," +"\"attachments\":[]},\"nonce\":\"" + bigDecimal.toString() + "\"} ").build();Request request = new Request.Builder().url("https://discord.com/api/v9/interactions").method("POST", body).addHeader("authority", "discord.com").addHeader("accept", "*/*").addHeader("accept-language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6").addHeader("authorization", discord.getAuthorization()).addHeader("cache-control", "no-cache").addHeader("cookie", discord.getCookie()).addHeader("origin", "https://discord.com").addHeader("pragma", "no-cache").addHeader("referer", "https://discord.com/channels/" + roomInfo.getDiscordGuildId() +"/" + roomInfo.getDiscordChannelId()).addHeader("sec-ch-ua", "\"Not_A Brand\";v=\"99\", \"Microsoft Edge\";v=\"109\", \"Chromium\";v=\"109\"").addHeader("sec-ch-ua-mobile", "?0").addHeader("sec-ch-ua-platform", "\"Windows\"").addHeader("sec-fetch-dest", "empty").addHeader("sec-fetch-mode", "cors").addHeader("sec-fetch-site", "same-origin").addHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.70").addHeader("x-debug-options", "bugReporterEnabled").addHeader("x-discord-locale", "zh-CN").addHeader("x-super-properties", discord.getSuperProperties()).build();Response response = client.newCall(request).execute();if (response.code() == 204) {roomInfoService.addOnce(roomInfo);response.close();return true;}response.close();log.info("[midjourney发消息失败] {}", response.code());return false;}}