AigcApiService.java 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package com.tzld.piaoquan.api.component;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.tzld.piaoquan.api.common.exception.CommonException;
  4. import com.tzld.piaoquan.api.model.vo.WxAccountDatastatVO;
  5. import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
  6. import com.tzld.piaoquan.growth.common.utils.DateUtil;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.beans.factory.annotation.Value;
  10. import org.springframework.stereotype.Component;
  11. import java.util.List;
  12. import java.util.Objects;
  13. @Slf4j
  14. @Component
  15. public class AigcApiService {
  16. @Autowired
  17. private HttpPoolClient httpPoolClient;
  18. @Value("${aigc.api.host:http://aigc-api.cybertogether.net/aigc}")
  19. private String aigcApiHost;
  20. @Value("${aigc.api.token:9ebfcb397e954c41986971f183eb1707}")
  21. private String aigcApiToken;
  22. private String getAigcPostParam(JSONObject params) {
  23. JSONObject baseInfo = JSONObject.parseObject("{\n" +
  24. " \"token\": \"" + aigcApiToken + "\",\n" +
  25. " \"appType\": 9,\n" +
  26. " \"platform\": \"pc\",\n" +
  27. " \"appVersionCode\": 1000,\n" +
  28. " \"clientTimestamp\": 1,\n" +
  29. " \"fid\": 1,\n" +
  30. " \"loginUid\": 1,\n" +
  31. " \"pageSource\": 1,\n" +
  32. " \"requestId\": 1,\n" +
  33. " \"rid\": 1,\n" +
  34. " \"uid\": 1\n" +
  35. "}");
  36. JSONObject param = new JSONObject();
  37. param.put("params", params);
  38. param.put("baseInfo", baseInfo);
  39. return param.toJSONString();
  40. }
  41. public String generateQrcode(String uuid) {
  42. String url = aigcApiHost + "/publish/account/generateQrcode";
  43. JSONObject params = new JSONObject();
  44. params.put("uuid", uuid);
  45. try {
  46. String post = httpPoolClient.post(url, getAigcPostParam(params));
  47. JSONObject res = JSONObject.parseObject(post);
  48. JSONObject data = res.getJSONObject("data");
  49. return data.getString("qrcodeStr");
  50. } catch (Exception e) {
  51. log.error("generateQrcode error", e);
  52. }
  53. return null;
  54. }
  55. public String getAuthResult(String uuid) {
  56. String url = aigcApiHost + "/publish/account/authResult";
  57. JSONObject params = new JSONObject();
  58. params.put("uuid", uuid);
  59. try {
  60. String post = httpPoolClient.post(url, getAigcPostParam(params));
  61. JSONObject res = JSONObject.parseObject(post);
  62. if (Objects.isNull(res)) {
  63. return null;
  64. }
  65. JSONObject data = res.getJSONObject("data");
  66. return data.getString("id");
  67. } catch (Exception e) {
  68. log.error("getAuthResult error", e);
  69. }
  70. return null;
  71. }
  72. public JSONObject getAccountDetail(String publishAccountId) {
  73. String url = aigcApiHost + "/publish/account/detail";
  74. JSONObject params = new JSONObject();
  75. params.put("id", publishAccountId);
  76. try {
  77. String post = httpPoolClient.post(url, getAigcPostParam(params));
  78. JSONObject res = JSONObject.parseObject(post);
  79. return res.getJSONObject("data");
  80. } catch (Exception e) {
  81. log.error("getAccountDetail error", e);
  82. }
  83. return null;
  84. }
  85. public String getDetailByGhId(String ghId) {
  86. String url = aigcApiHost + "/publish/account/getDetailByGhId";
  87. JSONObject params = new JSONObject();
  88. params.put("id", ghId);
  89. try {
  90. String post = httpPoolClient.post(url, getAigcPostParam(params));
  91. JSONObject res = JSONObject.parseObject(post);
  92. JSONObject data = res.getJSONObject("data");
  93. return data.getString("id");
  94. } catch (Exception e) {
  95. log.error("getAccountDetail error", e);
  96. }
  97. return null;
  98. }
  99. public String createPublishPlan(String publishAccountId, String name) {
  100. String url = aigcApiHost + "/publish/plan/save";
  101. JSONObject params = getPublishPlanAddParam(publishAccountId, name);
  102. JSONObject res = null;
  103. try {
  104. String post = httpPoolClient.post(url, getAigcPostParam(params));
  105. res = JSONObject.parseObject(post);
  106. } catch (Exception e) {
  107. log.error("createPublishPlan error", e);
  108. }
  109. if (Objects.isNull(res)) {
  110. throw new CommonException(3000, "创建计划失败,请稍后重试");
  111. }
  112. Integer code = res.getInteger("code");
  113. if (code != 0) {
  114. throw new CommonException(3000, res.getString("msg"));
  115. }
  116. JSONObject data = res.getJSONObject("data");
  117. return data.getString("id");
  118. }
  119. private JSONObject getPublishPlanAddParam(String publishAccountId, String name) {
  120. String dateStr = DateUtil.getCurrentDateStr("yyyyMMdd");
  121. JSONObject params = JSONObject.parseObject("{\n" +
  122. " \"accountIds\": [\n" +
  123. " \"" + publishAccountId + "\"\n" +
  124. " ],\n" +
  125. " \"activeManualReview\": 0,\n" +
  126. " \"channel\": 5,\n" +
  127. " \"contentAllocationRules\": 0,\n" +
  128. " \"contentModal\": 7,\n" +
  129. " \"douyinPublishAccoutSetting\": [],\n" +
  130. " \"filterMatchMode\": 1,\n" +
  131. " \"name\": \"自动回复-" + dateStr + "-" + name + "\",\n" +
  132. " \"publishAccoutJson\": \"\",\n" +
  133. " \"publishBgmType\": 0,\n" +
  134. " \"publishDate\": \"\",\n" +
  135. " \"publishLocation\": [],\n" +
  136. " \"publishNum\": \"\",\n" +
  137. " \"publishPushTime\": \"\",\n" +
  138. " \"publishRate\": 0,\n" +
  139. " \"publishTimeInterval\": 240,\n" +
  140. " \"wxContentInsert\": [\n" +
  141. " {\n" +
  142. " \"accountId\": \"" + publishAccountId + "\",\n" +
  143. " \"name\": \"" + name + "\",\n" +
  144. " \"bottomInsertFlag\": 0,\n" +
  145. " \"topInsertFlag\": 0,\n" +
  146. " \"miniprogramInsertFlag\": 0,\n" +
  147. " \"gzhArticleSortFlag\": 0,\n" +
  148. " \"publishOpenFlag\": 1\n" +
  149. " }\n" +
  150. " ],\n" +
  151. " \"wxVideoPublishAccountSetting\": [],\n" +
  152. " \"scoreJudgeFlag\": 0,\n" +
  153. " \"scoreJudgeTasks\": [],\n" +
  154. " \"inputGroups\": [],\n" +
  155. " \"machineReviewMatchMode\": 1,\n" +
  156. " \"gzhOnlyMiniprogramFlag\": 0,\n" +
  157. " \"planType\": 1,\n" +
  158. " \"pushType\": 6,\n" +
  159. " \"inputFilters\": [],\n" +
  160. " \"inputSources\": [],\n" +
  161. " \"triggerEvent\": 1,\n" +
  162. " \"gzhTriggerSyncFrequency\": 1,\n" +
  163. " \"gzhTriggerSendContentType\": 1,\n" +
  164. " \"gzhAutoReplyDelayFlag\": 1,\n" +
  165. " \"gzhAutoReplyDelayMillisecond\": 500,\n" +
  166. " \"pushContentSortingRules\": 1\n" +
  167. "}");
  168. return params;
  169. }
  170. public void closePublishPlan(String externalId) {
  171. String url = aigcApiHost + "/publish/plan/updatePlanStatus";
  172. JSONObject params = new JSONObject();
  173. params.put("id", externalId);
  174. params.put("status", 0);
  175. try {
  176. String post = httpPoolClient.post(url, getAigcPostParam(params));
  177. JSONObject res = JSONObject.parseObject(post);
  178. } catch (Exception e) {
  179. log.error("closePublishPlan error", e);
  180. }
  181. }
  182. public void refreshGzhAutoReplyMsgData(String ghId) {
  183. String url = aigcApiHost + "/publish/api/refreshGzhAutoReplyMsgData?ghId=" + ghId;
  184. try {
  185. httpPoolClient.get(url);
  186. } catch (Exception e) {
  187. log.error("refreshGzhAutoReplyMsgData error", e);
  188. }
  189. }
  190. public List<WxAccountDatastatVO> getWxAccountDatastat(String dateStr, List<String> accountIds) {
  191. String url = aigcApiHost + "/dataStat/getWxAccountDatastat";
  192. JSONObject params = new JSONObject();
  193. params.put("dateStr", dateStr);
  194. params.put("accountIds", accountIds);
  195. try {
  196. String post = httpPoolClient.post(url, getAigcPostParam(params));
  197. JSONObject res = JSONObject.parseObject(post);
  198. return res.getJSONArray("data").toJavaList(WxAccountDatastatVO.class);
  199. } catch (Exception e) {
  200. log.error("closePublishPlan error", e);
  201. }
  202. return null;
  203. }
  204. }