package com.qiuguo.iot.third.service;

import com.qiuguo.iot.data.resp.third.ThirdIpInfoResp;
import com.qiuguo.iot.data.resp.third.ThirdRpcResp;
import org.springframework.beans.factory.annotation.Value;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

/**
 * @author simon
 * @date 2023/9/21
 * @description ip查询
 **/

@Service
@Slf4j
public class IpService {
   @Value("https://qiuguo-app.qiuguojihua.com/prod-api/third/ip/info")
   public String thirdIpInfoUrl;

   /**
    * 查询ip信息
    * @param ip
    * @return
    */
   public Mono<ThirdRpcResp<ThirdIpInfoResp>> getIpInfo(String ip) {
      WebClient webClient = WebClient.builder().build();
      return webClient.get().uri(thirdIpInfoUrl + "?ip=" + ip).retrieve().bodyToMono(ThirdRpcResp.getResponseIpType());
   }
}
