|
@@ -1,14 +1,22 @@
|
|
|
package com.chuanghai.ihotel.controller;
|
|
package com.chuanghai.ihotel.controller;
|
|
|
|
|
|
|
|
|
|
+import com.chuanghai.ihotel.anno.UserLoginCheck;
|
|
|
|
|
+import com.chuanghai.ihotel.aop.LoginCheckAspect;
|
|
|
|
|
+import com.chuanghai.ihotel.common.utils.CommonResult;
|
|
|
|
|
+import com.chuanghai.ihotel.dto.LoginUserDTO;
|
|
|
|
|
+import com.chuanghai.ihotel.entity.HotelUserEntity;
|
|
|
import com.chuanghai.ihotel.service.HotelUserService;
|
|
import com.chuanghai.ihotel.service.HotelUserService;
|
|
|
import com.chuanghai.ihotel.vo.LoginUserVO;
|
|
import com.chuanghai.ihotel.vo.LoginUserVO;
|
|
|
-import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestHeader;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 普通用户
|
|
* 普通用户
|
|
@@ -17,7 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
* @email codingliang@gmail.com
|
|
* @email codingliang@gmail.com
|
|
|
* @date 2022-07-27 10:02:04
|
|
* @date 2022-07-27 10:02:04
|
|
|
*/
|
|
*/
|
|
|
-@RestController
|
|
|
|
|
|
|
+@Controller
|
|
|
@RequestMapping("hotelUser")
|
|
@RequestMapping("hotelUser")
|
|
|
public class HotelUserController {
|
|
public class HotelUserController {
|
|
|
|
|
|
|
@@ -30,7 +38,7 @@ public class HotelUserController {
|
|
|
* 微校授权回调地址
|
|
* 微校授权回调地址
|
|
|
*
|
|
*
|
|
|
* @apiNote 用户跳转到微校授权链接上,微校服务器接收用户授权后会携带wxcode回调到该接口上,该接口使用wxcode获取到用户的信息。
|
|
* @apiNote 用户跳转到微校授权链接上,微校服务器接收用户授权后会携带wxcode回调到该接口上,该接口使用wxcode获取到用户的信息。
|
|
|
- * 如果用户信息获取成功,该接口会以 【fontEndUrl + /?loginUserVO={}】 的形式跳回到前端应用页面;
|
|
|
|
|
|
|
+ * 如果用户信息获取成功,该接口会以 【fontEndUrl + /?token=】 的形式跳回到前端应用页面;
|
|
|
* 如果用户信息获取失败,该接口会以 【fontEndUrl + /error/?errorMsg=获取用户信息失败】 的形式跳回到前端应用页面。
|
|
* 如果用户信息获取失败,该接口会以 【fontEndUrl + /error/?errorMsg=获取用户信息失败】 的形式跳回到前端应用页面。
|
|
|
* <strong>注意:</strong>
|
|
* <strong>注意:</strong>
|
|
|
* fontEndUrl + 路由地址:前端项目地址+页面路由地址,用于前端页面接收用户的信息或错误信息,该地址需要前端人员与后台开发人员协调好。
|
|
* fontEndUrl + 路由地址:前端项目地址+页面路由地址,用于前端页面接收用户的信息或错误信息,该地址需要前端人员与后台开发人员协调好。
|
|
@@ -40,14 +48,29 @@ public class HotelUserController {
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("weixiaoAuth")
|
|
@GetMapping("weixiaoAuth")
|
|
|
- public String weixiaoAuth(String wxcode, String state) throws JsonProcessingException {
|
|
|
|
|
|
|
+ public String weixiaoAuth(String wxcode, String state) throws UnsupportedEncodingException {
|
|
|
|
|
+ System.out.println("code==>" + wxcode);
|
|
|
LoginUserVO loginUserVO = hotelUserService.weixiaoAuth(wxcode, state);
|
|
LoginUserVO loginUserVO = hotelUserService.weixiaoAuth(wxcode, state);
|
|
|
|
|
|
|
|
if (loginUserVO != null) {
|
|
if (loginUserVO != null) {
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
- return "redirect:" + fontEndUrl + "/#/pages/blankIndex/blankIndex/?loginUserVO=" + objectMapper.writeValueAsString(loginUserVO);
|
|
|
|
|
|
|
+ return "redirect:" + fontEndUrl + "/#/pages/blankIndex/blankIndex/?token=" + loginUserVO.getToken() + "&tokenTtl=" + loginUserVO.getTokenTtl();
|
|
|
} else {
|
|
} else {
|
|
|
- return "redirect:" + fontEndUrl + "/#/error/?errorMsg=获取用户信息失败";
|
|
|
|
|
|
|
+ return "redirect:" + fontEndUrl + "/#/error/?errorMsg=" + URLEncoder.encode("获取用户信息失败", "utf-8");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取用户信息
|
|
|
|
|
+ * @param userToken 用户token
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @UserLoginCheck
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ @GetMapping("userInfo")
|
|
|
|
|
+ public CommonResult<HotelUserEntity> getUserInfoByToken(@RequestHeader("user_token") String userToken) {
|
|
|
|
|
+ LoginUserDTO dto = LoginCheckAspect.threadLocal.get();
|
|
|
|
|
+ HotelUserEntity vo = hotelUserService.findByCardNumber(dto.getCardNumber());
|
|
|
|
|
+
|
|
|
|
|
+ return CommonResult.ok().setResult(vo);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|