|
@@ -17,13 +17,16 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.http.*;
|
|
import org.springframework.http.*;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
+import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Component
|
|
@Component
|
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
|
public class DaJiaApiRequestComponent {
|
|
public class DaJiaApiRequestComponent {
|
|
|
|
|
|
|
|
- private final RequestComponent requestComponent;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private final RestTemplate restTemplate;
|
|
|
|
|
|
|
|
private final DaJiaApiProperties daJiaApiProperties;
|
|
private final DaJiaApiProperties daJiaApiProperties;
|
|
|
|
|
|
|
@@ -40,12 +43,26 @@ public class DaJiaApiRequestComponent {
|
|
|
+ InsuranceEnum.DJPC.getName()+"}\n---------> 请求参数:{"
|
|
+ InsuranceEnum.DJPC.getName()+"}\n---------> 请求参数:{"
|
|
|
+JSON.toJSONString(requestBody)+"}");
|
|
+JSON.toJSONString(requestBody)+"}");
|
|
|
String encrypt = AESEncrypt.encrypt(JSON.toJSONString(requestBody), daJiaApiProperties.getEncryptKey());
|
|
String encrypt = AESEncrypt.encrypt(JSON.toJSONString(requestBody), daJiaApiProperties.getEncryptKey());
|
|
|
- ResponseEntity<B> bResponseEntity = requestComponent.objectPost(url, encrypt, responseType, httpHeaders);
|
|
|
|
|
- return bResponseEntity.getBody();
|
|
|
|
|
|
|
+ System.out.println(encrypt);
|
|
|
|
|
+ HttpEntity<String> httpEntity = new HttpEntity<>(encrypt, httpHeaders);
|
|
|
|
|
+ ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
|
|
|
|
|
+ String body = response.getBody();
|
|
|
|
|
+ System.out.println("\n\n---------> 响应参数:{"+body+"}");
|
|
|
|
|
+ B res = JSON.parseObject(body).toJavaObject(responseType);
|
|
|
|
|
+ if(ObjectUtils.isEmpty(body)){
|
|
|
|
|
+ throw new SystemException("请求失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ //统一处理错误
|
|
|
|
|
+ JSONObject resultObj = JSON.parseObject(body);
|
|
|
|
|
+ String code = resultObj.getString("code");
|
|
|
|
|
+ if(!"2000".equals(res.getStatus())) {
|
|
|
|
|
+ throw new SystemException(resultObj.getString("message"));
|
|
|
|
|
+ }
|
|
|
|
|
+ return res;
|
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
|
|
|
+ System.out.println(e.getMessage());
|
|
|
throw new SystemException(e.getMessage());
|
|
throw new SystemException(e.getMessage());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public <T, B extends DaJiaBaseResponse> B requestRequestUrl(RequestUrl requestUrl, T requestBody, Class<B> responseType) {
|
|
public <T, B extends DaJiaBaseResponse> B requestRequestUrl(RequestUrl requestUrl, T requestBody, Class<B> responseType) {
|