admin
2022-03-29 fac5d01bfcddfc8edef0a5fd3d401b1fe383fe16
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package org.yeshi.utils.alipay;
 
 
import com.alipay.api.*;
 
import java.security.cert.X509Certificate;
import java.util.concurrent.ConcurrentHashMap;
 
public class CertAlipayClient extends MyAbstractAlipayClient {
    private String privateKey;
    private String encryptKey;
    private String alipayPublicKey;
    private Signer signer;
    private SignChecker signChecker;
    private Encryptor encryptor;
    private Decryptor decryptor;
    private X509Certificate cert;
    private ConcurrentHashMap<String, X509Certificate> alipayPublicCertMap;
 
 
    public CertAlipayClient(MyCertAlipayRequest certAlipayRequest) throws AlipayApiException {
        super(certAlipayRequest.getServerUrl(), certAlipayRequest.getAppId(), certAlipayRequest.getFormat(),
                certAlipayRequest.getCharset(), certAlipayRequest.getSignType(), certAlipayRequest.getCertStream(),
                certAlipayRequest.getAlipayPublicCertStream(), certAlipayRequest.getRootCertStream(),
                certAlipayRequest.getProxyHost(), certAlipayRequest.getProxyPort(), certAlipayRequest.getEncryptType());
        this.privateKey = certAlipayRequest.getPrivateKey();
        this.signer = new DefaultSigner(certAlipayRequest.getPrivateKey());
        this.encryptor = new DefaultEncryptor(certAlipayRequest.getEncryptor());
        this.decryptor = new DefaultDecryptor(certAlipayRequest.getEncryptor());
    }
 
    public Signer getSigner() {
        return signer;
    }
 
    public SignChecker getSignChecker() {
        return signChecker;
    }
 
    public Encryptor getEncryptor() {
        return encryptor;
    }
 
    public Decryptor getDecryptor() {
        return decryptor;
    }
 
    public X509Certificate getCert() {
        return cert;
    }
 
    public ConcurrentHashMap<String, X509Certificate> getAlipayPublicCertMap() {
        return alipayPublicCertMap;
    }
 
    public void setPrivateKey(String privateKey) {
        this.privateKey = privateKey;
        if (this.signer == null) {
            this.signer = new DefaultSigner(privateKey);
        }
    }
 
    public void setEncryptKey(String encryptKey) {
        this.encryptKey = encryptKey;
        if (this.encryptor == null) {
            this.encryptor = new DefaultEncryptor(encryptKey);
        }
        if (this.decryptor == null) {
            this.decryptor = new DefaultDecryptor(encryptKey);
        }
    }
 
    public void setAlipayPublicKey(String alipayPublicKey) {
        this.alipayPublicKey = alipayPublicKey;
        if (this.signChecker == null) {
            this.signChecker = new DefaultSignChecker(alipayPublicKey);
        }
    }
}