VideoApiService.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. package com.tzld.piaoquan.api.component;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.tzld.piaoquan.api.common.enums.ExceptionEnum;
  4. import com.tzld.piaoquan.api.common.exception.CommonException;
  5. import com.tzld.piaoquan.api.model.vo.contentplatform.WxBaseUserInfoVO;
  6. import com.tzld.piaoquan.api.model.vo.contentplatform.WxVideoV2VO;
  7. import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.beans.factory.annotation.Value;
  11. import org.springframework.stereotype.Component;
  12. import java.util.List;
  13. import java.util.Objects;
  14. @Slf4j
  15. @Component
  16. public class VideoApiService {
  17. @Autowired
  18. private HttpPoolClient httpPoolClient;
  19. @Value("${video.api.host:https://videotest.yishihui.com}")
  20. private String videoApiHost;
  21. public List<String> getCoverImagePaths(Long videoId) {
  22. String url = videoApiHost + "/longvideoapi/video/getCoverImagePaths";
  23. try {
  24. String post = httpPoolClient.post(url, "id=" + videoId, "application/x-www-form-urlencoded;charset=UTF-8");
  25. JSONObject res = JSONObject.parseObject(post);
  26. JSONObject data = res.getJSONObject("data");
  27. return data.getJSONArray("videoCoverImages").toJavaList(String.class);
  28. } catch (Exception e) {
  29. log.error("VideoApiService getCoverImagePaths error", e);
  30. }
  31. return null;
  32. }
  33. public WxBaseUserInfoVO webLogin(String code, Integer appType, String appId, String machineCode) {
  34. String url = videoApiHost + "/longvideoapi/user/webLogin";
  35. try {
  36. String post = httpPoolClient.post(url, "code=" + code +
  37. "&appType=" + appType +
  38. "&appId=" + appId +
  39. "&path=%2F" +
  40. "&clientTimestamp=" + System.currentTimeMillis() +
  41. "&loginUid=" +
  42. "&token=" +
  43. "&machineCode=" + machineCode, "application/x-www-form-urlencoded;charset=UTF-8");
  44. JSONObject res = JSONObject.parseObject(post);
  45. return res.getObject("data", WxBaseUserInfoVO.class);
  46. } catch (Exception e) {
  47. log.error("VideoApiService webLogin error", e);
  48. }
  49. return null;
  50. }
  51. public void saveUserPhoneNumber(Long uid, String phoneNumber) {
  52. String url = videoApiHost + "/longvideoapi/openapi/user/saveUserPhoneNumber";
  53. try {
  54. JSONObject param = new JSONObject();
  55. param.put("uid", uid);
  56. param.put("phoneNumber", phoneNumber);
  57. String post = httpPoolClient.post(url, param.toJSONString());
  58. JSONObject res = JSONObject.parseObject(post);
  59. } catch (Exception e) {
  60. log.error("VideoApiService saveUserPhoneNumber error", e);
  61. }
  62. }
  63. public Long publishVideo(Long uid, String videoUrl, String coverUrl, String title) {
  64. String url = videoApiHost + "/longvideoapi/crawler/video/send";
  65. JSONObject res = null;
  66. try {
  67. String param = "videoPath=" + videoUrl +
  68. "&crawlerSrcCode=CONTENT" +
  69. "&crawlerSrcPublishTimestamp=" + System.currentTimeMillis() +
  70. "&crawlerTaskTimestamp=" + System.currentTimeMillis() +
  71. "&coverImgPath=" + coverUrl +
  72. "&appType=888888" +
  73. "&loginUid=" + uid +
  74. "&title=" + title +
  75. "&viewStatus=1" +
  76. "&versionCode=1";
  77. log.info("VideoApiService publishVideo param={}", param);
  78. String post = httpPoolClient.post(url, param, "application/x-www-form-urlencoded;charset=UTF-8");
  79. res = JSONObject.parseObject(post);
  80. } catch (Exception e) {
  81. log.error("VideoApiService publishVideo error", e);
  82. }
  83. if (Objects.isNull(res)) {
  84. return null;
  85. }
  86. if (res.getInteger("code") != 0) {
  87. log.error("publishVideo error, uid:{} videoUrl={} coverUrl={} title={} res={}", uid, videoUrl, coverUrl, title, res);
  88. throw new CommonException(ExceptionEnum.VIDEO_PUBLISH_FAILED.getCode(),
  89. ExceptionEnum.VIDEO_PUBLISH_FAILED.getMsg() + "," + res.getString("msg"));
  90. }
  91. JSONObject data = res.getJSONObject("data");
  92. Long videoId = data.getLong("id");
  93. log.info("VideoApiService publishVideo success, uid:{} videoId={}", uid, videoId);
  94. return videoId;
  95. }
  96. public void updateVideo(Long uid, Long videoId, String coverUrl, String title) {
  97. String url = videoApiHost + "/longvideoapi/openapi/video/update";
  98. JSONObject res = null;
  99. try {
  100. JSONObject videoDetail = getVideoInfo(videoId);
  101. JSONObject chargeDetail = videoDetail.getJSONObject("chargeDetail");
  102. JSONObject param = new JSONObject();
  103. param.put("loginUid", uid);
  104. param.put("id", videoId);
  105. param.put("videoId", videoId);
  106. param.put("appType", 8);
  107. param.put("coverImgPath", coverUrl);
  108. param.put("title", title);
  109. param.put("viewStatus", 1);
  110. param.put("videoCollectionId", videoDetail.getLong("videoCollectionId"));
  111. param.put("barrageSwitch", videoDetail.getLong("barrageSwitch"));
  112. param.put("charge", chargeDetail.getInteger("charge"));
  113. param.put("price", chargeDetail.getLong("price"));
  114. param.put("allowIosPlay", chargeDetail.getLong("allowIosPlay"));
  115. param.put("allowDownload", 0);
  116. log.info("VideoApiService updateVideo param={}", param.toJSONString());
  117. String post = httpPoolClient.post(url, param.toJSONString());
  118. res = JSONObject.parseObject(post);
  119. } catch (Exception e) {
  120. log.error("VideoApiService updateVideo error", e);
  121. }
  122. if (Objects.isNull(res)) {
  123. throw new CommonException(ExceptionEnum.VIDEO_UPDATE_FAILED);
  124. }
  125. if (res.getInteger("code") != 0) {
  126. log.error("VideoApiService updateVideo error, uid:{} videoId={} coverUrl={} title={} res={}", uid, videoId, coverUrl, title, res);
  127. throw new CommonException(ExceptionEnum.VIDEO_UPDATE_FAILED.getCode(), res.getString("msg"));
  128. }
  129. }
  130. public JSONObject getVideoInfo(Long videoId) {
  131. String url = videoApiHost + "/longvideoapi/openapi/video/getVideoInfo";
  132. JSONObject res = null;
  133. try {
  134. JSONObject param = new JSONObject();
  135. param.put("videoId", videoId);
  136. String post = httpPoolClient.post(url, param.toJSONString());
  137. res = JSONObject.parseObject(post);
  138. } catch (Exception e) {
  139. log.error("VideoApiService getVideoInfo error", e);
  140. }
  141. if (Objects.isNull(res)) {
  142. throw new CommonException(ExceptionEnum.VIDEO_INFO_FAILED);
  143. }
  144. if (res.getInteger("code") != 0) {
  145. log.error("VideoApiService getVideoInfo error, videoId={} res={}", videoId, res);
  146. throw new CommonException(ExceptionEnum.VIDEO_INFO_FAILED.getCode(),
  147. ExceptionEnum.VIDEO_INFO_FAILED.getMsg() + "," + res.getString("msg"));
  148. }
  149. return res.getJSONObject("data");
  150. }
  151. public void deleteVideo(Long uid, Long videoId) {
  152. String url = videoApiHost + "/longvideoapi/openapi/video/delete";
  153. JSONObject res = null;
  154. try {
  155. JSONObject param = new JSONObject();
  156. param.put("loginUid", uid);
  157. param.put("videoId", videoId);
  158. String post = httpPoolClient.post(url, param.toJSONString());
  159. res = JSONObject.parseObject(post);
  160. } catch (Exception e) {
  161. log.error("VideoApiService deleteVideo error", e);
  162. }
  163. if (Objects.isNull(res)) {
  164. throw new CommonException(ExceptionEnum.VIDEO_DELETE_FAILED);
  165. }
  166. if (res.getInteger("code") != 0) {
  167. log.error("VideoApiService deleteVideo error, videoId={} res={}", videoId, res);
  168. throw new CommonException(ExceptionEnum.VIDEO_DELETE_FAILED.getCode(),
  169. ExceptionEnum.VIDEO_DELETE_FAILED.getMsg() + "," + res.getString("msg"));
  170. }
  171. }
  172. public List<WxVideoV2VO> getUserVideoList(Long uid, List<Long> excludeVideoIds, Integer pageNum, Integer pageSize) {
  173. String url = videoApiHost + "/longvideoapi/openapi/video/getUserVideoListAuditPass";
  174. JSONObject res = null;
  175. try {
  176. JSONObject param = new JSONObject();
  177. param.put("uid", uid);
  178. param.put("excludeVideoIds", excludeVideoIds);
  179. param.put("pageNum", pageNum);
  180. param.put("pageSize", pageSize);
  181. String post = httpPoolClient.post(url, param.toJSONString());
  182. res = JSONObject.parseObject(post);
  183. } catch (Exception e) {
  184. log.error("VideoApiService getUserVideoList error, uid={} excludeVideoIds={} pageNum={} pageSize={}",
  185. uid, excludeVideoIds, pageNum, pageSize, e);
  186. }
  187. if (Objects.isNull(res)) {
  188. throw new CommonException(ExceptionEnum.VIDEO_DELETE_FAILED);
  189. }
  190. if (res.getInteger("code") != 0) {
  191. log.error("VideoApiService getUserVideoList error, uid={} excludeVideoIds={} pageNum={} pageSize={} res={}",
  192. uid, excludeVideoIds, pageNum, pageSize, res);
  193. throw new CommonException(ExceptionEnum.VIDEO_DELETE_FAILED.getCode(),
  194. ExceptionEnum.VIDEO_DELETE_FAILED.getMsg() + "," + res.getString("msg"));
  195. }
  196. return res.getJSONArray("data").toJavaList(WxVideoV2VO.class);
  197. }
  198. public List<WxVideoV2VO> getTagVideoList(String tagName, String roomId, List<Long> excludeVideoIds, Integer pageNum, Integer pageSize) {
  199. String url = videoApiHost + "/longvideoapi/openapi/video/getTagVideoListAuditPass";
  200. JSONObject res = null;
  201. try {
  202. JSONObject param = new JSONObject();
  203. param.put("tagName", tagName);
  204. param.put("sentRoomId", roomId);
  205. param.put("excludeVideoIds", excludeVideoIds);
  206. param.put("pageNum", pageNum);
  207. param.put("pageSize", pageSize);
  208. String post = httpPoolClient.post(url, param.toJSONString());
  209. res = JSONObject.parseObject(post);
  210. } catch (Exception e) {
  211. log.error("VideoApiService getTagVideoList error, tagName={} excludeVideoIds={} pageNum={} pageSize={}",
  212. tagName, excludeVideoIds, pageNum, pageSize, e);
  213. }
  214. if (Objects.isNull(res)) {
  215. throw new CommonException(ExceptionEnum.VIDEO_DELETE_FAILED);
  216. }
  217. if (res.getInteger("code") != 0) {
  218. log.error("VideoApiService getTagVideoList error, tagName={} excludeVideoIds={} pageNum={} pageSize={} res={}",
  219. tagName, excludeVideoIds, pageNum, pageSize, res);
  220. throw new CommonException(ExceptionEnum.VIDEO_DELETE_FAILED.getCode(),
  221. ExceptionEnum.VIDEO_DELETE_FAILED.getMsg() + "," + res.getString("msg"));
  222. }
  223. return res.getJSONArray("data").toJavaList(WxVideoV2VO.class);
  224. }
  225. }