一、自定义WxRealm,继承自AuthorizingRealm
package com.ruoyi.framework.shiro.realm;
import com.ruoyi.customer.domain.CustomerInfo;
import com.ruoyi.customer.domain.CustomerLoginLog;
import com.ruoyi.customer.service.ICustomerInfoService;
import com.ruoyi.customer.service.ICustomerLoginLogService;
import com.ruoyi.customer.service.ICustomerLoginService;
import com.ruoyi.framework.shiro.service.SysLoginService;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.ISysMenuService;
import com.ruoyi.system.service.ISysRoleService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.HashSet;
import java.util.Set;
/**
* 微信权限控制
*/
public class WxRealm extends AuthorizingRealm {
@Autowired
private ISysMenuService menuService;
@Autowired
private ISysRoleService roleService;
@Autowired
private SysLoginService loginService;
@Autowired
private ICustomerLoginService customerLoginService;
@Autowired
private ICustomerInfoService customerInfoService;
@Autowired
private ICustomerLoginLogService customerLoginLogService;
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
SysUser user = ShiroUtils.getSysUser();
// 角色列表
Set<String> roles = new HashSet<String>();
// 功能列表
Set<String> menus = new HashSet<String>();
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
// 管理员拥有所有权限
if (user.isAdmin())
{
info.addRole("admin");
info.addStringPermission("*:*:*");
}
else
{
roles = roleService.selectRoleKeys(user.getUserId());
menus = menuService.selectPermsByUserId(user.getUserId());
// 角色加入AuthorizationInfo认证对象
info.setRoles(roles);
// 权限加入AuthorizationInfo认证对象
info.setStringPermissions(menus);
}
return info;
}
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
//微信平台登录
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
String username = upToken.getUsername();
String password = "";
if (upToken.getPassword() != null)
{
password = new String(upToken.getPassword());
}
SimpleAuthenticationInfo info=null;
Long customer_id=customerLoginService.selectCustomerByOpenid(upToken.getUsername());
if(customer_id == null){
//新客户,返回重新注册新增客户信息
System.out.println("======================新的用户======================");
throw new UnknownAccountException();
}else{
//已存在用户
//添加用户登录日志
CustomerLoginLog customerLoginLog=new CustomerLoginLog();
customerLoginLog.setCustomerId(customer_id);
customerLoginLogService.insertCustomerLoginLog(customerLoginLog);
CustomerInfo customerInfo=customerInfoService.selectCustomerInfoByCustomerid(customer_id);
info = new SimpleAuthenticationInfo(customerInfo, ((UsernamePasswordToken) token).getPassword(), customerInfo.getNickName());
}
return info;
}
/**
* 清理缓存权限
*/
public void clearCachedAuthorizationInfo()
{
this.clearCachedAuthorizationInfo(SecurityUtils.getSubject().getPrincipals());
}
}
二、添加WxSessionManager,解决微信没有浏览器session,人工将session放入request请求head中之后,后台session获取的问题,经过该类处理,shiro会自动将抓取的session与服务端比较
package com.ruoyi.framework.shiro.web.session;
import com.ruoyi.common.constant.ShiroConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.shiro.session.OnlineSession;
import com.ruoyi.system.domain.SysUserOnline;
import com.ruoyi.system.service.ISysUserOnlineService;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.shiro.session.ExpiredSessionException;
import org.apache.shiro.session.InvalidSessionException;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.DefaultSessionKey;
import org.apache.shiro.session.mgt.SessionKey;
import org.apache.shiro.web.servlet.ShiroHttpServletRequest;
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.apache.shiro.web.util.WebUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
/**
* 自定义session管理器,重写getSessionId方法
* 继承DefaultWebSessionManager,重写getSessionId方法,逻辑是如果请求头中有token,就分析token,没有就调用父类的方法,依然按原先分析cookie中的参数
* author zxy
*/
public class WxSessionManager extends DefaultWebSessionManager {
/**
* 这个是客户端请求给服务端带的header
*/
public final static String HEADER_TOKEN_NAME = "X-Nideshop-Token";
public final static Logger LOG = LoggerFactory.getLogger(WxSessionManager.class);
private static final String REFERENCED_SESSION_ID_SOURCE = "Stateless request";
/**
* 重写getSessionId,分析请求头中的指定参数,做用户凭证sessionId
*/
@Override
protected Serializable getSessionId(ServletRequest request, ServletResponse response){
String id = WebUtils.toHttp(request).getHeader(HEADER_TOKEN_NAME);
//System.out.println("id:"+id);
if(StringUtils.isEmpty(id)){
//如果没有携带id参数则按照父类的方式在cookie进行获取
// System.out.println("super:"+super.getSessionId(request, response));
return super.getSessionId(request, response);
}else{
//如果请求头中有 authToken 则其值为sessionId
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE,REFERENCED_SESSION_ID_SOURCE);
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID,id);
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_IS_VALID,Boolean.TRUE);
return id;
}
}
}
三、ShiroConfig注入WxRealm和WxSessionManager
package com.ruoyi.framework.config;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.servlet.Filter;
import com.ruoyi.framework.shiro.realm.WxRealm;
import com.ruoyi.framework.shiro.web.session.WxSessionManager;
import org.apache.commons.io.IOUtils;
import org.apache.shiro.cache.ehcache.EhCacheManager;
import org.apache.shiro.codec.Base64;
import org.apache.shiro.config.ConfigurationException;
import org.apache.shiro.io.ResourceUtils;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.CookieRememberMeManager;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.apache.shiro.web.servlet.SimpleCookie;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.shiro.realm.UserRealm;
import com.ruoyi.framework.shiro.session.OnlineSessionDAO;
import com.ruoyi.framework.shiro.session.OnlineSessionFactory;
import com.ruoyi.framework.shiro.web.filter.LogoutFilter;
import com.ruoyi.framework.shiro.web.filter.captcha.CaptchaValidateFilter;
import com.ruoyi.framework.shiro.web.filter.kickout.KickoutSessionFilter;
import com.ruoyi.framework.shiro.web.filter.online.OnlineSessionFilter;
import com.ruoyi.framework.shiro.web.filter.sync.SyncOnlineSessionFilter;
import com.ruoyi.framework.shiro.web.session.OnlineWebSessionManager;
import com.ruoyi.framework.shiro.web.session.SpringSessionValidationScheduler;
import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
/**
* 权限配置加载
*
* @author ruoyi
*/
@Configuration
public class ShiroConfig
{
//自定义一个cookie名称
private static String cookieId = "WX_TOKEN";
public static final String PREMISSION_STRING = "perms[\"{0}\"]";
// Session超时时间,单位为毫秒(默认30分钟)
@Value("${shiro.session.expireTime}")
private int expireTime;
// 相隔多久检查一次session的有效性,单位毫秒,默认就是10分钟
@Value("${shiro.session.validationInterval}")
private int validationInterval;
// 同一个用户最大会话数
@Value("${shiro.session.maxSession}")
private int maxSession;
// 踢出之前登录的/之后登录的用户,默认踢出之前登录的用户
@Value("${shiro.session.kickoutAfter}")
private boolean kickoutAfter;
// 验证码开关
@Value("${shiro.user.captchaEnabled}")
private boolean captchaEnabled;
// 验证码类型
@Value("${shiro.user.captchaType}")
private String captchaType;
// 设置Cookie的域名
@Value("${shiro.cookie.domain}")
private String domain;
// 设置cookie的有效访问路径
@Value("${shiro.cookie.path}")
private String path;
// 设置HttpOnly属性
@Value("${shiro.cookie.httpOnly}")
private boolean httpOnly;
// 设置Cookie的过期时间,秒为单位
@Value("${shiro.cookie.maxAge}")
private int maxAge;
// 登录地址
@Value("${shiro.user.loginUrl}")
private String loginUrl;
// 权限认证失败地址
@Value("${shiro.user.unauthorizedUrl}")
private String unauthorizedUrl;
/**
* 缓存管理器 使用Ehcache实现
*/
@Bean
public EhCacheManager getEhCacheManager()
{
net.sf.ehcache.CacheManager cacheManager = net.sf.ehcache.CacheManager.getCacheManager("ruoyi");
EhCacheManager em = new EhCacheManager();
if (StringUtils.isNull(cacheManager))
{
em.setCacheManager(new net.sf.ehcache.CacheManager(getCacheManagerConfigFileInputStream()));
return em;
}
else
{
em.setCacheManager(cacheManager);
return em;
}
}
/**
* 返回配置文件流 避免ehcache配置文件一直被占用,无法完全销毁项目重新部署
*/
protected InputStream getCacheManagerConfigFileInputStream()
{
String configFile = "classpath:ehcache/ehcache-shiro.xml";
InputStream inputStream = null;
try
{
inputStream = ResourceUtils.getInputStreamForPath(configFile);
byte[] b = IOUtils.toByteArray(inputStream);
InputStream in = new ByteArrayInputStream(b);
return in;
}
catch (IOException e)
{
throw new ConfigurationException(
"Unable to obtain input stream for cacheManagerConfigFile [" + configFile + "]", e);
}
finally
{
IOUtils.closeQuietly(inputStream);
}
}
/**
* 自定义Realm
*/
@Bean
public UserRealm userRealm(EhCacheManager cacheManager)
{
UserRealm userRealm = new UserRealm();
userRealm.setCacheManager(cacheManager);
return userRealm;
}
/**
* 注入自定义的 Realm
* @return MyRealm
*/
@Bean
public WxRealm wxRealm() {
WxRealm wx_Realm = new WxRealm();
return wx_Realm;
}
/**
* 会话管理器
*/
@Bean
public WxSessionManager sessionManager()
{
// OnlineWebSessionManager manager = new OnlineWebSessionManager();
WxSessionManager manager = new WxSessionManager();
// 加入缓存管理器
manager.setCacheManager(getEhCacheManager());
// 删除过期的session
manager.setDeleteInvalidSessions(true);
// 设置全局session超时时间
manager.setGlobalSessionTimeout(expireTime * 60 * 1000);
// 去掉 JSESSIONID
manager.setSessionIdUrlRewritingEnabled(false);
// 定义要使用的无效的Session定时调度器
manager.setSessionValidationScheduler(SpringUtils.getBean(SpringSessionValidationScheduler.class));
// 是否定时检查session
manager.setSessionValidationSchedulerEnabled(true);
return manager;
}
/**
* 注入微信安全管理器
* @return SecurityManager
*/
@Bean
public SecurityManager securityManager() {
// 将自定义 Realm 加进来
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(wxRealm());
// 注入缓存管理器;
securityManager.setCacheManager(getEhCacheManager());
// session管理器
securityManager.setSessionManager(sessionManager());
return securityManager;
}
/**
* 退出过滤器
*/
public LogoutFilter logoutFilter()
{
LogoutFilter logoutFilter = new LogoutFilter();
logoutFilter.setCacheManager(getEhCacheManager());
logoutFilter.setLoginUrl(loginUrl);
return logoutFilter;
}
/**
* Shiro过滤器配置
*/
@Bean
public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager)
{
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
// Shiro的核心安全接口,这个属性是必须的
shiroFilterFactoryBean.setSecurityManager(securityManager);
// 身份认证失败,则跳转到登录页面的配置
shiroFilterFactoryBean.setLoginUrl(loginUrl);
// 权限认证失败,则跳转到指定页面
shiroFilterFactoryBean.setUnauthorizedUrl(unauthorizedUrl);
// Shiro连接约束配置,即过滤链的定义
LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
// 对静态资源设置匿名访问
filterChainDefinitionMap.put("/favicon.ico**", "anon");
filterChainDefinitionMap.put("/ruoyi.png**", "anon");
filterChainDefinitionMap.put("/css/**", "anon");
filterChainDefinitionMap.put("/docs/**", "anon");
filterChainDefinitionMap.put("/fonts/**", "anon");
filterChainDefinitionMap.put("/img/**", "anon");
filterChainDefinitionMap.put("/ajax/**", "anon");
filterChainDefinitionMap.put("/js/**", "anon");
filterChainDefinitionMap.put("/ruoyi/**", "anon");
filterChainDefinitionMap.put("/captcha/captchaImage**", "anon");
// 退出 logout地址,shiro去清除session
filterChainDefinitionMap.put("/logout", "logout");
// 不需要拦截的访问
filterChainDefinitionMap.put("/customer/getToken", "anon");
filterChainDefinitionMap.put("/customer/register", "anon");
filterChainDefinitionMap.put("/customer/login", "anon");
filterChainDefinitionMap.put("/login", "anon");
filterChainDefinitionMap.put("/getTestUser", "anon");
filterChainDefinitionMap.put("/getWord", "anon");
// 注册相关
filterChainDefinitionMap.put("/register", "anon");
// 系统权限列表
// filterChainDefinitionMap.putAll(SpringUtils.getBean(IMenuService.class).selectPermsAll());
Map<String, Filter> filters = new LinkedHashMap<String, Filter>();
// 注销成功,则跳转到指定页面
filters.put("logout", logoutFilter());
shiroFilterFactoryBean.setFilters(filters);
// 所有请求需要认证
filterChainDefinitionMap.put("/**", "user");
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
return shiroFilterFactoryBean;
}
/**
* cookie 属性设置
*/
public SimpleCookie rememberMeCookie()
{
SimpleCookie cookie = new SimpleCookie("rememberMe");
cookie.setDomain(domain);
cookie.setPath(path);
cookie.setHttpOnly(httpOnly);
cookie.setMaxAge(maxAge * 24 * 60 * 60);
return cookie;
}
}
三、微信和控制器
1、通过wx.login获取code,使用code到服务端换取openid和服务器返回的sessionid,注意,sessionid不要使用微信提供的“session_key”(使用微信提供的,后续很难与服务端匹配上)
return new Promise(function (resolve, reject) {
wx.login({
success: function (res) {
if (res.code) {
//登录远程服务器
var code = res.code;
//获取token
util.request(api.GetTokenUrl, { code: code }).then(function (res) {
console.log(res.session_key);
var session_key = res.session_key;
var openid = res.openid;
wx.setStorageSync('token', session_key);
util.login(code, openid);
console.log('=============测试开始================');
setTimeout(test, 5000);
})
}
else {
reject(res);
}
},
fail: function (err) {
reject(err);
}
});
});
2、根据返回的session,通过“wx.setStorageSync('token', session_key);”设置到全局变量,后续所有请求head都带上
/**
* 封封微信的的request
*/
function request(url, data = {}, method = "GET") {
return new Promise(function (resolve, reject) {
wx.request({
url: url,
data: data,
method: method,
header: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Nideshop-Token': wx.getStorageSync('token')
},
success: function (res) {
console.log("success");
if (res.statusCode == 200) {
if (res.data.errno == 401) {
//需要登录后才可以操作
// wx.showModal({
// title: '',
// content: '请先登录',
// success: function (res){
// if (res.confirm) {
// wx.removeStorageSync("userInfo");
// wx.removeStorageSync("token");
// wx.switchTab({
// url: '/pages/ucenter/index/index'
// });
// }
// }
// });
} else {
resolve(res.data);
}
} else {
reject(res.errMsg);
}
},
fail: function (err) {
reject(err)
console.log("failed")
}
})
});
3、其他涉及到的注册和登录方法
/**
* 调用微信登录
*/
function login(code,openid) {
//发起网络请求
wx.request({
url: api.LoginUrl,
method: "GET",
header: {
'content-type': 'application/x-www-form-urlencoded',
'X-Nideshop-Token': wx.getStorageSync('token')
},
data: {
code: code,
openid: openid,
session_key: wx.getStorageSync('token')
},
success: function (res) {
console.log(wx.getStorageSync('token'));
if (res.data.result == "0") {
//登录失败
console.log(res.data.msg);
} else if (res.data.result == "2") {
//新用户,先去注册
register(openid);
//注册完成,再次登录
login();
} else if (res.data.result == "1") {
console.log('===========登录成功==============');
}
},
fail: function (error) {
console.log(error);
}
});
}
/**
* 使用微信openid进行注册
*/
function register(openid){
wx.getUserInfo({
success: function (res) {
var userInfo = res.userInfo
var nickName = userInfo.nickName
var avatarUrl = userInfo.avatarUrl
var gender = userInfo.gender //性别 0:未知、1:男、2:女
var province = userInfo.province
var city = userInfo.city
var country = userInfo.country
wx.request({
url: api.Register,
method: "GET",
header: {
'Content-Type': 'application/json'
},
data: {
openid: openid,
nickName: nickName,
avatarUrl: avatarUrl,
gender: gender,
province: province,
city: city,
country: country
},
success: function (res) {
console.log('注册成功==============' + res.data.result);
if (res.result == "1") {
}
},
fail: function (error) {
console.log(error);
}
});
}
})
}
4、控制器
package com.ruoyi.controller.customer;
import com.alibaba.fastjson.JSONArray;
import com.mysql.cj.xdevapi.JsonArray;
import com.mysql.cj.xdevapi.JsonString;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.user.UserNotExistsException;
import com.ruoyi.common.json.JSONObject;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.controller.common.CommonController;
import com.ruoyi.customer.domain.CustomerInfo;
import com.ruoyi.customer.domain.CustomerLogin;
import com.ruoyi.customer.domain.CustomerLoginLog;
import com.ruoyi.customer.service.ICustomerLoginService;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.WxSeeionObject;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping("/customer")
public class CustomerLoginController extends BaseController {
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
@Autowired
private ICustomerLoginService customerLoginService;
/**
* 登录
* @param request
* @return
*/
@RequestMapping("getToken")
@ResponseBody
public Map<String, Object> getToken(HttpServletRequest request){
String sessionid=request.getSession().getId();
String code=request.getParameter("code");
String result= HttpUtils.sendGet("https://api.weixin.qq.com/sns/jscode2session","appid=wx3bb68f95e5c2b2cf&secret=1a0e79d36e22ddc797c071c4e13cecc1&js_code="+code+"&grant_type=authorization_code");
System.out.println(result);
WxSeeionObject wxSeeionObject= JSONArray.parseObject(result,WxSeeionObject.class);
Map<String, Object> map = new HashMap<String, Object>();
map.put("openid",wxSeeionObject.getOpenid());
map.put("session_key",sessionid);
return map;
}
/**
* 登录
* @param request
* @return
*/
@RequestMapping("login")
@ResponseBody
public Map<String, Object> login(HttpServletRequest request){
String openid=request.getParameter("openid");
String session_key=request.getParameter("session_key");
UsernamePasswordToken token = new UsernamePasswordToken(openid, session_key, false, "wx");
Subject subject = SecurityUtils.getSubject();
Map<String, Object> map = new HashMap<String, Object>();
try
{
subject.login(token);
map.put("result","1");
}
catch (UnknownAccountException e)
{
//新客户,需要新增注册
map.put("result","2");
}
catch (AuthenticationException e)
{
map.put("result","0");
map.put("msg","请使用微信登录平台");
}
return map;
}
/**
* 注册
* @param request
* @return
*/
@RequestMapping("register")
@ResponseBody
public Map<String, Object> register(HttpServletRequest request){
String openid=request.getParameter("openid");
String nickName=request.getParameter("nickName");
String avatarUrl=request.getParameter("avatarUrl");
String gender=request.getParameter("gender");
String province=request.getParameter("province");
String city=request.getParameter("city");
String country=request.getParameter("country");
CustomerLogin customerLogin=new CustomerLogin();
customerLogin.setOpenId(openid);
CustomerInfo customerInfo=new CustomerInfo();
customerInfo.setNickName(nickName);
customerInfo.setAvatarUrl(avatarUrl);
customerInfo.setCountry(country);
customerInfo.setProvince(province);
customerInfo.setCity(city);
customerInfo.setGender(gender);
CustomerLoginLog customerLoginLog=new CustomerLoginLog();
customerLoginLog.setLoginType(Byte.parseByte("1"));
customerLoginService.insertCustomerLogin(customerLogin,customerInfo,customerLoginLog);
Map<String, Object> map = new HashMap<String, Object>();
map.put("result",1);
return map;
}
@RequestMapping("getTestUser")
@ResponseBody
public Map<String, Object> getUser(HttpServletRequest request){
Object obj=SecurityUtils.getSubject().getPrincipal();
System.out.println("微信小程序正在调用。。。");
Map<String, Object> map = new HashMap<String, Object>();
List<String> list = new ArrayList<String>();
list.add("zhangsan");
list.add("lisi");
list.add("wanger");
list.add("mazi");
map.put("list",list);
System.out.println("微信小程序调用完成。。。");
return map;
}
@RequestMapping("getWord")
@ResponseBody
public Map<String, Object> getText(String word){
Map<String, Object> map = new HashMap<String, Object>();
String message = "我能力有限,不要为难我";
if ("后来".equals(word)) {
message="正在热映的后来的我们是刘若英的处女作。";
}else if("微信小程序".equals(word)){
message= "想获取更多微信小程序相关知识,请更多的阅读微信官方文档,还有其他更多微信开发相关的内容,学无止境。";
}else if("西安工业大学".equals(word)){
message="西安工业大学(Xi'an Technological University)简称”西安工大“,位于世界历史名城古都西安,是中国西北地区唯一一所以兵工为特色,以工为主,理、文、经、管、法协调发展的教学研究型大学。原中华人民共和国兵器工业部直属的七所本科院校之一(“兵工七子”),陕西省重点建设的高水平教学研究型大学、陕西省人民政府与中国兵器工业集团、国防科技工业局共建高校、教育部“卓越工程师教育培养计划”试点高校、陕西省大学生创新能力培养综合改革试点学校。国家二级保密资格单位,是一所以\"军民结合,寓军于民\"的国防科研高校。";
}
map.put("message", message);
return map;
}
@RequestMapping("")
public String getText(){
return "hello world";
}
}