feat:同步Habu完成地区隔离功能
This commit is contained in:
@@ -219,20 +219,9 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
if (currentAccountInfo == null || TextUtils.isEmpty(currentAccountInfo.getAccess_token())) {
|
||||
return Single.error(new Throwable(""));//没有账号信息
|
||||
}
|
||||
return requestTicket().flatMap(ticketResult -> {
|
||||
if (!ticketResult.isSuccess()) {
|
||||
return Single.error(new Throwable(ticketResult.getMessage()));
|
||||
}
|
||||
ticketInfo = ticketResult.getData();
|
||||
DemoCache.saveTicketInfo(ticketInfo);
|
||||
return Single.just(ResUtil.getString(R.string.xchat_android_core_auth_authmodel_01));
|
||||
})
|
||||
return imLogin(currentAccountInfo)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.flatMap((Function<String, SingleSource<String>>) s -> {
|
||||
Log.i("IMLogin", "apply");
|
||||
return imLogin(currentAccountInfo);
|
||||
})
|
||||
.doOnSuccess(s -> {
|
||||
EventBus.getDefault().post(new LoginEvent());
|
||||
});
|
||||
@@ -781,7 +770,7 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
});
|
||||
}
|
||||
|
||||
private void cleanLogInfo() {
|
||||
public void cleanLogInfo() {
|
||||
reset();//这里先重置状态,后调用IM登出,因为这里观察了IM的在线状态
|
||||
NIMClient.getService(AuthService.class).logout();
|
||||
EventBus.getDefault().post(new LogoutEvent());
|
||||
|
@@ -78,4 +78,5 @@ public interface IInitialModel extends IModel {
|
||||
@Nullable
|
||||
FairyOpenInfo getFairyOpenInfo();
|
||||
|
||||
void regionCheck();
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.yizhuan.xchat_android_core.initial;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@@ -14,6 +15,8 @@ import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.bumptech.glide.request.FutureTarget;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.chuhai.utils.LanguageUtils;
|
||||
import com.chuhai.utils.TelephonyUtils;
|
||||
import com.netease.nim.uikit.support.glide.GlideApp;
|
||||
import com.yizhuan.xchat_android_core.R;
|
||||
import com.yizhuan.xchat_android_core.DemoCache;
|
||||
@@ -30,6 +33,8 @@ import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
|
||||
import com.yizhuan.xchat_android_core.noble.NobleDataManager;
|
||||
import com.yizhuan.xchat_android_core.public_chat_hall.manager.PublicChatHallDataManager;
|
||||
import com.yizhuan.xchat_android_core.room.face.DynamicFaceModel;
|
||||
import com.yizhuan.xchat_android_core.user.UserModel;
|
||||
import com.yizhuan.xchat_android_core.user.bean.UserInfo;
|
||||
import com.yizhuan.xchat_android_core.user.event.LoadLoginUserInfoEvent;
|
||||
import com.yizhuan.xchat_android_core.utils.CurrentTimeUtils;
|
||||
import com.yizhuan.xchat_android_core.utils.SharedPreferenceUtils;
|
||||
@@ -49,11 +54,14 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.SingleOnSubscribe;
|
||||
import io.reactivex.SingleSource;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Action;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.functions.Function;
|
||||
@@ -131,6 +139,8 @@ public class InitialModel extends BaseModel implements IInitialModel {
|
||||
@Nullable
|
||||
private InitInfo cacheInitInfo;
|
||||
|
||||
private Disposable regionCheckTimer;
|
||||
|
||||
private InitialModel() {
|
||||
api = RxNet.create(Api.class);
|
||||
loadMainTabInfoList();
|
||||
@@ -514,6 +524,38 @@ public class InitialModel extends BaseModel implements IInitialModel {
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
/**
|
||||
* 地区检测
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void regionCheck() {
|
||||
UserInfo userInfo = UserModel.get().getCacheLoginUserInfo();
|
||||
if (userInfo == null) {
|
||||
return;
|
||||
}
|
||||
if (TextUtils.isEmpty(userInfo.getNick()) || TextUtils.isEmpty(userInfo.getAvatar())) {
|
||||
return;
|
||||
}
|
||||
String operatorCode;
|
||||
if (TelephonyUtils.INSTANCE.isChinaOperator()) {
|
||||
operatorCode = "460";
|
||||
} else {
|
||||
operatorCode = TelephonyUtils.INSTANCE.getOperatorFirstSim();
|
||||
}
|
||||
api.regionCheck(LanguageUtils.INSTANCE.getSystemLanguage().toLanguageTag(), operatorCode)
|
||||
.compose(RxHelper.handleSchedulers())
|
||||
.doOnSuccess(longServiceResult -> {
|
||||
if (regionCheckTimer != null && !regionCheckTimer.isDisposed()) {
|
||||
regionCheckTimer.dispose();
|
||||
}
|
||||
if (longServiceResult.isSuccess() && longServiceResult.getData() != null && longServiceResult.getData() > 0) {
|
||||
regionCheckTimer = Observable.timer(Math.max(longServiceResult.getData(), 30 * 1000), TimeUnit.MILLISECONDS).subscribe(aLong -> {
|
||||
regionCheck();
|
||||
});
|
||||
}
|
||||
}).subscribe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTeenagerMode() {
|
||||
@@ -591,5 +633,16 @@ public class InitialModel extends BaseModel implements IInitialModel {
|
||||
@GET("act/seize-treasure/status")
|
||||
Single<ServiceResult<FairyOpenInfo>> getFairyOpenInfo();
|
||||
|
||||
/**
|
||||
* 地区检测
|
||||
*
|
||||
* @param lang 语言
|
||||
* @param mcc 运营商码
|
||||
* @return
|
||||
*/
|
||||
@POST("/ipRegion/check")
|
||||
@FormUrlEncoded
|
||||
Single<ServiceResult<Long>> regionCheck(@Field("lang") String lang, @Field("mcc") String mcc);
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.chuhai.utils.TelephonyUtils;
|
||||
import com.yizhuan.xchat_android_core.auth.AuthModel;
|
||||
import com.yizhuan.xchat_android_core.utils.APIEncryptUtil;
|
||||
import com.yizhuan.xchat_android_core.utils.OaidUtil;
|
||||
@@ -34,6 +35,12 @@ public class ParamsInterceptor implements Interceptor {
|
||||
|
||||
private Map<String, String> mHttpParams;
|
||||
|
||||
// 运营商码
|
||||
private String operatorCode;
|
||||
|
||||
// 运营商码的获取时间
|
||||
private long operatorCodeTime;
|
||||
|
||||
public ParamsInterceptor(Map<String, String> params) {
|
||||
this.mHttpParams = params;
|
||||
}
|
||||
@@ -124,7 +131,6 @@ public class ParamsInterceptor implements Interceptor {
|
||||
// Log.e("ParamsInterceptor", " url: " + oldRequest.url()+ " final params Map : " + paramsMap.toString());
|
||||
// Log.e("ParamsInterceptor", "timestamp:"+timestamp + " url: " + oldRequest.url()+ " sign : " + signStr);
|
||||
|
||||
|
||||
Headers headers = oldRequest.headers().newBuilder()
|
||||
.add("pub_ticket", ticket)
|
||||
.add("pub_uid", uid == 0 ? "" : String.valueOf(uid))
|
||||
@@ -137,6 +143,7 @@ public class ParamsInterceptor implements Interceptor {
|
||||
}
|
||||
builder.addQueryParameter("pub_timestamp", timestamp);
|
||||
builder.addQueryParameter("pub_sign", signStr);
|
||||
addHeaderWithOperator(builder);
|
||||
Request newRequest = oldRequest.newBuilder()
|
||||
.method(oldRequest.method(), oldRequest.body())
|
||||
.headers(headers)
|
||||
@@ -146,5 +153,19 @@ public class ParamsInterceptor implements Interceptor {
|
||||
|
||||
}
|
||||
|
||||
private void addHeaderWithOperator(HttpUrl.Builder builder) {
|
||||
if ((System.currentTimeMillis() - operatorCodeTime) > (1000 * 60 * 10)) {
|
||||
loadOperatorCode();
|
||||
}
|
||||
builder.addQueryParameter("mcc", operatorCode);
|
||||
}
|
||||
|
||||
private void loadOperatorCode() {
|
||||
if (TelephonyUtils.INSTANCE.isChinaOperator()) {
|
||||
operatorCode = "460";
|
||||
} else {
|
||||
operatorCode = TelephonyUtils.INSTANCE.getOperatorFirstSim();
|
||||
}
|
||||
operatorCodeTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user