StaffWechatAuthController.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright 2017-2020 吴学文 and java110 team.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.java110.front.controller.wechat;
  17. import com.alibaba.fastjson.JSONObject;
  18. import com.java110.core.base.controller.BaseController;
  19. import com.java110.core.context.IPageData;
  20. import com.java110.core.context.PageData;
  21. import com.java110.front.smo.staff.IStaffAuthSMO;
  22. import com.java110.utils.constant.CommonConstant;
  23. import org.slf4j.Logger;
  24. import org.slf4j.LoggerFactory;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.http.ResponseEntity;
  27. import org.springframework.web.bind.annotation.RequestMapping;
  28. import org.springframework.web.bind.annotation.RequestParam;
  29. import org.springframework.web.bind.annotation.RestController;
  30. import javax.servlet.http.HttpServletRequest;
  31. import javax.servlet.http.HttpServletResponse;
  32. import java.util.Map;
  33. /**
  34. * 微信小程序登录处理类
  35. */
  36. @RestController
  37. @RequestMapping(path = "/app")
  38. public class StaffWechatAuthController extends BaseController {
  39. private final static Logger logger = LoggerFactory.getLogger(StaffWechatAuthController.class);
  40. @Autowired
  41. private IStaffAuthSMO staffAuthSMOImpl;
  42. /**
  43. * 微信登录接口
  44. *
  45. * @param request
  46. */
  47. @RequestMapping(path = "/loginStaffWechatAuth")
  48. public ResponseEntity<String> loginStaffWechatAuth(HttpServletRequest request) {
  49. Map<String, String> params = getParameterStringMap(request);
  50. String appId = params.get("appId");
  51. IPageData pd = PageData.newInstance().builder("", "", "", JSONObject.toJSONString(params),
  52. "login", "", "", "", appId
  53. );
  54. ResponseEntity responseEntity = staffAuthSMOImpl.getPageAccessToken(pd, request);
  55. request.setAttribute(CommonConstant.CONTEXT_PAGE_DATA, pd);
  56. return responseEntity;
  57. }
  58. /**
  59. * 微信公众号号鉴权
  60. *
  61. * @param request
  62. */
  63. @RequestMapping(path = "/staffAuth")
  64. public ResponseEntity<String> staffAuth(@RequestParam String redirectUrl,
  65. @RequestParam String errorUrl,
  66. @RequestParam String loginFlag,
  67. HttpServletRequest request,
  68. HttpServletResponse response) {
  69. IPageData pd = PageData.newInstance().builder("", "", "", "",
  70. "login", "", "", "", request.getHeader("app-id")
  71. );
  72. return staffAuthSMOImpl.refreshToken(pd, redirectUrl, errorUrl, loginFlag, request, response);
  73. }
  74. }