fix: 修复枝网查重无法使用
This commit is contained in:
parent
867d47fa59
commit
587f770531
|
|
@ -18,6 +18,11 @@ object CheckApi {
|
||||||
.addConverterFactory(GsonConverterFactory.create())
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
.client(OkHttpClient.Builder().apply {
|
.client(OkHttpClient.Builder().apply {
|
||||||
connectionPool(connectionPool)
|
connectionPool(connectionPool)
|
||||||
|
sslSocketFactory(
|
||||||
|
SSLSocketClient.getSSLSocketFactory(),
|
||||||
|
SSLSocketClient.getX509TrustManager()
|
||||||
|
)
|
||||||
|
hostnameVerifier(SSLSocketClient.getHostnameVerifier())
|
||||||
}.build())
|
}.build())
|
||||||
.build()
|
.build()
|
||||||
.create(ICheckApi::class.java)
|
.create(ICheckApi::class.java)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
package com.huanchengfly.tieba.post.plugins.asoulcnki.api;
|
||||||
|
|
||||||
|
import java.security.KeyStore;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import javax.net.ssl.HostnameVerifier;
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
|
import javax.net.ssl.TrustManager;
|
||||||
|
import javax.net.ssl.TrustManagerFactory;
|
||||||
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
|
||||||
|
|
||||||
|
public class SSLSocketClient {
|
||||||
|
|
||||||
|
//获取这个SSLSocketFactory
|
||||||
|
public static SSLSocketFactory getSSLSocketFactory() {
|
||||||
|
try {
|
||||||
|
SSLContext sslContext = SSLContext.getInstance("SSL");
|
||||||
|
sslContext.init(null, getTrustManager(), new SecureRandom());
|
||||||
|
return sslContext.getSocketFactory();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取TrustManager
|
||||||
|
private static TrustManager[] getTrustManager() {
|
||||||
|
return new TrustManager[]{
|
||||||
|
new X509TrustManager() {
|
||||||
|
@Override
|
||||||
|
public void checkClientTrusted(X509Certificate[] chain, String authType) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkServerTrusted(X509Certificate[] chain, String authType) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
|
return new X509Certificate[]{};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取HostnameVerifier
|
||||||
|
public static HostnameVerifier getHostnameVerifier() {
|
||||||
|
return (s, sslSession) -> true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static X509TrustManager getX509TrustManager() {
|
||||||
|
X509TrustManager trustManager = null;
|
||||||
|
try {
|
||||||
|
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||||
|
trustManagerFactory.init((KeyStore) null);
|
||||||
|
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
|
||||||
|
if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
|
||||||
|
throw new IllegalStateException("Unexpected default trust managers:" + Arrays.toString(trustManagers));
|
||||||
|
}
|
||||||
|
trustManager = (X509TrustManager) trustManagers[0];
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return trustManager;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -86,7 +86,13 @@ object EmotionManager {
|
||||||
contextRef = WeakReference(context)
|
contextRef = WeakReference(context)
|
||||||
val emotionCache = getEmotionDataCache()
|
val emotionCache = getEmotionDataCache()
|
||||||
if (emotionCache.ids.isEmpty()) {
|
if (emotionCache.ids.isEmpty()) {
|
||||||
for (i in 1..137) {
|
for (i in 1..50) {
|
||||||
|
emotionIds.add("image_emoticon$i")
|
||||||
|
}
|
||||||
|
for (i in 61..101) {
|
||||||
|
emotionIds.add("image_emoticon$i")
|
||||||
|
}
|
||||||
|
for (i in 125..137) {
|
||||||
emotionIds.add("image_emoticon$i")
|
emotionIds.add("image_emoticon$i")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -129,18 +135,18 @@ object EmotionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEmotionCacheDir(): File {
|
fun getEmotionCacheDir(): File {
|
||||||
return File(getContext().externalCacheDir ?: getContext().cacheDir, "emotion")
|
return File(getContext().externalCacheDir ?: getContext().cacheDir, "emotion").apply {
|
||||||
|
if (exists() && isFile) {
|
||||||
|
delete()
|
||||||
|
mkdirs()
|
||||||
|
} else if (!exists()) {
|
||||||
|
mkdirs()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEmotionFile(id: String): File {
|
fun getEmotionFile(id: String): File {
|
||||||
val emotionsCacheDir = getEmotionCacheDir()
|
return File(getEmotionCacheDir(), "$id.png")
|
||||||
if (emotionsCacheDir.exists() && emotionsCacheDir.isFile) {
|
|
||||||
emotionsCacheDir.delete()
|
|
||||||
emotionsCacheDir.mkdirs()
|
|
||||||
} else if (!emotionsCacheDir.exists()) {
|
|
||||||
emotionsCacheDir.mkdirs()
|
|
||||||
}
|
|
||||||
return File(emotionsCacheDir, "$id.png")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEmotionIdByName(name: String): String? {
|
fun getEmotionIdByName(name: String): String? {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue