Digital Office Automation System Backend
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.ruoyi.system.utils;
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.springframework.beans.factory.annotation.Value;
  4. import org.springframework.http.ResponseEntity;
  5. import org.springframework.stereotype.Component;
  6. import org.springframework.web.client.RestTemplate;
  7. import org.springframework.web.util.UriComponentsBuilder;
  8. import java.util.HashMap;
  9. import java.util.Map;
  10. //调用获取商品信息工具类
  11. @Component
  12. @Slf4j
  13. public class HttpUtil {
  14. private static String BASE_URL;
  15. @Value("${zs-operation.url}")
  16. public void setBaseUrl(String baseUrl) {
  17. HttpUtil.BASE_URL = baseUrl;
  18. }
  19. private static final RestTemplate restTemplate = new RestTemplate();
  20. /**
  21. * 发送GET请求并处理响应
  22. * @param url 请求URL
  23. * @param needScreenshot 是否需要截图
  24. * @return 响应结果
  25. */
  26. public static Map<String, Object> sendGetRequest(String url, boolean needScreenshot,String platform) {
  27. Long start = System.currentTimeMillis();
  28. try {
  29. // 构建请求URL和参数
  30. UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(BASE_URL)
  31. .queryParam("url", url)
  32. .queryParam("needScreenshot", needScreenshot)
  33. .queryParam("platform", platform);
  34. // 发送GET请求
  35. ResponseEntity<Map> response = restTemplate.getForEntity(builder.toUriString(), Map.class);
  36. Map body = response.getBody();
  37. Long end = System.currentTimeMillis();
  38. log.info("调用获取商品最新信息接口耗时=:"+(end-start));
  39. return body;
  40. } catch (Exception e) {
  41. Map<String, Object> reMap = new HashMap<>();
  42. reMap.put("success", false);
  43. reMap.put("message", "请求发生错误: " + e.getMessage());
  44. return reMap;
  45. }
  46. }
  47. }