当前位置:   article > 正文

wechat_wx10cbdeeec1667491://wapoauth?m=kzg2mtmyotk5mdg3mz

wx10cbdeeec1667491://wapoauth?m=kzg2mtmyotk5mdg3mzm%3d&t=804223

拦截器

  1. package com.ahies.ija.management.configer;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import com.ahies.ija.management.aoplog.RequireWechatOauth;
  5. import org.aspectj.lang.JoinPoint;
  6. import org.aspectj.lang.annotation.After;
  7. import org.aspectj.lang.annotation.Aspect;
  8. import org.aspectj.lang.annotation.Before;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.core.annotation.AnnotatedElementUtils;
  11. import org.springframework.stereotype.Component;
  12. import org.springframework.web.context.request.RequestContextHolder;
  13. import org.springframework.web.context.request.ServletRequestAttributes;
  14. import org.springframework.web.method.HandlerMethod;
  15. import org.springframework.web.servlet.HandlerInterceptor;
  16. import org.springframework.web.servlet.ModelAndView;
  17. import java.lang.reflect.Method;
  18. /**
  19. * 微信获取用户信息的拦截器
  20. *
  21. *
  22. * @author pc
  23. *
  24. */
  25. @Component
  26. @Aspect
  27. public class WeiXinInterceptor {
  28. @Before("@annotation(com.ahies.ija.management.aoplog.RequireWechatOauth)")// 拦截被TestAnnotation注解的方法;如果你需要拦截指定package指定规则名称的方法,可以使用表达式execution(...),具体百度一下资料一大堆
  29. public void beforeTest(JoinPoint point ) throws Throwable {
  30. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
  31. HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
  32. // all http://localhost:8080/deptmeeting/meet/byhall/1
  33. String allurl = request.getRequestURL().toString();
  34. // url /deptmeeting/meet/byhall/1
  35. String url = request.getRequestURI();
  36. // System.out.println(allurl);
  37. // System.out.println(url);
  38. // false 没有手机号和微信用户的openid
  39. // /deptmeeting
  40. String contenpath = request.getContextPath();
  41. // System.out.println(contenpath);
  42. url = url.replace(contenpath, "");
  43. String appid = "wx10aa64b285851297";
  44. String redirect_uri = "";
  45. String state = url;
  46. redirect_uri = allurl.replace(url, "");
  47. String authURL = "/weixinoauth/oauth";
  48. redirect_uri = redirect_uri+authURL;
  49. // System.out.println(url);
  50. // https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${meePlatPath}/wechatOAuth_oauth.shtml&response_type=code&scope=snsapi_userinfo&state=login#wechat_redirect
  51. // response.sendRedirect("http://blog.csdn.net/kepoon/article/details/53024841?locationNum=9&fps=1");
  52. String redirectURL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="
  53. +appid+ "&redirect_uri="+redirect_uri+"&response_type=code&scope=snsapi_userinfo&state="+state+"#wechat_redirect";
  54. response.sendRedirect(redirectURL);
  55. }
  56. @After("@annotation(com.ahies.ija.management.aoplog.RequireWechatOauth)")
  57. public void afterTest(JoinPoint point ) {
  58. }
  59. }

注解

  1. package com.ahies.ija.management.aoplog;
  2. import java.lang.annotation.*;
  3. /**
  4. * @Description TODO
  5. * @Date 2019/3/8 11:43
  6. * @Author zsj
  7. */
  8. @Documented
  9. @Target({ElementType.METHOD,ElementType.TYPE})
  10. @Retention(RetentionPolicy.RUNTIME)
  11. public @interface RequireWechatOauth {
  12. }

请求

  1. package com.ahies.ija.management.controller;
  2. import cn.hutool.core.map.MapUtil;
  3. import com.ahies.cloud.common.response.ResponseUtill;
  4. import com.ahies.ija.management.aoplog.ControllerLog;
  5. import com.ahies.ija.management.aoplog.OperateModule;
  6. import com.ahies.ija.management.aoplog.RequireWechatOauth;
  7. import com.ahies.ija.management.model.AppointmentBind;
  8. import com.ahies.ija.management.model.AppointmentManagement;
  9. import com.ahies.ija.management.model.SubscribeManagement;
  10. import com.ahies.ija.management.service.AppointmentManagementService;
  11. import com.ahies.ija.management.service.SubscribeManagementService;
  12. import com.ahies.ija.management.service.UserService;
  13. import com.ahies.ija.management.service.WxService;
  14. import com.ahies.ija.management.util.DateUtil;
  15. import com.ahies.system.common.response.ResponseMap;
  16. import com.github.pagehelper.PageInfo;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.http.HttpStatus;
  19. import org.springframework.web.bind.annotation.RequestBody;
  20. import org.springframework.web.bind.annotation.RequestMapping;
  21. import org.springframework.web.bind.annotation.RequestParam;
  22. import org.springframework.web.bind.annotation.RestController;
  23. import java.time.LocalDateTime;
  24. import java.util.HashMap;
  25. import java.util.Map;
  26. @RestController
  27. @RequestMapping("/wxSelfhelp")
  28. public class WxController {
  29. /**
  30. *
  31. *
  32. */
  33. @RequireWechatOauth
  34. @RequestMapping("/getWechatInfo")
  35. public Map<String, Object> getWechatInfo() {
  36. return new HashMap<>();
  37. }
  38. @RequestMapping("/getWechat")
  39. public Map<String, Object> getWechat() {
  40. return new HashMap<>();
  41. }
  42. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/345064
推荐阅读
相关标签
  

闽ICP备14008679号