VideoApiService.java 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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.growth.common.component.HttpPoolClient;
  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 VideoApiService {
  16. @Autowired
  17. private HttpPoolClient httpPoolClient;
  18. @Value("${video.api.host:https://videotest.yishihui.com}")
  19. private String videoApiHost;
  20. public List<String> getCoverImagePaths(Long videoId) {
  21. String url = videoApiHost + "/longvideoapi/video/getCoverImagePaths";
  22. try {
  23. String post = httpPoolClient.post(url, "id=" + videoId, "application/x-www-form-urlencoded;charset=UTF-8");
  24. JSONObject res = JSONObject.parseObject(post);
  25. JSONObject data = res.getJSONObject("data");
  26. return data.getJSONArray("videoCoverImages").toJavaList(String.class);
  27. } catch (Exception e) {
  28. log.error("getCoverImagePaths error", e);
  29. }
  30. return null;
  31. }
  32. public WxBaseUserInfoVO webLogin(String code, Integer appType, String appId, String machineCode) {
  33. String url = videoApiHost + "/longvideoapi/user/webLogin";
  34. try {
  35. String post = httpPoolClient.post(url, "code=" + code +
  36. "&appType=" + appType +
  37. "&appId=" + appId +
  38. "&path=%2F" +
  39. "&clientTimestamp=" + System.currentTimeMillis() +
  40. "&loginUid=" +
  41. "&token=" +
  42. "&machineCode=" + machineCode, "application/x-www-form-urlencoded;charset=UTF-8");
  43. JSONObject res = JSONObject.parseObject(post);
  44. return res.getObject("data", WxBaseUserInfoVO.class);
  45. } catch (Exception e) {
  46. log.error("webLogin error", e);
  47. }
  48. return null;
  49. }
  50. public void saveUserPhoneNumber(Long uid, String phoneNumber) {
  51. String url = videoApiHost + "/longvideoapi/openapi/user/saveUserPhoneNumber";
  52. try {
  53. JSONObject param = new JSONObject();
  54. param.put("uid", uid);
  55. param.put("phoneNumber", phoneNumber);
  56. String post = httpPoolClient.post(url, param.toJSONString());
  57. JSONObject res = JSONObject.parseObject(post);
  58. } catch (Exception e) {
  59. log.error("saveUserPhoneNumber error", e);
  60. }
  61. }
  62. public Long publishVideo(Long uid, String videoUrl, String coverUrl, String title) {
  63. String url = videoApiHost + "/longvideoapi/crawler/video/send";
  64. JSONObject res = null;
  65. try {
  66. String param = "videoPath=" + videoUrl +
  67. "&crawlerSrcCode=CONTENT" +
  68. "&crawlerSrcPublishTimestamp=" + System.currentTimeMillis() +
  69. "&crawlerTaskTimestamp=" + System.currentTimeMillis() +
  70. "&coverImgPath=" + coverUrl +
  71. "&appType=888888" +
  72. "&loginUid=" + uid +
  73. "&title=" + title +
  74. "&viewStatus=1" +
  75. "&versionCode=1";
  76. String post = httpPoolClient.post(url, param, "application/x-www-form-urlencoded;charset=UTF-8");
  77. res = JSONObject.parseObject(post);
  78. } catch (Exception e) {
  79. log.error("publishVideo error", e);
  80. }
  81. if (Objects.isNull(res)) {
  82. return null;
  83. }
  84. if (res.getInteger("code") != 0) {
  85. log.error("publishVideo error, uid:{} videoUrl={} coverUrl={} title={} res={}", uid, videoUrl, coverUrl, title, res);
  86. throw new CommonException(ExceptionEnum.VIDEO_PUBLISH_FAILED.getCode(), res.getString("msg"));
  87. }
  88. JSONObject data = res.getJSONObject("data");
  89. Long videoId = data.getLong("id");
  90. log.info("publishVideo success, uid:{} videoId={}", uid, videoId);
  91. return videoId;
  92. }
  93. public void updateVideo(Long uid, Long videoId, String coverUrl, String title) {
  94. String url = videoApiHost + "/longvideoapi/openapi/video/update";
  95. JSONObject res = null;
  96. try {
  97. JSONObject videoDetail = getVideoInfo(videoId);
  98. JSONObject chargeDetail = videoDetail.getJSONObject("chargeDetail");
  99. JSONObject param = new JSONObject();
  100. param.put("loginUid", uid);
  101. param.put("id", videoId);
  102. param.put("videoId", videoId);
  103. param.put("appType", 8);
  104. param.put("coverImgPath", coverUrl);
  105. param.put("title", title);
  106. param.put("viewStatus", 1);
  107. param.put("videoCollectionId", videoDetail.getLong("videoCollectionId"));
  108. param.put("barrageSwitch", videoDetail.getLong("barrageSwitch"));
  109. param.put("charge", chargeDetail.getInteger("charge"));
  110. param.put("price", chargeDetail.getLong("price"));
  111. param.put("allowIosPlay", chargeDetail.getLong("allowIosPlay"));
  112. param.put("allowDownload", 0);
  113. String post = httpPoolClient.post(url, param.toJSONString());
  114. res = JSONObject.parseObject(post);
  115. } catch (Exception e) {
  116. log.error("updateVideo error", e);
  117. }
  118. if (Objects.isNull(res)) {
  119. throw new CommonException(ExceptionEnum.VIDEO_UPDATE_FAILED);
  120. }
  121. if (res.getInteger("code") != 0) {
  122. log.error("updateVideo error, uid:{} videoId={} coverUrl={} title={} res={}", uid, videoId, coverUrl, title, res);
  123. throw new CommonException(ExceptionEnum.VIDEO_UPDATE_FAILED.getCode(), res.getString("msg"));
  124. }
  125. }
  126. public JSONObject getVideoInfo(Long videoId) {
  127. String url = videoApiHost + "/longvideoapi/openapi/video/getVideoInfo";
  128. try {
  129. JSONObject param = new JSONObject();
  130. param.put("videoId", videoId);
  131. String post = httpPoolClient.post(url, param.toJSONString());
  132. JSONObject res = JSONObject.parseObject(post);
  133. if (res.getInteger("code") != 0) {
  134. log.error("getVideoInfo error, videoId={} res={}", videoId, res);
  135. throw new CommonException(ExceptionEnum.VIDEO_PUBLISH_FAILED.getCode(), res.getString("msg"));
  136. }
  137. return res.getJSONObject("data");
  138. } catch (Exception e) {
  139. log.error("getVideoInfo error", e);
  140. }
  141. return null;
  142. }
  143. public void deleteVideo(Long uid, Long videoId) {
  144. String url = videoApiHost + "/longvideoapi/openapi/video/delete";
  145. try {
  146. JSONObject param = new JSONObject();
  147. param.put("loginUid", uid);
  148. param.put("videoId", videoId);
  149. String post = httpPoolClient.post(url, param.toJSONString());
  150. JSONObject res = JSONObject.parseObject(post);
  151. } catch (Exception e) {
  152. log.error("deleteVideo error", e);
  153. }
  154. }
  155. }