admin
2021-02-06 cad915058c3c53bf328a8ae9ca9bc7de099caba7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.yeshi.buwan.aspect;
 
import com.yeshi.buwan.vo.AcceptData;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
 
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
 
@Component
@Aspect
public class SignAspect {
 
 
    //签名验证
    @Around("execution(public * com.yeshi.buwan.controller.api.*.*(..))")
    public Object verifySign(ProceedingJoinPoint joinPoint) throws IOException {
        ServletRequestAttributes servletContainer = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = servletContainer.getRequest();
        Object[] args = joinPoint.getArgs();
        for (Object obj : args) {
            if (obj instanceof AcceptData) {
                AcceptData acceptData = (AcceptData) obj;
                if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
                    acceptData.setChannel("appstore");
                }
            }
        }
 
        Object obj = null;
        try {
            obj = joinPoint.proceed(args);
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return obj;
    }
 
 
}