|
@@ -1,6 +1,8 @@
|
|
|
package com.tzld.longarticle.recommend.server.service.cgi;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.tzld.longarticle.recommend.server.model.cgi.GroupData;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -8,8 +10,7 @@ import org.springframework.web.reactive.function.BodyInserters;
|
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-import java.util.UUID;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class TouLiuHttpClientService {
|
|
@@ -79,6 +80,40 @@ public class TouLiuHttpClientService {
|
|
|
return JSON.parseArray(block, GroupData.class);
|
|
|
}
|
|
|
|
|
|
- // 注意:在实际使用时,你还需要导入相关类和处理异常,以及添加@Service注解到你的服务类上
|
|
|
+ public static Map<Long, String> getVideoDetailRequest(List<Long> videoIds) {
|
|
|
+ Map<Long, String> map = new HashMap<>();
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ params.put("videoIdList", videoIds);
|
|
|
+ WebClient webClient = WebClient.builder()
|
|
|
+ .baseUrl("https://longvideoapi.piaoquantv.com")
|
|
|
+ .build();
|
|
|
+
|
|
|
+ // 发送POST请求
|
|
|
+ Mono<String> result = webClient.post()
|
|
|
+ .uri("/longvideoapi/openapi/video/batchSelectVideoInfo")
|
|
|
+ .contentType(MediaType.APPLICATION_JSON)
|
|
|
+ .body(BodyInserters.fromValue(params.toJSONString()))
|
|
|
+ .retrieve()
|
|
|
+ .bodyToMono(String.class);
|
|
|
+ String block = result.block();
|
|
|
+ JSONObject res = JSONObject.parseObject(block);
|
|
|
+ JSONArray data = res.getJSONArray("data");
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
+ JSONObject jsonObject = data.getJSONObject(i);
|
|
|
+ Long videoId = jsonObject.getLong("id");
|
|
|
+ String shareImgPath = jsonObject.getString("shareImgPath");
|
|
|
+ map.put(videoId, shareImgPath);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ List<Long> list = new ArrayList<>();
|
|
|
+ list.add(13586800L);
|
|
|
+ System.out.println(getVideoDetailRequest(list));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 注意:在实际使用时,你还需要导入相关类和处理异常,以及添加@Service注解到你的服务类上
|
|
|
// 另外,请确保MediaType已正确导入,它来自org.springframework.http包
|
|
|
}
|