|
|
package com.yohobuy.ufo.login.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yohobuy.ufo.constants.PlatformConstant;
|
|
|
import com.yohobuy.ufo.login.model.MenuInfoResponseBO;
|
|
|
import com.yohobuy.ufo.login.model.Response;
|
...
|
...
|
@@ -10,6 +11,8 @@ import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
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 org.springframework.util.LinkedMultiValueMap;
|
...
|
...
|
@@ -46,22 +49,25 @@ public class LoginService { |
|
|
String url = erpDomain + PlatformConstant.ERP_LOGIN_URL;
|
|
|
logger.info("enter login with loginName={}, url is {}", loginName, url);
|
|
|
|
|
|
MultiValueMap<String, String> param = new LinkedMultiValueMap<String, String>();
|
|
|
param.add("account", loginName);
|
|
|
param.add("password", password);
|
|
|
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(param, null);
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
headers.setContentType(type);
|
|
|
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
|
|
|
JSONObject jsonObj = new JSONObject();
|
|
|
jsonObj.put("account", loginName);
|
|
|
jsonObj.put("password", password);
|
|
|
HttpEntity<String> formEntity = new HttpEntity<String>(jsonObj.toString(), headers);
|
|
|
|
|
|
ResponseEntity<Response> responseResponseEntity = restTemplate.postForEntity(url, requestEntity, Response.class);
|
|
|
ResponseEntity<Object> responseResponseEntity = restTemplate.postForEntity(url, formEntity, Object.class);
|
|
|
Map<String, Object> body = (Map<String, Object>) responseResponseEntity.getBody();
|
|
|
Map<String, Object> data = (Map<String, Object>) body.get("data");
|
|
|
|
|
|
|
|
|
logger.info("login success with loginName={}, responseResponseEntity={}", loginName, responseResponseEntity);
|
|
|
UserInfoResponseBO user = new UserInfoResponseBO();
|
|
|
Response body = responseResponseEntity.getBody();
|
|
|
Object data = body.getData();
|
|
|
|
|
|
logger.info("login success with loginName={}, data={}", loginName, data);
|
|
|
|
|
|
setUser((Map<String, Object>) data, user);
|
|
|
setUser(data, user);
|
|
|
return new Response<>(user);
|
|
|
}
|
|
|
|
...
|
...
|
|