123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- package com.tzld.piaoquan.api.component;
- import com.alibaba.fastjson.JSONObject;
- import com.tzld.piaoquan.api.common.exception.CommonException;
- import com.tzld.piaoquan.api.model.vo.WxAccountDatastatVO;
- 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;
- import org.springframework.stereotype.Component;
- import java.util.List;
- import java.util.Objects;
- @Slf4j
- @Component
- public class AigcApiService {
- @Autowired
- private HttpPoolClient httpPoolClient;
- @Value("${aigc.api.host:http://aigc-testapi.cybertogether.net/aigc}")
- private String aigcApiHost;
- @Value("${aigc.api.token:9ebfcb397e954c41986971f183eb1707}")
- private String aigcApiToken;
- private String getAigcPostParam(JSONObject params) {
- JSONObject baseInfo = JSONObject.parseObject("{\n" +
- " \"token\": \"" + aigcApiToken + "\",\n" +
- " \"appType\": 9,\n" +
- " \"platform\": \"pc\",\n" +
- " \"appVersionCode\": 1000,\n" +
- " \"clientTimestamp\": 1,\n" +
- " \"fid\": 1,\n" +
- " \"loginUid\": 1,\n" +
- " \"pageSource\": 1,\n" +
- " \"requestId\": 1,\n" +
- " \"rid\": 1,\n" +
- " \"uid\": 1\n" +
- "}");
- JSONObject param = new JSONObject();
- param.put("params", params);
- param.put("baseInfo", baseInfo);
- return param.toJSONString();
- }
- public String generateQrcode(String uuid) {
- String url = aigcApiHost + "/publish/account/generateQrcode";
- JSONObject params = new JSONObject();
- params.put("uuid", uuid);
- try {
- String post = httpPoolClient.post(url, getAigcPostParam(params));
- JSONObject res = JSONObject.parseObject(post);
- JSONObject data = res.getJSONObject("data");
- return data.getString("qrcodeStr");
- } catch (Exception e) {
- log.error("generateQrcode error", e);
- }
- return null;
- }
- public String getAuthResult(String uuid) {
- String url = aigcApiHost + "/publish/account/authResult";
- JSONObject params = new JSONObject();
- params.put("uuid", uuid);
- try {
- String post = httpPoolClient.post(url, getAigcPostParam(params));
- JSONObject res = JSONObject.parseObject(post);
- if (Objects.isNull(res)) {
- return null;
- }
- JSONObject data = res.getJSONObject("data");
- return data.getString("id");
- } catch (Exception e) {
- log.error("getAuthResult error", e);
- }
- return null;
- }
- public JSONObject getAccountDetail(String publishAccountId) {
- String url = aigcApiHost + "/publish/account/detail";
- JSONObject params = new JSONObject();
- params.put("id", publishAccountId);
- try {
- String post = httpPoolClient.post(url, getAigcPostParam(params));
- JSONObject res = JSONObject.parseObject(post);
- return res.getJSONObject("data");
- } catch (Exception e) {
- log.error("getAccountDetail error", e);
- }
- return null;
- }
- public String getDetailByGhId(String ghId) {
- String url = aigcApiHost + "/publish/account/getDetailByGhId";
- JSONObject params = new JSONObject();
- params.put("id", ghId);
- try {
- String post = httpPoolClient.post(url, getAigcPostParam(params));
- JSONObject res = JSONObject.parseObject(post);
- JSONObject data = res.getJSONObject("data");
- if (Objects.nonNull(data)) {
- return data.getString("id");
- }
- } catch (Exception e) {
- log.error("getDetailByGhId error", e);
- }
- return null;
- }
- public String createPublishPlan(String publishAccountId, String name, String channel) {
- String url = aigcApiHost + "/publish/plan/save";
- JSONObject params = getPublishPlanAddParam(publishAccountId, name, channel);
- JSONObject res = null;
- try {
- String post = httpPoolClient.post(url, getAigcPostParam(params));
- res = JSONObject.parseObject(post);
- } catch (Exception e) {
- log.error("createPublishPlan error", e);
- }
- 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 channel) {
- String dateStr = DateUtil.getCurrentDateStr("yyyyMMdd");
- JSONObject params = JSONObject.parseObject("{\n" +
- " \"accountIds\": [\n" +
- " \"" + publishAccountId + "\"\n" +
- " ],\n" +
- " \"activeManualReview\": 0,\n" +
- " \"channel\": 5,\n" +
- " \"contentAllocationRules\": 0,\n" +
- " \"contentModal\": 7,\n" +
- " \"douyinPublishAccoutSetting\": [],\n" +
- " \"filterMatchMode\": 1,\n" +
- " \"name\": \"自动回复-" + dateStr + "-" + name + "-" + channel + "\",\n" +
- " \"publishAccoutJson\": \"\",\n" +
- " \"publishBgmType\": 0,\n" +
- " \"publishDate\": \"\",\n" +
- " \"publishLocation\": [],\n" +
- " \"publishNum\": \"\",\n" +
- " \"publishPushTime\": \"\",\n" +
- " \"publishRate\": 0,\n" +
- " \"publishTimeInterval\": 240,\n" +
- " \"wxContentInsert\": [\n" +
- " {\n" +
- " \"accountId\": \"" + publishAccountId + "\",\n" +
- " \"name\": \"" + name + "\",\n" +
- " \"bottomInsertFlag\": 0,\n" +
- " \"topInsertFlag\": 0,\n" +
- " \"miniprogramInsertFlag\": 0,\n" +
- " \"gzhArticleSortFlag\": 0,\n" +
- " \"publishOpenFlag\": 1\n" +
- " }\n" +
- " ],\n" +
- " \"wxVideoPublishAccountSetting\": [],\n" +
- " \"scoreJudgeFlag\": 0,\n" +
- " \"scoreJudgeTasks\": [],\n" +
- " \"inputGroups\": [],\n" +
- " \"machineReviewMatchMode\": 1,\n" +
- " \"gzhOnlyMiniprogramFlag\": 0,\n" +
- " \"planType\": 1,\n" +
- " \"pushType\": 6,\n" +
- " \"inputFilters\": [],\n" +
- " \"inputSources\": [],\n" +
- " \"triggerEvent\": 1,\n" +
- " \"gzhTriggerSyncFrequency\": 1,\n" +
- " \"gzhTriggerSendContentType\": 1,\n" +
- " \"gzhAutoReplyDelayFlag\": 1,\n" +
- " \"gzhAutoReplyDelayMillisecond\": 1000,\n" +
- " \"pushContentSortingRules\": 1\n" +
- "}");
- return params;
- }
- public void changePublishPlanStatus(String externalId, Integer status) {
- String url = aigcApiHost + "/publish/plan/updatePlanStatus";
- JSONObject params = new JSONObject();
- params.put("id", externalId);
- params.put("status", status);
- try {
- String post = httpPoolClient.post(url, getAigcPostParam(params));
- JSONObject res = JSONObject.parseObject(post);
- } catch (Exception e) {
- log.error("changePublishPlanStatus error", e);
- }
- }
- public void refreshGzhAutoReplyMsgData(String ghId) {
- String url = aigcApiHost + "/publish/api/refreshGzhAutoReplyMsgData?ghId=" + ghId;
- try {
- httpPoolClient.get(url);
- } catch (Exception e) {
- log.error("refreshGzhAutoReplyMsgData error", e);
- }
- }
- public List<WxAccountDatastatVO> getWxAccountDatastat(String dateStr, List<String> accountIds) {
- String url = aigcApiHost + "/dataStat/getWxAccountDatastat";
- JSONObject params = new JSONObject();
- params.put("dateStr", dateStr);
- params.put("accountIds", accountIds);
- try {
- String post = httpPoolClient.post(url, getAigcPostParam(params));
- JSONObject res = JSONObject.parseObject(post);
- return res.getJSONArray("data").toJavaList(WxAccountDatastatVO.class);
- } catch (Exception e) {
- log.error("getWxAccountDatastat error", e);
- }
- return null;
- }
- public void closeAccountMessagePublishPlan(String publishAccountId) {
- String url = aigcApiHost + "/publish/plan/closeAccountMessagePublishPlan";
- JSONObject params = new JSONObject();
- params.put("id", publishAccountId);
- try {
- String post = httpPoolClient.post(url, getAigcPostParam(params));
- JSONObject res = JSONObject.parseObject(post);
- } catch (Exception e) {
- log.error("closeAccountMessagePublishPlan error", e);
- }
- }
- }
|