| | |
| | | package com.iailab.sdk.auth.client; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.iailab.sdk.auth.client.dto.TokenDTO; |
| | | import com.iailab.sdk.auth.config.AuthProperties; |
| | | import com.iailab.sdk.auth.constants.SdkErrorCodeConstants; |
| | | import com.iailab.sdk.util.http.IailabHttpUtils; |
| | | import org.springframework.core.ParameterizedTypeReference; |
| | | import org.springframework.http.*; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | private static final String GRAND_TYPE = "password"; |
| | | |
| | | private static final String SCOPE = "user.read user.write"; |
| | | |
| | | private static final String CHARSET = "utf-8"; |
| | | |
| | | // 鉴权token |
| | | public static String accessToken; |
| | |
| | | return handleResponse(exchange); |
| | | } |
| | | |
| | | /** |
| | | * 平台http请求封装 |
| | | * @param method |
| | | * @param url |
| | | * @param params |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static String doHttp(String method, String url, Map<String, Object> params) throws Exception { |
| | | String response = null; |
| | | String upperMethod = method.toUpperCase(); |
| | | if("GET".equals(upperMethod)) { |
| | | response = IailabHttpUtils.doGet(url, params, CHARSET); |
| | | } else if("POST".equals(upperMethod)) { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | response = IailabHttpUtils.doPost(url, objectMapper.writeValueAsString(params), CHARSET); |
| | | } |
| | | return response; |
| | | } |
| | | |
| | | private static void addClientHeader(HttpHeaders headers) { |
| | | // client 拼接,需要 BASE64 编码 |
| | | String client = authProperties.getClientId() + ":" + authProperties.getClientSecret(); |