| | |
| | | package com.vci.ubcs.code.service.impl; |
| | | |
| | | import com.vci.ubcs.code.service.IPasswordFreeLoginService; |
| | | import org.apache.commons.collections4.MultiValuedMap; |
| | | import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | /** |
| | | * 免密登录服务 |
| | |
| | | @Service |
| | | public class PasswordFreeLoginServiceImpl implements IPasswordFreeLoginService { |
| | | |
| | | private RestTemplate restTemplate; |
| | | |
| | | |
| | | /** |
| | | * 免密登录方法 |
| | | * 免密登录 |
| | | * @param account 账号 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean passwordFreeLogin(String account) { |
| | | // 免密登录接口地址 |
| | | String loginUrl = "http://ubcs-auth/auth/login"; |
| | | |
| | | // 设置请求头 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); |
| | | |
| | | //设置请求体参数 |
| | | MultiValueMap<String,String> bodyParams = new LinkedMultiValueMap<String,String>(); |
| | | bodyParams.add("account",account); |
| | | |
| | | // 创建请求实体 |
| | | HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(bodyParams, headers); |
| | | |
| | | // 发送POST请求 |
| | | ResponseEntity<String> responseEntity = restTemplate.exchange(loginUrl, HttpMethod.POST, requestEntity, String.class); |
| | | String responseBody = responseEntity.getBody(); |
| | | |
| | | //拿到响应体将token存入到redis中,以account作为存储的key |
| | | |
| | | // 解析响应体获取令牌 |
| | | // 这里假设响应体是JSON格式,包含一个名为"token"的字段 |
| | | // 根据实际情况进行解析 |
| | | // JSONObject json = new JSONObject(responseBody); |
| | | // String token = json.getString("token"); |
| | | |
| | | return false; |
| | | } |