九州仙境 v3.0.0版本的 MD5 值为:7b5ce5daab0f4a38a386ae4309157477

以下内容为反编译后的 CertificateService.java 源代码,内容仅作参考


package com.wechat.pay.java.service.certificate;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.cipher.AeadAesCipher;
import com.wechat.pay.java.core.cipher.AeadCipher;
import com.wechat.pay.java.core.http.Constant;
import com.wechat.pay.java.core.http.DefaultHttpClientBuilder;
import com.wechat.pay.java.core.http.HostName;
import com.wechat.pay.java.core.http.HttpClient;
import com.wechat.pay.java.core.http.HttpMethod;
import com.wechat.pay.java.core.http.HttpRequest;
import com.wechat.pay.java.core.http.MediaType;
import com.wechat.pay.java.core.util.PemUtil;
import com.wechat.pay.java.service.certificate.model.Data;
import com.wechat.pay.java.service.certificate.model.DownloadCertificateResponse;
import com.wechat.pay.java.service.certificate.model.EncryptCertificate;
import java.nio.charset.StandardCharsets;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
public class CertificateService {
    private static final String RSA_URL = "https://api.mch.weixin.qq.com/v3/certificates";
    private final HostName hostName;
    private final HttpClient httpClient;

    private CertificateService(HttpClient httpClient, HostName hostName) {
        this.httpClient = (HttpClient) Objects.requireNonNull(httpClient);
        this.hostName = hostName;
    }

    public static class Builder {
        private HostName hostName;
        private HttpClient httpClient;

        public Builder config(Config config) {
            this.httpClient = new DefaultHttpClientBuilder().config(config).build();
            return this;
        }

        public Builder httpClient(HttpClient httpClient) {
            this.httpClient = (HttpClient) Objects.requireNonNull(httpClient);
            return this;
        }

        public Builder hostName(HostName hostName) {
            this.hostName = hostName;
            return this;
        }

        public CertificateService build() {
            return new CertificateService(this.httpClient, this.hostName);
        }
    }

    public List<X509Certificate> downloadCertificate(byte[] bArr) {
        return downloadCertificate(new AeadAesCipher(bArr));
    }

    public List<X509Certificate> downloadCertificate(String str, AeadCipher aeadCipher, Function<String, X509Certificate> function) {
        if (this.hostName != null) {
            str = str.replaceFirst(HostName.API.getValue(), this.hostName.getValue());
        }
        List<Data> data = ((DownloadCertificateResponse) this.httpClient.execute(new HttpRequest.Builder().httpMethod(HttpMethod.GET).url(str).addHeader(Constant.ACCEPT, " */*").addHeader(Constant.CONTENT_TYPE, MediaType.APPLICATION_JSON.getValue()).build(), DownloadCertificateResponse.class).getServiceResponse()).getData();
        ArrayList arrayList = new ArrayList();
        for (Data data2 : data) {
            EncryptCertificate encryptCertificate = data2.getEncryptCertificate();
            arrayList.add(function.apply(aeadCipher.decrypt(encryptCertificate.getAssociatedData().getBytes(StandardCharsets.UTF_8), encryptCertificate.getNonce().getBytes(StandardCharsets.UTF_8), Base64.getDecoder().decode(encryptCertificate.getCiphertext()))));
        }
        return arrayList;
    }

    public List<X509Certificate> downloadCertificate(AeadCipher aeadCipher) {
        return downloadCertificate(RSA_URL, aeadCipher, new Function() {
            @Override
            public final Object apply(Object obj) {
                return PemUtil.loadX509FromString((String) obj);
            }
        });
    }
}