PC
2024-03-30 48c8f6440a6c0b0c060467a0633bc669ca255345
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.qianwen.core.api.crypto.core;
 
import java.lang.reflect.Parameter;
import com.qianwen.core.api.crypto.annotation.decrypt.ApiDecrypt;
import com.qianwen.core.api.crypto.bean.CryptoInfoBean;
import com.qianwen.core.api.crypto.config.ApiCryptoProperties;
import com.qianwen.core.api.crypto.util.ApiCryptoUtil;
import com.qianwen.core.tool.jackson.JsonUtil;
import com.qianwen.core.tool.utils.Charsets;
import com.qianwen.core.tool.utils.StringUtil;
import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.lang.Nullable;
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;
 
/* loaded from: blade-starter-api-crypto-9.3.0.0-SNAPSHOT.jar:org/springblade/core/api/crypto/core/ApiDecryptParamResolver.class */
public class ApiDecryptParamResolver implements HandlerMethodArgumentResolver {
    private final ApiCryptoProperties properties;
 
    public ApiDecryptParamResolver(final ApiCryptoProperties properties) {
        this.properties = properties;
    }
 
    public boolean supportsParameter(MethodParameter parameter) {
        return AnnotatedElementUtils.hasAnnotation(parameter.getParameter(), ApiDecrypt.class);
    }
 
    @Nullable
    public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
        Parameter parameter = methodParameter.getParameter();
        ApiDecrypt apiDecrypt = (ApiDecrypt) AnnotatedElementUtils.getMergedAnnotation(parameter, ApiDecrypt.class);
        String text = webRequest.getParameter(this.properties.getParamName());
        if (StringUtil.isBlank(text)) {
            return null;
        }
        CryptoInfoBean infoBean = new CryptoInfoBean(apiDecrypt.value(), apiDecrypt.secretKey());
        byte[] textBytes = text.getBytes(Charsets.UTF_8);
        byte[] decryptData = ApiCryptoUtil.decryptData(this.properties, textBytes, infoBean);
        return JsonUtil.readValue(decryptData, parameter.getType());
    }
}