赞
踩
- package com.ahies.ija.management.configer;
-
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
-
- import com.ahies.ija.management.aoplog.RequireWechatOauth;
- import org.aspectj.lang.JoinPoint;
- import org.aspectj.lang.annotation.After;
- import org.aspectj.lang.annotation.Aspect;
- import org.aspectj.lang.annotation.Before;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.core.annotation.AnnotatedElementUtils;
- import org.springframework.stereotype.Component;
- import org.springframework.web.context.request.RequestContextHolder;
- import org.springframework.web.context.request.ServletRequestAttributes;
- import org.springframework.web.method.HandlerMethod;
- import org.springframework.web.servlet.HandlerInterceptor;
- import org.springframework.web.servlet.ModelAndView;
-
- import java.lang.reflect.Method;
-
-
- /**
- * 微信获取用户信息的拦截器
- *
- *
- * @author pc
- *
- */
- @Component
- @Aspect
- public class WeiXinInterceptor {
-
- @Before("@annotation(com.ahies.ija.management.aoplog.RequireWechatOauth)")// 拦截被TestAnnotation注解的方法;如果你需要拦截指定package指定规则名称的方法,可以使用表达式execution(...),具体百度一下资料一大堆
- public void beforeTest(JoinPoint point ) throws Throwable {
- HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
- HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
- // all http://localhost:8080/deptmeeting/meet/byhall/1
- String allurl = request.getRequestURL().toString();
- // url /deptmeeting/meet/byhall/1
- String url = request.getRequestURI();
- // System.out.println(allurl);
- // System.out.println(url);
- // false 没有手机号和微信用户的openid
- // /deptmeeting
- String contenpath = request.getContextPath();
-
- // System.out.println(contenpath);
- url = url.replace(contenpath, "");
- String appid = "wx10aa64b285851297";
- String redirect_uri = "";
- String state = url;
- redirect_uri = allurl.replace(url, "");
- String authURL = "/weixinoauth/oauth";
- redirect_uri = redirect_uri+authURL;
- // System.out.println(url);
- // 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
- // response.sendRedirect("http://blog.csdn.net/kepoon/article/details/53024841?locationNum=9&fps=1");
- String redirectURL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="
- +appid+ "&redirect_uri="+redirect_uri+"&response_type=code&scope=snsapi_userinfo&state="+state+"#wechat_redirect";
- response.sendRedirect(redirectURL);
- }
-
- @After("@annotation(com.ahies.ija.management.aoplog.RequireWechatOauth)")
- public void afterTest(JoinPoint point ) {
-
- }
- }
注解
- package com.ahies.ija.management.aoplog;
-
- import java.lang.annotation.*;
-
- /**
- * @Description TODO
- * @Date 2019/3/8 11:43
- * @Author zsj
- */
- @Documented
- @Target({ElementType.METHOD,ElementType.TYPE})
- @Retention(RetentionPolicy.RUNTIME)
- public @interface RequireWechatOauth {
- }
请求
- package com.ahies.ija.management.controller;
-
- import cn.hutool.core.map.MapUtil;
- import com.ahies.cloud.common.response.ResponseUtill;
- import com.ahies.ija.management.aoplog.ControllerLog;
- import com.ahies.ija.management.aoplog.OperateModule;
- import com.ahies.ija.management.aoplog.RequireWechatOauth;
- import com.ahies.ija.management.model.AppointmentBind;
- import com.ahies.ija.management.model.AppointmentManagement;
- import com.ahies.ija.management.model.SubscribeManagement;
- import com.ahies.ija.management.service.AppointmentManagementService;
- import com.ahies.ija.management.service.SubscribeManagementService;
- import com.ahies.ija.management.service.UserService;
- import com.ahies.ija.management.service.WxService;
- import com.ahies.ija.management.util.DateUtil;
- import com.ahies.system.common.response.ResponseMap;
- import com.github.pagehelper.PageInfo;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.HttpStatus;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
-
- import java.time.LocalDateTime;
- import java.util.HashMap;
- import java.util.Map;
-
-
- @RestController
- @RequestMapping("/wxSelfhelp")
- public class WxController {
-
-
-
- /**
- *
- *
- */
- @RequireWechatOauth
- @RequestMapping("/getWechatInfo")
- public Map<String, Object> getWechatInfo() {
- return new HashMap<>();
-
- }
-
-
- @RequestMapping("/getWechat")
- public Map<String, Object> getWechat() {
- return new HashMap<>();
-
- }
-
-
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。