From 056a96fcdcefb6c48acd3147559713c8e93068d7 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期一, 11 九月 2023 22:46:53 +0800 Subject: [PATCH] 代码提交 --- Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/PasswordFreeLoginServiceImpl.java | 39 ++++++++++++++++++++++++++++++++++++--- 1 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/PasswordFreeLoginServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/PasswordFreeLoginServiceImpl.java index ef70cbe..692c097 100644 --- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/PasswordFreeLoginServiceImpl.java +++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/PasswordFreeLoginServiceImpl.java @@ -1,9 +1,17 @@ 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; /** * 鍏嶅瘑鐧诲綍鏈嶅姟 @@ -13,16 +21,41 @@ @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); + + // 鍙戦�丳OST璇锋眰 + ResponseEntity<String> responseEntity = restTemplate.exchange(loginUrl, HttpMethod.POST, requestEntity, String.class); + String responseBody = responseEntity.getBody(); + + //鎷垮埌鍝嶅簲浣撳皢token瀛樺叆鍒皉edis涓紝浠ccount浣滀负瀛樺偍鐨刱ey + + // 瑙f瀽鍝嶅簲浣撹幏鍙栦护鐗� + // 杩欓噷鍋囪鍝嶅簲浣撴槸JSON鏍煎紡锛屽寘鍚竴涓悕涓�"token"鐨勫瓧娈� + // 鏍规嵁瀹為檯鎯呭喌杩涜瑙f瀽 + // JSONObject json = new JSONObject(responseBody); + // String token = json.getString("token"); return false; } -- Gitblit v1.9.3