VideoApiService.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. @Slf4j
  13. @Component
  14. public class VideoApiService {
  15. @Autowired
  16. private HttpPoolClient httpPoolClient;
  17. @Value("${video.api.host:https://videotest.yishihui.com}")
  18. private String videoApiHost;
  19. public List<String> getCoverImagePaths(Long videoId) {
  20. String url = videoApiHost + "/longvideoapi/video/getCoverImagePaths";
  21. try {
  22. String post = httpPoolClient.post(url, "id=" + videoId, "application/x-www-form-urlencoded;charset=UTF-8");
  23. JSONObject res = JSONObject.parseObject(post);
  24. JSONObject data = res.getJSONObject("data");
  25. return data.getJSONArray("videoCoverImages").toJavaList(String.class);
  26. } catch (Exception e) {
  27. log.error("getCoverImagePaths error", e);
  28. }
  29. return null;
  30. }
  31. public WxBaseUserInfoVO webLogin(String code, Integer appType, String appId, String machineCode) {
  32. String url = videoApiHost + "/longvideoapi/user/webLogin";
  33. try {
  34. String post = httpPoolClient.post(url, "code=" + code +
  35. "&appType=" + appType +
  36. "&appId=" + appId +
  37. "&path=%2F" +
  38. "&clientTimestamp=" + System.currentTimeMillis() +
  39. "6&loginUid=" +
  40. "&token=" +
  41. "&machineCode=" + machineCode, "application/x-www-form-urlencoded;charset=UTF-8");
  42. JSONObject res = JSONObject.parseObject(post);
  43. return res.getObject("data", WxBaseUserInfoVO.class);
  44. } catch (Exception e) {
  45. log.error("webLogin error", e);
  46. }
  47. return null;
  48. }
  49. public void saveUserPhoneNumber(Long uid, String phoneNumber) {
  50. String url = videoApiHost + "/longvideoapi/openapi/user/saveUserPhoneNumber";
  51. try {
  52. JSONObject param = new JSONObject();
  53. param.put("uid", uid);
  54. param.put("phoneNumber", phoneNumber);
  55. String post = httpPoolClient.post(url, param.toJSONString());
  56. } catch (Exception e) {
  57. log.error("saveUserPhoneNumber error", e);
  58. }
  59. }
  60. public Long publishVideo(Long uid, String videoUrl, String coverUrl, String title) {
  61. String url = videoApiHost + "/longvideoapi/crawler/video/send";
  62. try {
  63. String post = httpPoolClient.post(url, "videoPath=" + videoUrl +
  64. "&crawlerSrcCode=\"CONTENT\"" +
  65. "&crawlerSrcPublishTimestamp=\"" + System.currentTimeMillis() + "\"" +
  66. "&crawlerTaskTimestamp=\"" + System.currentTimeMillis() + "\"" +
  67. "&coverImgPath=" + coverUrl +
  68. "&loginUid=" + uid +
  69. "&title=" + title, "application/x-www-form-urlencoded;charset=UTF-8");
  70. JSONObject res = JSONObject.parseObject(post);
  71. if (res.getInteger("code") != 0) {
  72. log.error("publishVideo error, uid:{} videoUrl={} coverUrl={} title={} res={}", uid, videoUrl, coverUrl, title, res);
  73. throw new CommonException(ExceptionEnum.VIDEO_PUBLISH_FAILED.getCode(), res.getString("msg"));
  74. }
  75. JSONObject data = res.getJSONObject("data");
  76. Long videoId = data.getLong("videoId");
  77. log.info("publishVideo success, uid:{} videoId={}", uid, videoId);
  78. return videoId;
  79. } catch (Exception e) {
  80. log.error("publishVideo error", e);
  81. }
  82. return null;
  83. }
  84. public void updateVideo(Long uid, Long videoId, String coverUrl, String title) {
  85. String url = videoApiHost + "/longvideoapi/openapi/video/update";
  86. try {
  87. JSONObject param = new JSONObject();
  88. param.put("loginUid", uid);
  89. param.put("videoId", videoId);
  90. param.put("coverImgPath", coverUrl);
  91. param.put("title", title);
  92. String post = httpPoolClient.post(url, param.toJSONString());
  93. JSONObject res = JSONObject.parseObject(post);
  94. if (res.getInteger("code") != 0) {
  95. log.error("updateVideo error, uid:{} videoId={} coverUrl={} title={} res={}", uid, videoId, coverUrl, title, res);
  96. throw new CommonException(ExceptionEnum.VIDEO_PUBLISH_FAILED.getCode(), res.getString("msg"));
  97. }
  98. } catch (Exception e) {
  99. log.error("updateVideo error", e);
  100. }
  101. }
  102. public void deleteVideo(Long uid, Long videoId) {
  103. String url = videoApiHost + "/longvideoapi/openapi/video/delete";
  104. try {
  105. JSONObject param = new JSONObject();
  106. param.put("loginUid", uid);
  107. param.put("videoId", videoId);
  108. String post = httpPoolClient.post(url, param.toJSONString());
  109. } catch (Exception e) {
  110. log.error("deleteVideo error", e);
  111. }
  112. }
  113. }