AigcApiService.java 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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-testapi.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. if (Objects.nonNull(data)) {
  94. return data.getString("id");
  95. }
  96. } catch (Exception e) {
  97. log.error("getDetailByGhId error", e);
  98. }
  99. return null;
  100. }
  101. public String createPublishPlan(String publishAccountId, String name, String channel) {
  102. String url = aigcApiHost + "/publish/plan/save";
  103. JSONObject params = getPublishPlanAddParam(publishAccountId, name, channel);
  104. JSONObject res = null;
  105. try {
  106. String post = httpPoolClient.post(url, getAigcPostParam(params));
  107. res = JSONObject.parseObject(post);
  108. } catch (Exception e) {
  109. log.error("createPublishPlan error", e);
  110. }
  111. if (Objects.isNull(res)) {
  112. throw new CommonException(3000, "创建计划失败,请稍后重试");
  113. }
  114. Integer code = res.getInteger("code");
  115. if (code != 0) {
  116. throw new CommonException(3000, res.getString("msg"));
  117. }
  118. JSONObject data = res.getJSONObject("data");
  119. return data.getString("id");
  120. }
  121. private JSONObject getPublishPlanAddParam(String publishAccountId, String name, String channel) {
  122. String dateStr = DateUtil.getCurrentDateStr("yyyyMMdd");
  123. JSONObject params = JSONObject.parseObject("{\n" +
  124. " \"accountIds\": [\n" +
  125. " \"" + publishAccountId + "\"\n" +
  126. " ],\n" +
  127. " \"activeManualReview\": 0,\n" +
  128. " \"channel\": 5,\n" +
  129. " \"contentAllocationRules\": 0,\n" +
  130. " \"contentModal\": 7,\n" +
  131. " \"douyinPublishAccoutSetting\": [],\n" +
  132. " \"filterMatchMode\": 1,\n" +
  133. " \"name\": \"自动回复-" + dateStr + "-" + name + "-" + channel + "\",\n" +
  134. " \"publishAccoutJson\": \"\",\n" +
  135. " \"publishBgmType\": 0,\n" +
  136. " \"publishDate\": \"\",\n" +
  137. " \"publishLocation\": [],\n" +
  138. " \"publishNum\": \"\",\n" +
  139. " \"publishPushTime\": \"\",\n" +
  140. " \"publishRate\": 0,\n" +
  141. " \"publishTimeInterval\": 240,\n" +
  142. " \"wxContentInsert\": [\n" +
  143. " {\n" +
  144. " \"accountId\": \"" + publishAccountId + "\",\n" +
  145. " \"name\": \"" + name + "\",\n" +
  146. " \"bottomInsertFlag\": 0,\n" +
  147. " \"topInsertFlag\": 0,\n" +
  148. " \"miniprogramInsertFlag\": 0,\n" +
  149. " \"gzhArticleSortFlag\": 0,\n" +
  150. " \"publishOpenFlag\": 1\n" +
  151. " }\n" +
  152. " ],\n" +
  153. " \"wxVideoPublishAccountSetting\": [],\n" +
  154. " \"scoreJudgeFlag\": 0,\n" +
  155. " \"scoreJudgeTasks\": [],\n" +
  156. " \"inputGroups\": [],\n" +
  157. " \"machineReviewMatchMode\": 1,\n" +
  158. " \"gzhOnlyMiniprogramFlag\": 0,\n" +
  159. " \"planType\": 1,\n" +
  160. " \"pushType\": 6,\n" +
  161. " \"inputFilters\": [],\n" +
  162. " \"inputSources\": [],\n" +
  163. " \"triggerEvent\": 1,\n" +
  164. " \"gzhTriggerSyncFrequency\": 1,\n" +
  165. " \"gzhTriggerSendContentType\": 1,\n" +
  166. " \"gzhAutoReplyDelayFlag\": 1,\n" +
  167. " \"gzhAutoReplyDelayMillisecond\": 1000,\n" +
  168. " \"pushContentSortingRules\": 1\n" +
  169. "}");
  170. return params;
  171. }
  172. public void changePublishPlanStatus(String externalId, Integer status) {
  173. String url = aigcApiHost + "/publish/plan/updatePlanStatus";
  174. JSONObject params = new JSONObject();
  175. params.put("id", externalId);
  176. params.put("status", status);
  177. try {
  178. String post = httpPoolClient.post(url, getAigcPostParam(params));
  179. JSONObject res = JSONObject.parseObject(post);
  180. } catch (Exception e) {
  181. log.error("changePublishPlanStatus error", e);
  182. }
  183. }
  184. public void refreshGzhAutoReplyMsgData(String ghId) {
  185. String url = aigcApiHost + "/publish/api/refreshGzhAutoReplyMsgData?ghId=" + ghId;
  186. try {
  187. httpPoolClient.get(url);
  188. } catch (Exception e) {
  189. log.error("refreshGzhAutoReplyMsgData error", e);
  190. }
  191. }
  192. public List<WxAccountDatastatVO> getWxAccountDatastat(String dateStr, List<String> accountIds) {
  193. String url = aigcApiHost + "/dataStat/getWxAccountDatastat";
  194. JSONObject params = new JSONObject();
  195. params.put("dateStr", dateStr);
  196. params.put("accountIds", accountIds);
  197. try {
  198. String post = httpPoolClient.post(url, getAigcPostParam(params));
  199. JSONObject res = JSONObject.parseObject(post);
  200. return res.getJSONArray("data").toJavaList(WxAccountDatastatVO.class);
  201. } catch (Exception e) {
  202. log.error("getWxAccountDatastat error", e);
  203. }
  204. return null;
  205. }
  206. public void closeAccountMessagePublishPlan(String publishAccountId) {
  207. String url = aigcApiHost + "/publish/plan/closeAccountMessagePublishPlan";
  208. JSONObject params = new JSONObject();
  209. params.put("id", publishAccountId);
  210. try {
  211. String post = httpPoolClient.post(url, getAigcPostParam(params));
  212. JSONObject res = JSONObject.parseObject(post);
  213. } catch (Exception e) {
  214. log.error("closeAccountMessagePublishPlan error", e);
  215. }
  216. }
  217. }