Skip to content

Commit

Permalink
feat: 自动签到
Browse files Browse the repository at this point in the history
feat: 自动签到
  • Loading branch information
mlzzen committed Jul 10, 2023
1 parent 6f62784 commit 6d3fe3b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class PreferenceKey {

public static final String BOOKMARK_BOARD = "bookmark_board";

public static final String CHECK_IN_LAST_TIME = "check_in_last_time";

public static final String USER_ACTIVE_INDEX = "user_active_index";

public static final String SORT_BY_POST = "sort_by_post";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@
import gov.anzong.androidnga.base.util.ContextUtils;
import gov.anzong.androidnga.base.util.PreferenceUtils;
import gov.anzong.androidnga.base.util.ThreadUtils;
import gov.anzong.androidnga.base.util.ToastUtils;
import gov.anzong.androidnga.common.PreferenceKey;
import gov.anzong.androidnga.common.util.ReflectUtils;
import gov.anzong.androidnga.db.AppDatabase;
import sp.phone.common.FilterKeywordsManagerImpl;
import sp.phone.common.UserManagerImpl;
import sp.phone.common.VersionUpgradeHelper;
import sp.phone.task.CheckInTask;

public class NgaClientApp extends Application {

private static final String TAG = NgaClientApp.class.getSimpleName();

private static boolean sNewVersion;

private CheckInTask mCheckInTask;

@Override
public void onCreate() {
initLogger();
Expand All @@ -39,6 +43,7 @@ public void onCreate() {
AppDatabase.init(this);
initCoreModule();
initRouter();
checkIn();
super.onCreate();

// fixWebViewMultiProcessException();
Expand All @@ -62,7 +67,7 @@ private void fixWebViewMultiProcessException() {
if (dirs != null) {
for (File dir : dirs) {
if (dir.getName().contains("webview")) {
if (!dir.getName().contains("webview_" + ppid)){
if (!dir.getName().contains("webview_" + ppid)) {
ThreadUtils.postOnSubThread(() -> {
try {
FileUtils.deleteDirectory(dir);
Expand Down Expand Up @@ -109,6 +114,13 @@ private void checkNewVersion() {
}
}

private void checkIn() {
if (mCheckInTask == null) {
mCheckInTask = new CheckInTask();
}
mCheckInTask.execute();
}

public static boolean isNewVersion() {
return sNewVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public OkHttpClient.Builder createOkHttpClientBuilder() {
Request request = original.newBuilder()
.header("Cookie", cookie)
.header("User-Agent", mUserAgent)
.header("X-User-Agent", "Nga_Official")
.method(original.method(), original.body())
.build();
return chain.proceed(request);
Expand Down
50 changes: 50 additions & 0 deletions nga_phone_base_3.0/src/main/java/sp/phone/task/CheckInTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package sp.phone.task;

import static sp.phone.util.ActivityUtils.showToast;

import java.util.Calendar;
import java.util.Date;

import gov.anzong.androidnga.Utils;
import gov.anzong.androidnga.base.util.PreferenceUtils;
import gov.anzong.androidnga.common.PreferenceKey;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import sp.phone.http.retrofit.RetrofitHelper;
import sp.phone.http.retrofit.RetrofitService;
import sp.phone.rxjava.BaseSubscriber;
import sp.phone.util.StringUtils;

/**
* 签到
* Created by mlzzen on 2023/7/7.
*/
public class CheckInTask {
private static final String url = Utils.getNGAHost() + "nuke.php?__lib=check_in&__act=check_in&lite=js";

public static void execute() {
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
long checkInLastTime = PreferenceUtils.getData(PreferenceKey.CHECK_IN_LAST_TIME, new Date().getTime() - 24 * 3600 * 1000);
cal1.setTime(new Date(checkInLastTime));
cal2.setTime(new Date());
if (cal1.get(Calendar.DAY_OF_YEAR) != cal2.get(Calendar.DAY_OF_YEAR)) {
RetrofitService service = RetrofitHelper.getInstance().getService();
service.post(url)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new BaseSubscriber<String>() {
@Override
public void onNext(String result) {
String msg = StringUtils.getStringBetween(result, 0, "{\"0\":\"", "\"},\"time\"").result;
if (msg.indexOf("签到成功") != -1) {
showToast("签到成功");
}
if (msg.indexOf("签到成功") != -1 || msg.indexOf("今天已经签到") != -1) {
PreferenceUtils.putData(PreferenceKey.CHECK_IN_LAST_TIME, new Date().getTime());
}
}
});
}
}
}

0 comments on commit 6d3fe3b

Please sign in to comment.