Commit 0e76b1ac authored by linruibiao's avatar linruibiao

接口编写

parent 29667bb4
......@@ -82,27 +82,30 @@ public class BaseRestController {
}
log.info("请求头参数--->>>>"+SlmConstants.gson.toJson(headers));
token=request.getHeader("token");
if(StringUtils.isEmpty(token)){
throw new SysException("token不能为空");
if(!uri.contains("tokens")) {
if (StringUtils.isEmpty(token)) {
throw new SysException("token不能为空");
}
log.info("获取用户信息");
NativeWebRequest webRequest = new ServletWebRequest(request);
Map<String, String> map = (Map<String, String>) webRequest.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
// Map<String, Object> map = (Map<String, Object>) webRequest.getAttribute(View.PATH_VARIABLES, RequestAttributes.SCOPE_REQUEST);
Map<String,String> heads = Maps.newHashMap();
heads.put("token",token);
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("appId",map.get("appId")+"");
String getUrl =dcClientHost+"/{appId}/users/user-info";
R<Map<String,Object>> result = RestTemplateUtils.get(getUrl, heads, new TypeToken<R<Map<String,Object>>>() {}.getType(), uriVariables);
Map<String,Object> userInfo= result.detach();
currentUser = new CurrentUser();
currentUser.setUid(userInfo.get("uid")+"");
currentUser.setPlatformId(userInfo.get("platform_id")+"");
currentUser.setName(userInfo.get("real_name")+"");
currentUser.setAppId(userInfo.get("app_id")+"");
currentUser.setToken(token);
request.getSession().setAttribute(token, SlmConstants.gson.toJson(currentUser));
}
log.info("获取用户信息");
NativeWebRequest webRequest = new ServletWebRequest(request);
Map<String, String> map = (Map<String, String>) webRequest.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
// Map<String, Object> map = (Map<String, Object>) webRequest.getAttribute(View.PATH_VARIABLES, RequestAttributes.SCOPE_REQUEST);
Map<String,String> heads = Maps.newHashMap();
heads.put("token",token);
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("appId",map.get("appId")+"");
String getUrl =dcClientHost+"/{appId}/users/user-info";
R<Map<String,Object>> result = RestTemplateUtils.get(getUrl, heads, new TypeToken<R<Map<String,Object>>>() {}.getType(), uriVariables);
Map<String,Object> userInfo= result.detach();
currentUser = new CurrentUser();
currentUser.setUid(userInfo.get("uid")+"");
currentUser.setPlatformId(userInfo.get("platform_id")+"");
currentUser.setName(userInfo.get("real_name")+"");
currentUser.setAppId(userInfo.get("app_id")+"");
currentUser.setToken(token);
request.getSession().setAttribute(token, SlmConstants.gson.toJson(currentUser));
}
R<Object> call(Action0 action) {
......
......@@ -24,7 +24,7 @@ import java.util.Map;
* @date : 2021-04-14 16:17
**/
@RestController
@RequestMapping("/token")
@RequestMapping("/tokens")
@Api(value ="获取token",tags = "获取token")
public class TokenController extends BaseRestController{
@PostMapping
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment