ClientCustomerServiceHttpClient.java 1.52 KB
package com.infoloop.tianting.service.client;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.infoloop.tianting.model.dto.ClientCustomerDbDTO.CurrentClientCustomerDto;
import com.infoloop.tianting.model.dto.WxUserDto.WxUserOpenIdDto;
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ClientCustomerServiceHttpClient {
  private final OkHttpClient client = new OkHttpClient();

  public List<CurrentClientCustomerDto> getCurrentClientCustomer() {
    ObjectMapper objectMapper = new ObjectMapper();
    try {
      String url = "http://47.101.193.136:3031/clientcustomers/current/query";
      Request request = new Request.Builder()
          .url(url)
          .build();

      Response response = client.newCall(request).execute();

      String jsonData = response.body().string();
      System.out.println(jsonData);
      objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//      return objectMapper.readValue(jsonData, WxUserOpenIdDto.class);
      return new ArrayList<>();
    } catch (Exception e) {
      System.out.println("error"+e.getMessage());
      throw new IllegalArgumentException("获取用户openid失败");
    }
  }
}