|
|
@@ -3,6 +3,7 @@ package com.zd.forward.serivce;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.zd.common.core.constant.SecurityConstants;
|
|
|
import com.zd.common.core.domain.R;
|
|
|
+import com.zd.common.core.exception.ServiceException;
|
|
|
import com.zd.common.security.service.TokenService;
|
|
|
import com.zd.forward.config.AlgorithmYml;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -15,6 +16,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.Assert;
|
|
|
+import org.springframework.web.client.RestClientException;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
@@ -54,13 +56,17 @@ public class LoginService {
|
|
|
map.put("username", "admin");
|
|
|
map.put("password", "zd123456..");
|
|
|
ParameterizedTypeReference<R<Map<String, Object>>> reference = new ParameterizedTypeReference<R<Map<String, Object>>>(){};
|
|
|
- ResponseEntity<R<Map<String, Object>>> response = restTemplate.exchange(url, HttpMethod.POST, new HttpEntity<>(map), reference);
|
|
|
- R<Map<String, Object>> parse = response.getBody();
|
|
|
- if (parse != null) {
|
|
|
- Assert.isTrue(parse.getCode() == R.SUCCESS, "登录失败:" + parse.getMsg());
|
|
|
- //拿到token
|
|
|
- Map<String, Object> data = parse.getData();
|
|
|
- setToken("Bearer " + data.get("access_token"));
|
|
|
+ try {
|
|
|
+ ResponseEntity<R<Map<String, Object>>> response = restTemplate.exchange(url, HttpMethod.POST, new HttpEntity<>(map), reference);
|
|
|
+ R<Map<String, Object>> parse = response.getBody();
|
|
|
+ if (parse != null) {
|
|
|
+ Assert.isTrue(parse.getCode() == R.SUCCESS, "登录失败:" + parse.getMsg());
|
|
|
+ //拿到token
|
|
|
+ Map<String, Object> data = parse.getData();
|
|
|
+ setToken("Bearer " + data.get("access_token"));
|
|
|
+ }
|
|
|
+ } catch (RestClientException e) {
|
|
|
+ throw new ServiceException(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|