Quellcode durchsuchen

公众号-自动回复

wangyunpeng vor 3 Monaten
Ursprung
Commit
b1c2efaacc

+ 20 - 10
api-module/src/main/java/com/tzld/piaoquan/api/remote/AigcApiService.java

@@ -1,7 +1,9 @@
 package com.tzld.piaoquan.api.remote;
 
 import com.alibaba.fastjson.JSONObject;
+import com.tzld.piaoquan.api.common.exception.CommonException;
 import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
+import com.tzld.piaoquan.growth.common.utils.DateUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -52,7 +54,7 @@ public class AigcApiService {
             JSONObject data = res.getJSONObject("data");
             return data.getString("qrcodeStr");
         } catch (Exception e) {
-            log.error("getVideoDetailRequest error", e);
+            log.error("generateQrcode error", e);
         }
         return null;
     }
@@ -70,7 +72,7 @@ public class AigcApiService {
             JSONObject data = res.getJSONObject("data");
             return data.getString("id");
         } catch (Exception e) {
-            log.error("getVideoDetailRequest error", e);
+            log.error("getAuthResult error", e);
         }
         return null;
     }
@@ -84,7 +86,7 @@ public class AigcApiService {
             JSONObject res = JSONObject.parseObject(post);
             return res.getJSONObject("data");
         } catch (Exception e) {
-            log.error("getVideoDetailRequest error", e);
+            log.error("getAccountDetail error", e);
         }
         return null;
     }
@@ -92,18 +94,26 @@ public class AigcApiService {
     public String createPublishPlan(String publishAccountId, String name) {
         String url = aigcApiHost + "/publish/plan/save";
         JSONObject params = getPublishPlanAddParam(publishAccountId, name);
+        JSONObject res = null;
         try {
             String post = httpPoolClient.post(url, getAigcPostParam(params));
-            JSONObject res = JSONObject.parseObject(post);
-            JSONObject data = res.getJSONObject("data");
-            return data.getString("id");
+            res = JSONObject.parseObject(post);
         } catch (Exception e) {
-            log.error("getVideoDetailRequest error", e);
+            log.error("createPublishPlan error", e);
         }
-        return null;
+        if (Objects.isNull(res)) {
+            throw new CommonException(3000, "创建计划失败,请稍后重试");
+        }
+        Integer code = res.getInteger("code");
+        if (code != 0) {
+            throw new CommonException(3000, res.getString("msg"));
+        }
+        JSONObject data = res.getJSONObject("data");
+        return data.getString("id");
     }
 
     private JSONObject getPublishPlanAddParam(String publishAccountId, String name) {
+        String dateStr = DateUtil.getCurrentDateStr("yyyyMMdd");
         JSONObject params = JSONObject.parseObject("{\n" +
                 "    \"accountIds\": [\n" +
                 "        \"" + publishAccountId + "\"\n" +
@@ -114,7 +124,7 @@ public class AigcApiService {
                 "    \"contentModal\": 7,\n" +
                 "    \"douyinPublishAccoutSetting\": [],\n" +
                 "    \"filterMatchMode\": 1,\n" +
-                "    \"name\": \" 自动回复-" + name + "\",\n" +
+                "    \"name\": \"自动回复-" + dateStr + "-" + name + "\",\n" +
                 "    \"publishAccoutJson\": \"\",\n" +
                 "    \"publishBgmType\": 0,\n" +
                 "    \"publishDate\": \"\",\n" +
@@ -163,7 +173,7 @@ public class AigcApiService {
             String post = httpPoolClient.post(url, getAigcPostParam(params));
             JSONObject res = JSONObject.parseObject(post);
         } catch (Exception e) {
-            log.error("getVideoDetailRequest error", e);
+            log.error("closePublishPlan error", e);
         }
     }
 }

+ 7 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/utils/DateUtil.java

@@ -1,6 +1,7 @@
 package com.tzld.piaoquan.growth.common.utils;
 
 
+import java.text.SimpleDateFormat;
 import java.time.Instant;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -13,6 +14,12 @@ import java.util.TimeZone;
 
 public class DateUtil {
 
+    public static String getCurrentDateStr(String format) {
+        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
+        Date currentDate = new Date();
+        return dateFormat.format(currentDate);
+    }
+
     //获取当天的日期
     public static Date getThatDayDate() {
         Calendar calendar = Calendar.getInstance();