/*    */ package com.picc.grab.aop;
/*    */ 
/*    */ import com.alibaba.fastjson.JSONObject;
/*    */ import com.picc.grab.common.constants.ErrorEnum;
/*    */ import com.picc.grab.config.CarManageConfig;
/*    */ import com.picc.grab.exception.BusinessException;
/*    */ import com.picc.grab.util.StringEncrypt;
/*    */ import com.picc.grab.util.StringUtil;
/*    */ import java.util.Date;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import org.apache.commons.lang3.StringUtils;
/*    */ import org.aspectj.lang.ProceedingJoinPoint;
/*    */ import org.aspectj.lang.annotation.Around;
/*    */ import org.aspectj.lang.annotation.Aspect;
/*    */ import org.aspectj.lang.annotation.Pointcut;
/*    */ import org.slf4j.Logger;
/*    */ import org.slf4j.LoggerFactory;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ import org.springframework.context.annotation.Configuration;
/*    */ import org.springframework.web.context.request.RequestAttributes;
/*    */ import org.springframework.web.context.request.RequestContextHolder;
/*    */ import org.springframework.web.context.request.ServletRequestAttributes;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ @Aspect
/*    */ @Configuration
/*    */ public class WbInterfacerAop
/*    */ {
/* 33 */   private static final Logger logger = LoggerFactory.getLogger(WbInterfacerAop.class);
/*    */   
/*    */   @Autowired
/*    */   private CarManageConfig manageConfig;
/*    */ 
/*    */   
/*    */   @Pointcut("@annotation(com.picc.grab.aop.WbInterface)")
/*    */   public void excudeService() {}
/*    */ 
/*    */   
/*    */   @Around("excudeService()")
/*    */   public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
/* 45 */     RequestAttributes ra = RequestContextHolder.getRequestAttributes();
/* 46 */     ServletRequestAttributes sra = (ServletRequestAttributes)ra;
/* 47 */     HttpServletRequest request = sra.getRequest();
/*    */ 
/*    */     
/* 50 */     String url = request.getRequestURL().toString();
/* 51 */     String method = request.getMethod();
/* 52 */     String uri = request.getRequestURI();
/* 53 */     String queryString = request.getQueryString();
/* 54 */     logger.info("请求开始, 各个参数, url: {}, method: {}, uri: {}, params: {}", new Object[] { url, method, uri, queryString });
/* 55 */     String appname = request.getHeader("interface-appname-key");
/* 56 */     String token = request.getHeader("interface-token-key");
/* 57 */     logger.info("token 信息, appname: {}, token: {}", appname, token);
/* 58 */     if (StringUtil.isNotBlank(appname) && StringUtil.isNotBlank(token)) {
/*    */       
/* 60 */       token = tokenDecrypt(token, appname);
/* 61 */       long timestamp = (new Date()).getTime();
/* 62 */       JSONObject tokenJo = JSONObject.parseObject(token);
/* 63 */       if (timestamp - tokenJo.getLong("timestamp").longValue() >= 1800000L) {
/* 64 */         throw new BusinessException(ErrorEnum.ERROR_TOKEN_INVALID);
/*    */       }
/*    */     } else {
/* 67 */       throw new BusinessException(ErrorEnum.ERROR_TOKEN);
/*    */     } 
/*    */     
/* 70 */     Object result = pjp.proceed();
/*    */ 
/*    */     
/* 73 */     return result;
/*    */   }
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   
/*    */   private String tokenDecrypt(String token, String appanme) {
/* 83 */     if (StringUtils.equals(this.manageConfig.getAppname(), appanme)) {
/* 84 */       token = StringEncrypt.decrypt(token, this.manageConfig.getSecret());
/*    */     } else {
/* 86 */       throw new BusinessException(ErrorEnum.ERROR_TOKEN_CONFIG);
/*    */     } 
/* 88 */     return token;
/*    */   }
/*    */ }


/* Location:              C:\Users\Administrator\Desktop\ROOT\WEB-INF\classes\!\com\picc\grab\aop\WbInterfacerAop.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */