Skip to content

Commit

Permalink
修复refresh_token无法正确获取access_token的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CeuiLiSA committed Feb 10, 2021
1 parent fd25dce commit e062072
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "ceui.lisa.pixiv"
minSdkVersion 21
targetSdkVersion 30
versionCode 164
versionName "3.0.1"
versionCode 165
versionName "3.0.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

javaCompileOptions {
Expand All @@ -23,7 +23,7 @@ android {
//必须,告知RxHttp你依赖的okhttp版本,目前已适配 v3.12.0 - v4.9.0版本 (v4.3.0除外)
rxhttp_okhttp : '4.4.0',
//使用asXxx方法时必须,告知RxHttp你依赖的rxjava版本,可传入rxjava2、rxjava3
rxhttp_rxåjava : 'rxjava3',
rxhttp_rxjava : 'rxjava3',
rxhttp_package: 'rxhttp' //非必须,指定RxHttp类包名
]
}
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/ceui/lisa/fragments/FragmentRecmdIllust.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.scwang.smartrefresh.layout.footer.FalsifyFooter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -21,12 +22,15 @@
import ceui.lisa.helper.IllustFilter;
import ceui.lisa.helper.TagFilter;
import ceui.lisa.http.NullCtrl;
import ceui.lisa.http.Retro;
import ceui.lisa.model.ListIllust;
import ceui.lisa.models.IllustsBean;
import ceui.lisa.models.UserModel;
import ceui.lisa.repo.RecmdIllustRepo;
import ceui.lisa.utils.Common;
import ceui.lisa.utils.DensityUtil;
import ceui.lisa.utils.Dev;
import ceui.lisa.utils.Local;
import ceui.lisa.utils.Params;
import ceui.lisa.view.SpacesItemWithHeadDecoration;
import ceui.lisa.viewmodel.BaseModel;
Expand All @@ -35,6 +39,7 @@
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import retrofit2.Call;

public class FragmentRecmdIllust extends NetListFragment<FragmentBaseListBinding,
ListIllust, IllustsBean> {
Expand Down Expand Up @@ -77,6 +82,24 @@ public boolean localData() {

@Override
public BaseAdapter<IllustsBean, RecyIllustStaggerBinding> adapter() {
new Thread(new Runnable() {
@Override
public void run() {
UserModel userModel = Local.getUser();
Call<UserModel> call = Retro.getAccountApi().newRefreshToken(
FragmentLogin.CLIENT_ID,
FragmentLogin.CLIENT_SECRET,
FragmentLogin.REFRESH_TOKEN,
userModel.getResponse().getRefresh_token(),
Boolean.TRUE);
try {
UserModel newUser = call.execute().body();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();

return new IAdapterWithHeadView(allItems, mContext, dataType);
}

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/ceui/lisa/http/AccountApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,4 @@ Call<UserModel> newRefreshToken(@Field("client_id") String client_id,
@Field("refresh_token") String refresh_token,
@Field("include_policy") boolean include_policy);


}
4 changes: 2 additions & 2 deletions app/src/main/java/ceui/lisa/http/TokenInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ private synchronized String getNewToken(String tokenForThisRequest) throws IOExc
Common.showLog("getNewToken 主动获取最新的token old:" + tokenForThisRequest + " new:" + Shaft.sUserModel.getResponse().getAccess_token());
UserModel userModel = Local.getUser();
Call<UserModel> call = Retro.getAccountApi().newRefreshToken(
FragmentLogin.IOS_CLIENT_ID,
FragmentLogin.IOS_CLIENT_SECRET,
FragmentLogin.CLIENT_ID,
FragmentLogin.CLIENT_SECRET,
FragmentLogin.REFRESH_TOKEN,
userModel.getResponse().getRefresh_token(),
Boolean.TRUE);
Expand Down

0 comments on commit e062072

Please sign in to comment.