TouLiuHttpClient.java 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package com.tzld.piaoquan.api.component;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.tzld.piaoquan.common.component.HttpPoolClient;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Component;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Map;
  11. import java.util.UUID;
  12. @Slf4j
  13. @Component
  14. public class TouLiuHttpClient {
  15. @Autowired
  16. private HttpPoolClient httpPoolClient;
  17. public String sendAdFlowAddRequest(String baseUrl,
  18. String videoId,
  19. String putScene,
  20. String channel,
  21. String remark,
  22. String putTypeOne,
  23. String putTypeTwo,
  24. String putTypeThree,
  25. String putCarrierId) {
  26. String url = baseUrl + "/ad/put/flow/add/tencent";
  27. UUID uuid = UUID.randomUUID();
  28. String jsonBody = "{" +
  29. "\"videoId\":\"" + videoId + "\"," +
  30. "\"putScene\":\"" + putScene + "\"," +
  31. "\"channel\":\"" + channel + "\"," +
  32. "\"remark\":\"" + remark + "\"," +
  33. "\"putTypeOne\":\"" + putTypeOne + "\"," +
  34. "\"putTypeTwo\":\"" + putTypeTwo + "\"," +
  35. "\"putTypeThree\":\"" + putTypeThree + "\"," +
  36. "\"putCarrierId\":\"" + putCarrierId + "\"," +
  37. "\"path\":\"" + "pages/category" + "\"," +
  38. "\"requestParam\":{" +
  39. "\"jumpPage\":\"" + "pages/user-videos?id=" + videoId + "&fromGzh=1&rootShareId=" + uuid + "&shareId=" + uuid + "&rootSourceId=[rootSourceId]" + "\"" +
  40. "}" +
  41. "}";
  42. try {
  43. return httpPoolClient.post(url, jsonBody);
  44. } catch (Exception e) {
  45. log.error("sendAdFlowAddRequest error", e);
  46. }
  47. return "";
  48. }
  49. public Map<Long, String> getVideoDetailRequest(List<Long> videoIds) {
  50. Map<Long, String> map = new HashMap<>();
  51. try {
  52. String url = "https://longvideoapi.piaoquantv.com/longvideoapi/openapi/video/batchSelectVideoInfo";
  53. JSONObject params = new JSONObject();
  54. params.put("videoIdList", videoIds);
  55. String post = httpPoolClient.post(url, JSONObject.toJSONString(params));
  56. JSONObject res = JSONObject.parseObject(post);
  57. JSONArray data = res.getJSONArray("data");
  58. for (int i = 0; i < data.size(); i++) {
  59. JSONObject jsonObject = data.getJSONObject(i);
  60. Long videoId = jsonObject.getLong("id");
  61. String shareImgPath = jsonObject.getString("shareImgPath");
  62. map.put(videoId, shareImgPath);
  63. }
  64. } catch (Exception e) {
  65. log.error("getVideoDetailRequest error", e);
  66. }
  67. return map;
  68. }
  69. }