|
|
@@ -33,6 +33,7 @@ import com.ydtech.modules.order.entity.api.pingan.utils.checkNull.FieldEmptyExce
|
|
|
import com.ydtech.modules.order.entity.filter.CarModelsFilterUtils;
|
|
|
import com.ydtech.modules.order.utils.InsuranceLog;
|
|
|
import com.ydtech.utils.RequestIdUtils;
|
|
|
+import com.ydtech.utils.StringUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@@ -115,27 +116,29 @@ public class PinganRequestApiComponents {
|
|
|
String clientSecret = properties.getClientSecret();
|
|
|
logger.info("客户端id==========" + clientId);
|
|
|
logger.info("客户端密钥==========" + clientSecret);
|
|
|
- if ((clientId != null && !"".equals(clientId)) && (clientSecret == null && !"".equals(clientSecret))) {
|
|
|
- url = url + "?client_id=" + clientId + "&grant_type=client_credentials&client_secret=" + clientSecret;
|
|
|
- try {
|
|
|
- ResponseEntity<JSONObject> response = restTemplate.exchange(url, HttpMethod.GET, entity, JSONObject.class);
|
|
|
- JSONObject body = response.getBody();
|
|
|
- TokenResponse token = JSON.toJavaObject(body, TokenResponse.class);
|
|
|
- if (token != null) {
|
|
|
- String expiresIn = token.getData().getExpires_in();
|
|
|
- if (expiresIn != null && Integer.parseInt(expiresIn) > 0) {
|
|
|
- return token.getData().getAccess_token();
|
|
|
- } else {
|
|
|
- throw new SystemException("令牌已过期");
|
|
|
- }
|
|
|
+ if(StringUtils.isEmpty(clientId)){
|
|
|
+ throw new SystemException("客户端id为空,请检查配置!!!");
|
|
|
+ }
|
|
|
+ if(StringUtils.isEmpty(clientId)){
|
|
|
+ throw new SystemException("客户端密钥,请检查配置!!!");
|
|
|
+ }
|
|
|
+ url = url + "?client_id=" + clientId + "&grant_type=client_credentials&client_secret=" + clientSecret;
|
|
|
+ try {
|
|
|
+ ResponseEntity<JSONObject> response = restTemplate.exchange(url, HttpMethod.GET, entity, JSONObject.class);
|
|
|
+ JSONObject body = response.getBody();
|
|
|
+ TokenResponse token = JSON.toJavaObject(body, TokenResponse.class);
|
|
|
+ if (token != null) {
|
|
|
+ String expiresIn = token.getData().getExpires_in();
|
|
|
+ if (expiresIn != null && Integer.parseInt(expiresIn) > 0) {
|
|
|
+ return token.getData().getAccess_token();
|
|
|
} else {
|
|
|
- throw new SystemException("返回值为空,请检查访问路径以及参数!!!");
|
|
|
+ throw new SystemException("令牌已过期");
|
|
|
}
|
|
|
- }catch (Exception e) {
|
|
|
- throw new SystemException("接口请求异常,请检查请求路径以及参数");
|
|
|
+ } else {
|
|
|
+ throw new SystemException("返回值为空,请检查访问路径以及参数!!!");
|
|
|
}
|
|
|
- } else {
|
|
|
- throw new SystemException("clientId或clientSecret值为空,请检查配置!!!");
|
|
|
+ }catch (Exception e) {
|
|
|
+ throw new SystemException("接口请求异常,请检查请求路径以及参数");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -165,7 +168,7 @@ public class PinganRequestApiComponents {
|
|
|
//获取令牌token
|
|
|
token = getToken(properties.getAccessUrl());
|
|
|
}catch (Exception e){
|
|
|
- throw new SystemException("接口请求异常,请检查请求路径以及参数");
|
|
|
+ throw new SystemException(e.getMessage());
|
|
|
}
|
|
|
|
|
|
if (token == null) {
|
|
|
@@ -241,7 +244,7 @@ public class PinganRequestApiComponents {
|
|
|
throw new SystemException(requestUrl.getCode()+"-"+requestUrl.getDesc()+"-"+requestUrl.getUrl()+"接口返回信息"+PinAnEnumUtils.getEnumValueByCode(enumCodeClass,response.getResultCode()));
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- throw new SystemException(requestUrl.getCode()+"-"+requestUrl.getDesc()+"-"+requestUrl.getUrl()+"接口报错,请检查请求路径及参数");
|
|
|
+ throw new SystemException(requestUrl.getCode()+"-"+requestUrl.getDesc()+"-"+requestUrl.getUrl()+"接口报错:"+e.getMessage());
|
|
|
}
|
|
|
return response;
|
|
|
}
|