【登录】安眼统一认证
This commit is contained in:
+4
-1
@@ -96,12 +96,14 @@ public class AnYanClientExecutor implements AnYanClient {
|
||||
@Override
|
||||
public AuthResult getAuthTokenByPassword(String username, String password) {
|
||||
try {
|
||||
|
||||
String encryptPassword = StringUtils.encryptByPublicKey(publicKey, password);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
|
||||
formData.add("grant_type", "password");
|
||||
formData.add("username", username);
|
||||
formData.add("password", password);
|
||||
formData.add("password", encryptPassword);
|
||||
formData.add("client_id", anYanProperties.getClientId());
|
||||
formData.add("client_secret", anYanProperties.getClientSecret());
|
||||
ResponseEntity<AuthResult> authResult = RestTemplateUtil.postExchangeForGetTokenByPassword(AnYanApiEnum.QUERY_AUTH_TOKEN, formData, headers, AuthResult.class);
|
||||
@@ -114,6 +116,7 @@ public class AnYanClientExecutor implements AnYanClient {
|
||||
return null;
|
||||
}
|
||||
} catch (HttpClientErrorException e) {
|
||||
log.error("------安眼系统获取token失败(密码模式){}------", e.getMessage());
|
||||
String replace = Objects.requireNonNull(e.getMessage()).replace("401 Unauthorized: ", "");
|
||||
replace = replace.replace("\"", "");
|
||||
AuthResult bean = JSONUtil.toBean(replace, AuthResult.class);
|
||||
|
||||
+3
-3
@@ -62,7 +62,7 @@ public class RestTemplateUtil {
|
||||
public static <T> ResponseEntity<T> postExchangeForGetTokenByPassword(AnYanApiEnum api, MultiValueMap<String, String> formData, HttpHeaders headers, Class<T> responseType) {
|
||||
String url = getProperties().getPublicHost() + api.getMethodPath();
|
||||
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(formData, headers);
|
||||
log.info("开始发送请求到: {}", url);
|
||||
log.info("开始发送请求到: {},入参:{}", url, formData);
|
||||
ResponseEntity<T> response = getRestTemplate().exchange(url, api.getHttpMethod(), requestEntity, responseType);
|
||||
log.info("收到响应: {}", response);
|
||||
return response;
|
||||
@@ -98,8 +98,8 @@ public class RestTemplateUtil {
|
||||
/**
|
||||
* 通用调用方法
|
||||
*
|
||||
* @param api 请求接口
|
||||
* @param headers 请求头
|
||||
* @param api 请求接口
|
||||
* @param headers 请求头
|
||||
* @return Result对象
|
||||
*/
|
||||
public static <T> ResponseEntity<T> getExchange(AnYanApiEnum api, HttpHeaders headers, Class<T> responseType) {
|
||||
|
||||
Reference in New Issue
Block a user