Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Kloping committed May 30, 2022
1 parent b0d4501 commit 060f5ac
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class CallApiPlugin extends JavaPlugin {
public static final CallApiPlugin INSTANCE = new CallApiPlugin();

public CallApiPlugin() {
super(new JvmPluginDescriptionBuilder("io.github.Kloping.mirai.p1.CallApiPlugin", "1.2").info("调用自定义API插件").build());
super(new JvmPluginDescriptionBuilder("io.github.Kloping.mirai.p1.CallApiPlugin", "1.3").info("调用自定义API插件").build());
}

@Override
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/io/github/Kloping/mirai/p1/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@
import net.mamoe.mirai.utils.ExternalResource;
import org.jsoup.nodes.Document;

import javax.net.ssl.*;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Base64;
import java.util.List;
import java.util.Map;
Expand All @@ -27,6 +33,44 @@
* @author github.kloping
*/
public class Worker {
static {
try {
SSLContext sslcontext = SSLContext.getInstance("SSL", "SunJSSE");
sslcontext.init(null, new TrustManager[]{new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] certificates, String authType) throws CertificateException {
}

@Override
public void checkServerTrusted(X509Certificate[] ax509certificate, String s) throws CertificateException {
}

@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}}, new java.security.SecureRandom());


HostnameVerifier ignoreHostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslsession) {
System.out.println("WARNING: Hostname is not matched for cert.");
return true;
}
};

HttpsURLConnection.setDefaultHostnameVerifier(ignoreHostnameVerifier);
HttpsURLConnection.setDefaultSSLSocketFactory(sslcontext.getSocketFactory());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
}

public static Message call(String text, long gid, long qid) {
try {
Conf conf = CallApiPlugin.conf;
Expand Down

0 comments on commit 060f5ac

Please sign in to comment.