2021与蓝度共同重构项目,服务端
liuhaonan
2022-06-30 3688ab2fe5ea1f85b9a7c26be859410e76a0a1be
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
package com.sandu.ximon.admin.security.wxOpenId;
 
import cn.hutool.core.util.StrUtil;
import com.sandu.common.enums.ResponseStatusEnums;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.util.AesUtil;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author LiuHaoNan
 * @date 2022/6/30
 */
public class WxOpenIdHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver {
 
    static final String OPENID = "openId";
 
    public static final String SPLIT = ";";
 
    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        return parameter.getParameterType().isAssignableFrom(OpenId.class) ;
    }
 
    @Override
    public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer
            , NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception {
        String openId = nativeWebRequest.getHeader(OPENID);
        if (StrUtil.isBlank(openId)) {
            throw new BusinessException("openId不能为空");
        }
        openId = AesUtil.decrypt(openId);
        return openId;
    }
}