TASK:flux积分不足,邮件通知

This commit is contained in:
2025-12-11 16:07:14 +08:00
parent 5c2008ec4a
commit 94cafbd10c
2 changed files with 56 additions and 2 deletions

View File

@@ -88,7 +88,7 @@ public class SendRequestUtil {
}
}
public String sendFluxPost(String url, String requestBodyStr){
/*public String sendFluxPost(String url, String requestBodyStr){
int status;
String body;
try (HttpResponse execute = HttpRequest.post(url)
@@ -103,9 +103,63 @@ public class SendRequestUtil {
if (status == 200) {
return body;
}
if (status == 402 || status == 403) {
SendEmailUtil.commonExceptionReminder("Flux账户积分不足flux生成任务",
new String[]{"xupei3360@163.com, fangjianliao@aidlab.hk, investigation@aidlab.hk"});
}
}
log.warn("请求失败,状态码为 {}", status);
return null;
}*/
public String sendFluxPost(String url, String requestBodyStr) {
// 尝试两个API key
String[] apiKeys = {"d447a0ac-2291-4f1c-9a36-f7614c385989",
"84e8f5d5-b0b3-49aa-b244-ab7ba27e7ae7"};
boolean[] notified = {false, false}; // 记录是否已发送过不足提醒
for (int i = 0; i < apiKeys.length; i++) {
int status;
String body;
try (HttpResponse execute = HttpRequest.post(url)
.header(Header.CONTENT_TYPE, "application/json")
.header("x-key", apiKeys[i])
.body(requestBodyStr)
.timeout(180000)
.execute()) {
status = execute.getStatus();
body = execute.body();
if (status == 200) {
return body;
}
// 余额不足处理
if (status == 402 || status == 403) {
if (!notified[i]) {
SendEmailUtil.commonExceptionReminder(
"Flux账户积分不足flux生成任务失败",
new String[]{"xupei3360@163.com, fangjianliao@aidlab.hk, investigation@aidlab.hk"}
);
notified[i] = true;
}
continue; // 尝试下一个key
}
// 其他错误直接返回null
log.warn("请求失败,状态码为:{}使用key{}", status, apiKeys[i]);
return null;
} catch (Exception e) {
log.error("请求异常使用key{}", apiKeys[i], e);
if (i == apiKeys.length - 1) return null; // 最后一个key也失败则返回null
}
}
log.warn("所有API key均余额不足");
return null;
}
public String sendPost(String url, String requestBodyStr){

View File

@@ -70,7 +70,7 @@ public class StripeController {
Long size = redisUtil.getSize(key_1);
// 给我发送邮件
if (webhookReminderFlag.equals("1") && size == 3){
SendEmailUtil.commonExceptionReminder("Stripe Webhook 回调", new String[]{"xupei3360@163.com"});
SendEmailUtil.commonExceptionReminder("Stripe Webhook 回调处理出现异常", new String[]{"xupei3360@163.com"});
}
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}