Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #6 from mouyase/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mouyase authored Oct 24, 2019
2 parents e0bb80b + 794edc1 commit 8e2f5d9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/build
/bugly
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "tech.yojigen.pivisionm"
minSdkVersion 19
targetSdkVersion 29
versionCode 443002
versionName '4.4.3(443002)'
versionCode 443003
versionName '4.4.3(443003)'
vectorDrawables.useSupportLibrary = true
multiDexEnabled = true
}
Expand Down
43 changes: 20 additions & 23 deletions app/src/main/java/com/reiya/pixiv/network/HttpClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.reiya.pixiv.network;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.preference.PreferenceManager;
Expand All @@ -13,6 +14,9 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import okhttp3.Cache;
import okhttp3.Call;
Expand All @@ -32,6 +36,7 @@
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import tech.yojigen.common.MD5;
import tech.yojigen.pivisionm.BuildConfig;
import tech.yojigen.pivisionm.R;

Expand All @@ -45,53 +50,45 @@ public class HttpClient {
public static void init(Context context) {
File cacheFile = new File(context.getCacheDir(), "/HttpCache/");
Cache cache = new Cache(cacheFile, 1024 * 1024 * 10); //10MB
@SuppressLint("SimpleDateFormat")
String pixivTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ", Locale.US).format(new Date());
String pixivHash = MD5.convert(pixivTime + "28c1fdd170a5204386cb1313c7077b34f83e4aaf4aa829ce78c231e05b0bae2c");
Interceptor interceptor = chain -> {
Request request = chain.request().newBuilder()
.header("User-Agent", BaseApplication.getUA())
.header("Accept-Language", "zh_CN")
.header("App-OS", "android")
.header("App-OS", "Android")
.header("App-OS-Version", "" + Build.VERSION.RELEASE)
.header("App-Version", "5.0.156")
.header("X-Client-Time", "3000-01-01T00:00:00+00:00")
.header("X-Client-Hash", "93771864335ef0c8e52db10be563eab3")
.header("X-Client-Time", pixivTime)
.header("X-Client-Hash", pixivHash)
.header("Referer", "https://www.pixiv.net")
.build();
return chain.proceed(request);
};
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE);


OkHttpClient.Builder builder = new OkHttpClient.Builder()
.cache(cache)
.addInterceptor(interceptor)
.addNetworkInterceptor(interceptor)
.addInterceptor(logging);
int connectMode = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString(context.getString(R.string.key_connect_mode), "0"));
switch (connectMode) {
case 0:
client = new OkHttpClient.Builder()
.cache(cache)
.addInterceptor(logging)
.addInterceptor(interceptor)
.addNetworkInterceptor(interceptor)
.sslSocketFactory(PixivSSLSocketFactory.getInstance(), PixivTrustManager.getInstance())
.dns(PixivDNS.getInstance())
.build();
builder.sslSocketFactory(PixivSSLSocketFactory.getInstance(), PixivTrustManager.getInstance())
.dns(PixivDNS.getInstance());
break;
case 1:
client = new OkHttpClient.Builder()
.cache(cache)
.addInterceptor(logging)
.addInterceptor(interceptor)
.addNetworkInterceptor(interceptor)
.build();
break;
case 2:
Value.URL_AUTH = Value.PROXY_URL_AUTH_YOJIGEN;
Value.URL_PIXIV = Value.PROXY_URL_PIXIV_YOJIGEN;
client = new OkHttpClient.Builder()
.cache(cache)
.addInterceptor(logging)
.addInterceptor(interceptor)
.addNetworkInterceptor(interceptor)
.build();
break;
}
client = builder.build();
service = getRetrofit(Value.URL_PIXIV).create(HttpService.class);
}

Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/tech/yojigen/common/MD5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package tech.yojigen.common;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5 {

public static String convert(String string) {
byte[] hash;
try {
hash = MessageDigest.getInstance("MD5").digest(string.getBytes(StandardCharsets.UTF_8));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
StringBuilder hex = new StringBuilder(hash.length * 2);
for (byte b : hash) {
if ((b & 0xFF) < 0x10)
hex.append("0");
hex.append(Integer.toHexString(b & 0xFF));
}
return hex.toString();
}
}

0 comments on commit 8e2f5d9

Please sign in to comment.