| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- package com.tzld.piaoquan.api.component;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.tzld.piaoquan.api.common.enums.ExceptionEnum;
- import com.tzld.piaoquan.api.common.exception.CommonException;
- import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
- 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.Objects;
- @Slf4j
- @Component
- public class ManagerApiService {
- @Autowired
- private HttpPoolClient httpPoolClient;
- @Value("${manager.api.host:https://testadmin.piaoquantv.com/manager}")
- private String managerApiHost;
- public JSONObject videoMultiTitleSave(Long videoId, String title) {
- String url = managerApiHost + "/video/multiTitleV2/saveNoAuth";
- JSONObject res = null;
- try {
- JSONObject param = new JSONObject();
- param.put("videoId", videoId);
- param.put("title", title);
- param.put("source", 1);
- String post = httpPoolClient.post(url, param.toJSONString());
- res = JSONObject.parseObject(post);
- } catch (Exception e) {
- log.error("ManagerApiService videoMultiTitleSave error, videoId={} title={}",
- videoId, title, e);
- }
- if (Objects.isNull(res)) {
- throw new CommonException(ExceptionEnum.VIDEO_MULTI_TITLE_SAVE_FAILED);
- }
- if (res.getInteger("code") != 0) {
- log.error("ManagerApiService videoMultiTitleSave error, videoId={} title={} res={}",
- videoId, title, res);
- throw new CommonException(ExceptionEnum.VIDEO_MULTI_TITLE_SAVE_FAILED.getCode(),
- ExceptionEnum.VIDEO_MULTI_TITLE_SAVE_FAILED.getMsg() + "," + res.getString("msg"));
- }
- return res.getJSONObject("content");
- }
- public JSONObject videoMultiCoverSave(Long videoId, String coverUrl) {
- String url = managerApiHost + "/video/multiCover/saveNoAuth";
- JSONObject res = null;
- try {
- JSONObject param = new JSONObject();
- param.put("videoId", videoId);
- param.put("coverUrl", coverUrl);
- param.put("source", 1);
- String post = httpPoolClient.post(url, param.toJSONString());
- res = JSONObject.parseObject(post);
- } catch (Exception e) {
- log.error("ManagerApiService videoMultiCoverSave error, videoId={} coverUrl={}",
- videoId, coverUrl, e);
- }
- if (Objects.isNull(res)) {
- throw new CommonException(ExceptionEnum.VIDEO_MULTI_COVER_SAVE_FAILED);
- }
- if (res.getInteger("code") != 0) {
- log.error("ManagerApiService videoMultiCoverSave error, videoId={} coverUrl={} res={}",
- videoId, coverUrl, res);
- throw new CommonException(ExceptionEnum.VIDEO_MULTI_COVER_SAVE_FAILED.getCode(),
- ExceptionEnum.VIDEO_MULTI_COVER_SAVE_FAILED.getMsg() + "," + res.getString("msg"));
- }
- return res.getJSONObject("content");
- }
- public JSONArray videoMultiCoverListV2(Long videoId) {
- String url = managerApiHost + "/video/multiCover/listV2";
- JSONObject res = null;
- int retry = 0;
- while (retry < 3) {
- try {
- JSONObject param = new JSONObject();
- param.put("videoId", videoId);
- param.put("range", "2h");
- String post = httpPoolClient.post(url, param.toJSONString());
- res = JSONObject.parseObject(post);
- break;
- } catch (Exception e) {
- log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={}",
- videoId, "2h", e);
- retry++;
- }
- }
- if (Objects.isNull(res)) {
- throw new CommonException(ExceptionEnum.VIDEO_MULTI_COVER_LIST_FAILED);
- }
- if (res.getInteger("code") != 0) {
- log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={} res={}",
- videoId, "2h", res);
- throw new CommonException(ExceptionEnum.VIDEO_MULTI_COVER_LIST_FAILED.getCode(),
- ExceptionEnum.VIDEO_MULTI_COVER_LIST_FAILED.getMsg() + "," + res.getString("msg"));
- }
- return res.getJSONArray("content");
- }
- public JSONArray videoMultiTitleListV2(Long videoId) {
- String url = managerApiHost + "/video/multiTitleV2/listV2";
- JSONObject res = null;
- int retry = 0;
- while (retry < 3) {
- try {
- JSONObject param = new JSONObject();
- param.put("videoId", videoId);
- param.put("range", "4h");
- String post = httpPoolClient.post(url, param.toJSONString());
- res = JSONObject.parseObject(post);
- break;
- } catch (Exception e) {
- log.error("ManagerApiService videoMultiCoverListV2 error, videoId={} range={}",
- videoId, "4h", e);
- retry++;
- }
- }
- if (Objects.isNull(res)) {
- throw new CommonException(ExceptionEnum.VIDEO_MULTI_TITLE_LIST_FAILED);
- }
- if (res.getInteger("code") != 0) {
- log.error("ManagerApiService videoMultiTitleListV2 error, videoId={} range={} res={}",
- videoId, "4h", res);
- throw new CommonException(ExceptionEnum.VIDEO_MULTI_TITLE_LIST_FAILED.getCode(),
- ExceptionEnum.VIDEO_MULTI_TITLE_LIST_FAILED.getMsg() + "," + res.getString("msg"));
- }
- return res.getJSONArray("content");
- }
- }
|