登录错误提示优化

This commit is contained in:
huangjian
2022-08-30 17:52:08 +08:00
parent 7e048d1421
commit 14dd247e56
5 changed files with 380 additions and 455 deletions

View File

@@ -20,13 +20,11 @@ import androidx.core.content.ContextCompat;
import com.coorchice.library.utils.LogUtils; import com.coorchice.library.utils.LogUtils;
import com.trello.rxlifecycle3.android.ActivityEvent; import com.trello.rxlifecycle3.android.ActivityEvent;
import com.yizhuan.erban.R; import com.yizhuan.erban.R;
import com.yizhuan.erban.UIHelper;
import com.yizhuan.erban.base.BaseLoginAct; import com.yizhuan.erban.base.BaseLoginAct;
import com.yizhuan.erban.ui.login.ui.CodeEditText; import com.yizhuan.erban.ui.login.ui.CodeEditText;
import com.yizhuan.xchat_android_core.auth.AuthModel; import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.auth.exception.BanAccountException; import com.yizhuan.xchat_android_core.auth.exception.BanAccountException;
import com.yizhuan.xchat_android_core.auth.exception.IsSuperAdminException; import com.yizhuan.xchat_android_core.auth.exception.IsSuperAdminException;
import com.yizhuan.xchat_android_core.auth.exception.ShowPhoneCodeException;
import com.yizhuan.xchat_android_core.code.CodeType; import com.yizhuan.xchat_android_core.code.CodeType;
import com.yizhuan.xchat_android_core.statistic.StatisticManager; import com.yizhuan.xchat_android_core.statistic.StatisticManager;
import com.yizhuan.xchat_android_core.statistic.protocol.StatisticsProtocol; import com.yizhuan.xchat_android_core.statistic.protocol.StatisticsProtocol;
@@ -45,7 +43,6 @@ import java.util.Locale;
import io.reactivex.SingleObserver; import io.reactivex.SingleObserver;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Action;
/** /**
* @author zhouxiangfeng * @author zhouxiangfeng
@@ -204,10 +201,6 @@ public class BindCodeActivity extends BaseLoginAct {
start, text.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); start, text.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
getDialogManager().showOkCancelWithTitleDialog("您被封号了", getDialogManager().showOkCancelWithTitleDialog("您被封号了",
spannableString, "确定", "取消", null); spannableString, "确定", "取消", null);
} else if (e instanceof ShowPhoneCodeException) {
isSuperAdmin = false;
ShowPhoneCodeException showPhoneCodeException = (ShowPhoneCodeException) e;
toast(e.getMessage());
} else if (e instanceof IOException) { } else if (e instanceof IOException) {
toast("网络异常,请检查您的网络再试~"); toast("网络异常,请检查您的网络再试~");
} else { } else {

View File

@@ -22,14 +22,12 @@ import com.netease.nim.uikit.StatusBarUtil;
import com.trello.rxlifecycle3.android.ActivityEvent; import com.trello.rxlifecycle3.android.ActivityEvent;
import com.yizhuan.erban.R; import com.yizhuan.erban.R;
import com.yizhuan.erban.base.BaseLoginAct; import com.yizhuan.erban.base.BaseLoginAct;
import com.yizhuan.erban.common.widget.dialog.DialogManager;
import com.yizhuan.erban.ui.login.ui.CodeEditText; import com.yizhuan.erban.ui.login.ui.CodeEditText;
import com.yizhuan.xchat_android_core.auth.AuthModel; import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.auth.event.LoginEvent; import com.yizhuan.xchat_android_core.auth.event.LoginEvent;
import com.yizhuan.xchat_android_core.auth.exception.AccountCancelException; import com.yizhuan.xchat_android_core.auth.exception.AccountCancelException;
import com.yizhuan.xchat_android_core.auth.exception.BanAccountException; import com.yizhuan.xchat_android_core.auth.exception.BanAccountException;
import com.yizhuan.xchat_android_core.auth.exception.IsSuperAdminException; import com.yizhuan.xchat_android_core.auth.exception.IsSuperAdminException;
import com.yizhuan.xchat_android_core.auth.exception.ShowPhoneCodeException;
import com.yizhuan.xchat_android_core.code.CodeType; import com.yizhuan.xchat_android_core.code.CodeType;
import com.yizhuan.xchat_android_core.statistic.StatisticManager; import com.yizhuan.xchat_android_core.statistic.StatisticManager;
import com.yizhuan.xchat_android_core.statistic.protocol.StatisticsProtocol; import com.yizhuan.xchat_android_core.statistic.protocol.StatisticsProtocol;
@@ -254,10 +252,6 @@ public class LoginCodeActivity extends BaseLoginAct {
0, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); 0, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
getDialogManager().showOkWithTitleDialog("该账号已注销", getDialogManager().showOkWithTitleDialog("该账号已注销",
spannableString, "我知道了", true, null); spannableString, "我知道了", true, null);
} else if (e instanceof ShowPhoneCodeException) {
isSuperAdmin = false;
ShowPhoneCodeException showPhoneCodeException = (ShowPhoneCodeException) e;
toast(e.getMessage());
} else if (e instanceof IOException) { } else if (e instanceof IOException) {
toast("网络异常,请检查您的网络再试~"); toast("网络异常,请检查您的网络再试~");
} else { } else {

View File

@@ -31,7 +31,6 @@ import com.yizhuan.xchat_android_core.auth.exception.AccountCancelException;
import com.yizhuan.xchat_android_core.auth.exception.BanAccountException; import com.yizhuan.xchat_android_core.auth.exception.BanAccountException;
import com.yizhuan.xchat_android_core.auth.exception.BigHeadPhoneException; import com.yizhuan.xchat_android_core.auth.exception.BigHeadPhoneException;
import com.yizhuan.xchat_android_core.auth.exception.IsSuperAdminException; import com.yizhuan.xchat_android_core.auth.exception.IsSuperAdminException;
import com.yizhuan.xchat_android_core.auth.exception.ShowPhoneCodeException;
import com.yizhuan.xchat_android_core.base.BaseModel; import com.yizhuan.xchat_android_core.base.BaseModel;
import com.yizhuan.xchat_android_core.bean.response.ServiceResult; import com.yizhuan.xchat_android_core.bean.response.ServiceResult;
import com.yizhuan.xchat_android_core.bean.response.result.LoginResult; import com.yizhuan.xchat_android_core.bean.response.result.LoginResult;
@@ -86,23 +85,36 @@ import retrofit2.http.Query;
public class AuthModel extends BaseModel implements IAuthModel { public class AuthModel extends BaseModel implements IAuthModel {
/**
* 封禁账号
*/
public static final int CODE_BAN_ACCOUNT = 407;
/**
* 封禁设备
*/
public static final int CODE_BAN_DEVICE = 408;
/**
* 验证码结果不正确
*/
public static final int VERIFY_CODE_ERROR = 3002; // 图片验证码?
/**
* 账号已注销
*/
public static final int CODE_ACCOUNT_CANCEL = 3009;
/**
* 注册异常,请稍后再试
*/
public static final int CODE_HIT_YI_DUN = 24000;
/**
* 一个手机绑定多个账号(大头账号)
*/
public static final int CODE_BIG_HEAD_NUM = 25002;
private static final String TAG = "AuthModel"; private static final String TAG = "AuthModel";
/** /**
* 类型1、手机号/耳伴号登陆2、手机号/耳伴号登陆并绑定QQ * 类型1、手机号/耳伴号登陆2、手机号/耳伴号登陆并绑定QQ
*/ */
private static final int TYPE_LOGIN_NORMAL = 1; private static final int TYPE_LOGIN_NORMAL = 1;
private static final int TYPE_LOGIN_BIND_QQ = 2; private static final int TYPE_LOGIN_BIND_QQ = 2;
/**
* 封禁账号
*/
public static final int CODE_BAN_ACCOUNT = 407;
/**
* 封禁设备
*/
public static final int CODE_BAN_DEVICE = 408;
/** /**
* 校验验证码 * 校验验证码
*/ */
@@ -111,44 +123,24 @@ public class AuthModel extends BaseModel implements IAuthModel {
* 超管登录校验验证码 * 超管登录校验验证码
*/ */
private static final int SUPER_CODE_SHOW_CODE = 136; private static final int SUPER_CODE_SHOW_CODE = 136;
/**
* 验证码结果不正确
*/
public static final int VERIFY_CODE_ERROR = 3002; // 图片验证码?
/**
* 账号已注销
*/
public static final int CODE_ACCOUNT_CANCEL = 3009;
/**
* 注册异常,请稍后再试
*/
public static final int CODE_HIT_YI_DUN = 24000;
/**
* 一个手机绑定多个账号(大头账号)
*/
public static final int CODE_BIG_HEAD_NUM = 25002;
private Api api;
@Getter
private AccountInfo currentAccountInfo;
private TicketInfo ticketInfo;
private ThirdUserInfo thirdUserInfo;
private static final int TYPE_WECHAT_LOGIN = 1;//微信登录类型 private static final int TYPE_WECHAT_LOGIN = 1;//微信登录类型
private static final int TYPE_QQ_LOGIN = 2;//QQ登录类型 private static final int TYPE_QQ_LOGIN = 2;//QQ登录类型
private Platform wechat; private volatile static AuthModel instance = null;
private Platform qq;
/** /**
* 是否来源于登录 * 是否来源于登录
*/ */
public boolean isFromLogin = false; public boolean isFromLogin = false;
private volatile static AuthModel instance = null; boolean isInit = false;
private Api api;
@Getter
private AccountInfo currentAccountInfo;
private TicketInfo ticketInfo;
private ThirdUserInfo thirdUserInfo;
private Platform wechat;
private Platform qq;
/****************************************************** IM *************************************************************/
private StatusCode statusCode;
private AuthModel() { private AuthModel() {
api = RxNet.create(Api.class); api = RxNet.create(Api.class);
@@ -222,16 +214,16 @@ public class AuthModel extends BaseModel implements IAuthModel {
return Single.error(new Throwable(""));//没有账号信息 return Single.error(new Throwable(""));//没有账号信息
} }
return requestTicket().flatMap(new Function<TicketResult, SingleSource<? extends String>>() { return requestTicket().flatMap(new Function<TicketResult, SingleSource<? extends String>>() {
@Override @Override
public SingleSource<? extends String> apply(TicketResult ticketResult) throws Exception { public SingleSource<? extends String> apply(TicketResult ticketResult) throws Exception {
if (!ticketResult.isSuccess()) { if (!ticketResult.isSuccess()) {
return Single.error(new Throwable(ticketResult.getMessage())); return Single.error(new Throwable(ticketResult.getMessage()));
} }
ticketInfo = ticketResult.getData(); ticketInfo = ticketResult.getData();
DemoCache.saveTicketInfo(ticketInfo); DemoCache.saveTicketInfo(ticketInfo);
return Single.just("自动登录成功"); return Single.just("自动登录成功");
} }
}) })
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.flatMap(new Function<String, SingleSource<String>>() { .flatMap(new Function<String, SingleSource<String>>() {
@@ -261,67 +253,64 @@ public class AuthModel extends BaseModel implements IAuthModel {
@Override @Override
public Single<String> login(String account, String password, String code, String yiDunToken, String shuMeiDeviceId) { public Single<String> login(String account, String password, String code, String yiDunToken, String shuMeiDeviceId) {
return Single.create(new SingleOnSubscribe<String>() { return Single.create(new SingleOnSubscribe<String>() {
@Override @Override
public void subscribe(SingleEmitter<String> emitter) throws Exception { public void subscribe(SingleEmitter<String> emitter) throws Exception {
//获取登录信息 //获取登录信息
try { try {
LoginResult loginResult = api.login( LoginResult loginResult = api.login(
DESUtils.DESAndBase64(account), DESUtils.DESAndBase64(account),
VersionUtil.getLocalName(BasicConfig.INSTANCE.getAppContext()), VersionUtil.getLocalName(BasicConfig.INSTANCE.getAppContext()),
"erban-client", "erban-client",
DESUtils.DESAndBase64(account), DESUtils.DESAndBase64(account),
DESAndBase64(password), DESAndBase64(password),
"password", "password",
"uyzjdhds", "uyzjdhds",
code, code,
yiDunToken, yiDunToken,
shuMeiDeviceId shuMeiDeviceId
).blockingGet(); ).blockingGet();
if (!loginResult.isSuccess()) { if (!loginResult.isSuccess()) {
if (loginResult.getCode() == CODE_BAN_ACCOUNT || loginResult.getCode() == CODE_BAN_DEVICE) { if (loginResult.getCode() == CODE_BAN_ACCOUNT || loginResult.getCode() == CODE_BAN_DEVICE) {
emitter.onError(new BanAccountException(loginResult.getReason(), loginResult.getDate())); emitter.onError(new BanAccountException(loginResult.getReason(), loginResult.getDate()));
} else if (loginResult.getCode() == CODE_ACCOUNT_CANCEL) { } else if (loginResult.getCode() == CODE_ACCOUNT_CANCEL) {
emitter.onError(new AccountCancelException(loginResult.getMessage(), loginResult.getErbanNo(), loginResult.getCancelDate())); emitter.onError(new AccountCancelException(loginResult.getMessage(), loginResult.getErbanNo(), loginResult.getCancelDate()));
} else if (loginResult.getCode() == CODE_SHOW_CODE) { } else if (loginResult.getCode() == SUPER_CODE_SHOW_CODE) {
emitter.onError(new ShowPhoneCodeException(loginResult.getMessage(), loginResult.isVerifyCode())); //是否是超管
} else if (loginResult.getCode() == SUPER_CODE_SHOW_CODE) { if (loginResult.getSuperCodeVerify() == 1) {
//是否是超管 emitter.onError(new IsSuperAdminException(loginResult.getMessage()));
if (loginResult.getSuperCodeVerify() == 1) { } else {
emitter.onError(new IsSuperAdminException(loginResult.getMessage())); emitter.onError(new Throwable(loginResult.getMessage()));
} else { }
emitter.onError(new Throwable(loginResult.getMessage())); } else {
emitter.onError(new Throwable(loginResult.getMessage()));
}
return;
} }
} else { currentAccountInfo = loginResult.getData();
emitter.onError(new Throwable(loginResult.getMessage())); DemoCache.saveCurrentAccountInfo(currentAccountInfo);
//成功获取到uid后就通知首页刷新审核中状态的数据
EventBus.getDefault().post(new GetCurrentUidEvent(true));
} catch (Exception e) {
emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
return;
} }
return; //获取tick
} try {
currentAccountInfo = loginResult.getData(); TicketResult ticketResult = requestTicket().blockingGet();
DemoCache.saveCurrentAccountInfo(currentAccountInfo); if (!ticketResult.isSuccess()) {
//成功获取到uid后就通知首页刷新审核中状态的数据 emitter.onError(new Throwable(ticketResult.getMessage()));
EventBus.getDefault().post(new GetCurrentUidEvent(true)); return;
} catch (Exception e) { }
emitter.onError(handleException(e)); ticketInfo = ticketResult.getData();
//emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e))); DemoCache.saveTicketInfo(ticketInfo);
return;
}
//获取tick
try {
TicketResult ticketResult = requestTicket().blockingGet();
if (!ticketResult.isSuccess()) {
emitter.onError(new Throwable(ticketResult.getMessage()));
return;
}
ticketInfo = ticketResult.getData();
DemoCache.saveTicketInfo(ticketInfo);
} catch (Exception e) { } catch (Exception e) {
emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e))); emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
return; return;
} }
emitter.onSuccess("登录成功!"); emitter.onSuccess("登录成功!");
} }
}) })
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.flatMap(new Function<String, SingleSource<String>>() { .flatMap(new Function<String, SingleSource<String>>() {
@@ -339,36 +328,6 @@ public class AuthModel extends BaseModel implements IAuthModel {
}); });
} }
/**
* 处理异常
*
* @param e
*/
private Exception handleException(Exception e) {
try {
if (e instanceof HttpException) {
Response response = ((HttpException) e).response();
if (response != null) {
ResponseBody errorBody = response.errorBody();
if (errorBody != null) {
String content = errorBody.string();
LoginResult result = new Gson().fromJson(content, LoginResult.class);
if (result != null) {
if (result.isVerifyCode()) {
return new ShowPhoneCodeException(result.getMessage(), result.isVerifyCode());
} else {
return new RuntimeException(result.getMessage());
}
}
}
}
}
} catch (IOException e1) {
e1.printStackTrace();
}
return e;
}
/** /**
* 微信登录 * 微信登录
@@ -378,47 +337,47 @@ public class AuthModel extends BaseModel implements IAuthModel {
@Override @Override
public Single<String> wxLogin(String yiDunToken, String shuMeiDeviceId) { public Single<String> wxLogin(String yiDunToken, String shuMeiDeviceId) {
return Single.create(new SingleOnSubscribe<Platform>() { return Single.create(new SingleOnSubscribe<Platform>() {
@Override
public void subscribe(SingleEmitter<Platform> e) throws Exception {
wechat = ShareSDK.getPlatform(Wechat.NAME);
if (wechat == null || !wechat.isClientValid()) {
e.onError(new Throwable("未安装微信"));
return;
}
if (wechat.isAuthValid()) {
wechat.removeAccount(true);
}
wechat.setPlatformActionListener(new PlatformActionListener() {
@Override @Override
public void onComplete(final Platform platform, int i, HashMap<String, Object> hashMap) { public void subscribe(SingleEmitter<Platform> e) throws Exception {
if (i == Platform.ACTION_USER_INFOR) { wechat = ShareSDK.getPlatform(Wechat.NAME);
String openid = platform.getDb().getUserId(); if (wechat == null || !wechat.isClientValid()) {
String unionid = platform.getDb().get("unionid"); e.onError(new Throwable("未安装微信"));
Logger.i("openid" + openid + "unionid" + unionid + platform.getDb().getUserIcon()); return;
thirdUserInfo = new ThirdUserInfo();
thirdUserInfo.setPlatform("微信");
thirdUserInfo.setType(ThirdUserInfo.TYPE_WX);
thirdUserInfo.setUserName(platform.getDb().getUserName());
thirdUserInfo.setUserGender(platform.getDb().getUserGender());
thirdUserInfo.setUserIcon(platform.getDb().getUserIcon());
e.onSuccess(platform);
} }
} if (wechat.isAuthValid()) {
wechat.removeAccount(true);
}
wechat.setPlatformActionListener(new PlatformActionListener() {
@Override
public void onComplete(final Platform platform, int i, HashMap<String, Object> hashMap) {
if (i == Platform.ACTION_USER_INFOR) {
String openid = platform.getDb().getUserId();
String unionid = platform.getDb().get("unionid");
Logger.i("openid" + openid + "unionid" + unionid + platform.getDb().getUserIcon());
thirdUserInfo = new ThirdUserInfo();
thirdUserInfo.setPlatform("微信");
thirdUserInfo.setType(ThirdUserInfo.TYPE_WX);
thirdUserInfo.setUserName(platform.getDb().getUserName());
thirdUserInfo.setUserGender(platform.getDb().getUserGender());
thirdUserInfo.setUserIcon(platform.getDb().getUserIcon());
e.onSuccess(platform);
}
}
@Override @Override
public void onError(Platform platform, int i, Throwable throwable) { public void onError(Platform platform, int i, Throwable throwable) {
e.onError(new Throwable("获取微信信息失败")); e.onError(new Throwable("获取微信信息失败"));
} }
@Override @Override
public void onCancel(Platform platform, int i) { public void onCancel(Platform platform, int i) {
e.onError(new Throwable("微信登录取消")); e.onError(new Throwable("微信登录取消"));
}
});
wechat.SSOSetting(false);
wechat.showUser(null);
} }
}); })
wechat.SSOSetting(false);
wechat.showUser(null);
}
})
.flatMap(new Function<Platform, SingleSource<String>>() { .flatMap(new Function<Platform, SingleSource<String>>() {
@Override @Override
public SingleSource<String> apply(Platform platform) throws Exception { public SingleSource<String> apply(Platform platform) throws Exception {
@@ -453,48 +412,48 @@ public class AuthModel extends BaseModel implements IAuthModel {
@Override @Override
public Single<String> qqLogin(String yiDunToken, String shuMeiDeviceId) { public Single<String> qqLogin(String yiDunToken, String shuMeiDeviceId) {
return Single.create(new SingleOnSubscribe<Platform>() { return Single.create(new SingleOnSubscribe<Platform>() {
@Override
public void subscribe(SingleEmitter<Platform> e) throws Exception {
qq = ShareSDK.getPlatform(QQ.NAME);
if (qq == null || !qq.isClientValid()) {
e.onError(new Throwable("未安装腾讯QQ或TIM"));
return;
}
if (qq.isAuthValid()) {
qq.removeAccount(true);
}
qq.setPlatformActionListener(new PlatformActionListener() {
@Override @Override
public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) { public void subscribe(SingleEmitter<Platform> e) throws Exception {
if (i == Platform.ACTION_USER_INFOR) { qq = ShareSDK.getPlatform(QQ.NAME);
String openid = platform.getDb().getUserId(); if (qq == null || !qq.isClientValid()) {
String unionid = platform.getDb().get("unionid"); e.onError(new Throwable("未安装腾讯QQ或TIM"));
Logger.i("openid:" + openid + " unionid:" + unionid + platform.getDb().getUserIcon()); return;
thirdUserInfo = new ThirdUserInfo();
thirdUserInfo.setType(ThirdUserInfo.TYPE_QQ);
thirdUserInfo.setUserName(platform.getDb().getUserName());
thirdUserInfo.setUserGender(platform.getDb().getUserGender());
thirdUserInfo.setUserIcon(platform.getDb().getUserIcon());
e.onSuccess(platform);
} }
} if (qq.isAuthValid()) {
qq.removeAccount(true);
}
qq.setPlatformActionListener(new PlatformActionListener() {
@Override
public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
if (i == Platform.ACTION_USER_INFOR) {
String openid = platform.getDb().getUserId();
String unionid = platform.getDb().get("unionid");
Logger.i("openid:" + openid + " unionid:" + unionid + platform.getDb().getUserIcon());
@Override thirdUserInfo = new ThirdUserInfo();
public void onError(Platform platform, int i, Throwable throwable) { thirdUserInfo.setType(ThirdUserInfo.TYPE_QQ);
e.onError(new Throwable("获取QQ登录信息错误")); thirdUserInfo.setUserName(platform.getDb().getUserName());
} thirdUserInfo.setUserGender(platform.getDb().getUserGender());
thirdUserInfo.setUserIcon(platform.getDb().getUserIcon());
e.onSuccess(platform);
}
}
@Override @Override
public void onCancel(Platform platform, int i) { public void onError(Platform platform, int i, Throwable throwable) {
e.onError(new Throwable("QQ登录取消")); e.onError(new Throwable("获取QQ登录信息错误"));
} }
});
qq.SSOSetting(false);
qq.showUser(null);
} @Override
}) public void onCancel(Platform platform, int i) {
e.onError(new Throwable("QQ登录取消"));
}
});
qq.SSOSetting(false);
qq.showUser(null);
}
})
.flatMap(new Function<Platform, SingleSource<String>>() { .flatMap(new Function<Platform, SingleSource<String>>() {
@Override @Override
public SingleSource<String> apply(Platform platform) throws Exception { public SingleSource<String> apply(Platform platform) throws Exception {
@@ -537,52 +496,52 @@ public class AuthModel extends BaseModel implements IAuthModel {
String finalLinkedmeChannel = linkedmeChannel; String finalLinkedmeChannel = linkedmeChannel;
return Single.create(new SingleOnSubscribe<String>() { return Single.create(new SingleOnSubscribe<String>() {
@Override @Override
public void subscribe(SingleEmitter<String> e) throws Exception { public void subscribe(SingleEmitter<String> e) throws Exception {
try { try {
LoginResult loginResult = api.thirdLogin( LoginResult loginResult = api.thirdLogin(
openid, openid,
unionid, unionid,
String.valueOf(type), String.valueOf(type),
finalLinkedmeChannel, finalLinkedmeChannel,
yiDunToken, yiDunToken,
shuMeiDeviceId shuMeiDeviceId
).blockingGet(); ).blockingGet();
if (!loginResult.isSuccess()) { if (!loginResult.isSuccess()) {
if (loginResult.getCode() == CODE_BAN_ACCOUNT || loginResult.getCode() == CODE_BAN_DEVICE) { if (loginResult.getCode() == CODE_BAN_ACCOUNT || loginResult.getCode() == CODE_BAN_DEVICE) {
e.onError(new BanAccountException(loginResult.getReason(), loginResult.getDate())); e.onError(new BanAccountException(loginResult.getReason(), loginResult.getDate()));
} else if (loginResult.getCode() == CODE_ACCOUNT_CANCEL) { } else if (loginResult.getCode() == CODE_ACCOUNT_CANCEL) {
e.onError(new AccountCancelException(loginResult.getMessage(), loginResult.getErbanNo(), loginResult.getCancelDate())); e.onError(new AccountCancelException(loginResult.getMessage(), loginResult.getErbanNo(), loginResult.getCancelDate()));
} else { } else {
e.onError(new Throwable(loginResult.getMessage())); e.onError(new Throwable(loginResult.getMessage()));
}
return;
}
currentAccountInfo = loginResult.getData();
DemoCache.saveCurrentAccountInfo(currentAccountInfo);
//成功获取到uid后就通知首页刷新审核中状态的数据
EventBus.getDefault().post(new GetCurrentUidEvent(true));
} catch (Exception e1) {
e.onError(new Throwable(OldHttpErrorHandleUtil.handle(e1)));
return;
} }
return; //获取tick
} try {
currentAccountInfo = loginResult.getData(); TicketResult ticketResult = requestTicket().blockingGet();
DemoCache.saveCurrentAccountInfo(currentAccountInfo); if (!ticketResult.isSuccess()) {
//成功获取到uid后就通知首页刷新审核中状态的数据 e.onError(new Throwable(ticketResult.getMessage()));
EventBus.getDefault().post(new GetCurrentUidEvent(true)); return;
} catch (Exception e1) { }
e.onError(new Throwable(OldHttpErrorHandleUtil.handle(e1))); ticketInfo = ticketResult.getData();
return; DemoCache.saveTicketInfo(ticketInfo);
}
//获取tick
try {
TicketResult ticketResult = requestTicket().blockingGet();
if (!ticketResult.isSuccess()) {
e.onError(new Throwable(ticketResult.getMessage()));
return;
}
ticketInfo = ticketResult.getData();
DemoCache.saveTicketInfo(ticketInfo);
} catch (Exception e1) { } catch (Exception e1) {
e.onError(new Throwable(OldHttpErrorHandleUtil.handle(e1))); e.onError(new Throwable(OldHttpErrorHandleUtil.handle(e1)));
return; return;
} }
e.onSuccess("登录成功!"); e.onSuccess("登录成功!");
} }
}).subscribeOn(Schedulers.io()) }).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()); .observeOn(AndroidSchedulers.mainThread());
} }
@@ -590,58 +549,55 @@ public class AuthModel extends BaseModel implements IAuthModel {
@Override @Override
public Single<String> quickPassLogin(String token, String accessToken, String shuMeiDeviceId, String yiDunToken) { public Single<String> quickPassLogin(String token, String accessToken, String shuMeiDeviceId, String yiDunToken) {
return Single.create(new SingleOnSubscribe<String>() { return Single.create(new SingleOnSubscribe<String>() {
@Override @Override
public void subscribe(SingleEmitter<String> emitter) throws Exception { public void subscribe(SingleEmitter<String> emitter) throws Exception {
//获取登录信息 //获取登录信息
try { try {
LoginResult loginResult = api.quickPassLogin(token, accessToken, yiDunToken, shuMeiDeviceId).blockingGet(); LoginResult loginResult = api.quickPassLogin(token, accessToken, yiDunToken, shuMeiDeviceId).blockingGet();
if (!loginResult.isSuccess()) { if (!loginResult.isSuccess()) {
if (loginResult.getCode() == CODE_BAN_ACCOUNT || loginResult.getCode() == CODE_BAN_DEVICE) { if (loginResult.getCode() == CODE_BAN_ACCOUNT || loginResult.getCode() == CODE_BAN_DEVICE) {
emitter.onError(new BanAccountException(loginResult.getReason(), loginResult.getDate())); emitter.onError(new BanAccountException(loginResult.getReason(), loginResult.getDate()));
} else if (loginResult.getCode() == CODE_ACCOUNT_CANCEL) { } else if (loginResult.getCode() == CODE_ACCOUNT_CANCEL) {
emitter.onError(new AccountCancelException(loginResult.getMessage(), loginResult.getErbanNo(), loginResult.getCancelDate())); emitter.onError(new AccountCancelException(loginResult.getMessage(), loginResult.getErbanNo(), loginResult.getCancelDate()));
} else if (loginResult.getCode() == CODE_SHOW_CODE) { } else if (loginResult.getCode() == SUPER_CODE_SHOW_CODE) {
emitter.onError(new ShowPhoneCodeException(loginResult.getMessage(), loginResult.isVerifyCode())); //是否是超管
} else if (loginResult.getCode() == SUPER_CODE_SHOW_CODE) { if (loginResult.getSuperCodeVerify() == 1) {
//是否是超管 emitter.onError(new IsSuperAdminException(loginResult.getMessage()));
if (loginResult.getSuperCodeVerify() == 1) { } else {
emitter.onError(new IsSuperAdminException(loginResult.getMessage())); emitter.onError(new Throwable(loginResult.getMessage()));
} else { }
emitter.onError(new Throwable(loginResult.getMessage())); } else if (loginResult.getCode() == CODE_BIG_HEAD_NUM) {
emitter.onError(new BigHeadPhoneException(loginResult.getMessage()));
} else {
emitter.onError(new Throwable(loginResult.getMessage()));
}
return;
} }
} else if (loginResult.getCode() == CODE_BIG_HEAD_NUM) { currentAccountInfo = loginResult.getData();
emitter.onError(new BigHeadPhoneException(loginResult.getMessage())); DemoCache.saveCurrentAccountInfo(currentAccountInfo);
} else { //成功获取到uid后就通知首页刷新审核中状态的数据
emitter.onError(new Throwable(loginResult.getMessage())); EventBus.getDefault().post(new GetCurrentUidEvent(true));
} catch (Exception e) {
emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
return;
} }
return; //获取tick
} try {
currentAccountInfo = loginResult.getData(); TicketResult ticketResult = requestTicket().blockingGet();
DemoCache.saveCurrentAccountInfo(currentAccountInfo); if (!ticketResult.isSuccess()) {
//成功获取到uid后就通知首页刷新审核中状态的数据 emitter.onError(new Throwable(ticketResult.getMessage()));
EventBus.getDefault().post(new GetCurrentUidEvent(true)); return;
} catch (Exception e) { }
emitter.onError(handleException(e)); ticketInfo = ticketResult.getData();
//emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e))); DemoCache.saveTicketInfo(ticketInfo);
return;
}
//获取tick
try {
TicketResult ticketResult = requestTicket().blockingGet();
if (!ticketResult.isSuccess()) {
emitter.onError(new Throwable(ticketResult.getMessage()));
return;
}
ticketInfo = ticketResult.getData();
DemoCache.saveTicketInfo(ticketInfo);
} catch (Exception e) { } catch (Exception e) {
emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e))); emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
return; return;
} }
emitter.onSuccess("登录成功!"); emitter.onSuccess("登录成功!");
} }
}) })
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.flatMap(new Function<String, SingleSource<String>>() { .flatMap(new Function<String, SingleSource<String>>() {
@@ -697,7 +653,6 @@ public class AuthModel extends BaseModel implements IAuthModel {
return pwd; return pwd;
} }
/** /**
* 获取短信验证码 * 获取短信验证码
* *
@@ -708,23 +663,23 @@ public class AuthModel extends BaseModel implements IAuthModel {
@Override @Override
public Single<String> requestSMSCode(String phone, int type) { public Single<String> requestSMSCode(String phone, int type) {
return Single.create(new SingleOnSubscribe<String>() { return Single.create(new SingleOnSubscribe<String>() {
@Override @Override
public void subscribe(SingleEmitter<String> emitter) throws Exception { public void subscribe(SingleEmitter<String> emitter) throws Exception {
try { try {
ServiceResult serviceResult = api.requestSMSCode( ServiceResult serviceResult = api.requestSMSCode(
DESUtils.DESAndBase64(phone), DESUtils.DESAndBase64(phone),
String.valueOf(type) String.valueOf(type)
).blockingGet(); ).blockingGet();
if (!serviceResult.isSuccess()) { if (!serviceResult.isSuccess()) {
emitter.onError(new Throwable(serviceResult.getMessage())); emitter.onError(new Throwable(serviceResult.getMessage()));
return; return;
}
emitter.onSuccess("获取短信验证码成功");
} catch (Exception e) {
emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
}
} }
emitter.onSuccess("获取短信验证码成功"); }).subscribeOn(Schedulers.io())
} catch (Exception e) {
emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
}
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()); .observeOn(AndroidSchedulers.mainThread());
} }
@@ -739,26 +694,26 @@ public class AuthModel extends BaseModel implements IAuthModel {
@Override @Override
public Single<String> requestResetPsw(String phone, String sms_code, String newPsw) { public Single<String> requestResetPsw(String phone, String sms_code, String newPsw) {
return Single.create(new SingleOnSubscribe<String>() { return Single.create(new SingleOnSubscribe<String>() {
@Override @Override
public void subscribe(SingleEmitter<String> e) throws Exception { public void subscribe(SingleEmitter<String> e) throws Exception {
try { try {
ServiceResult serviceResult = api.requestResetPsw( ServiceResult serviceResult = api.requestResetPsw(
DESUtils.DESAndBase64(phone), DESUtils.DESAndBase64(phone),
sms_code, sms_code,
DESAndBase64(newPsw) DESAndBase64(newPsw)
).blockingGet(); ).blockingGet();
if (!serviceResult.isSuccess()) { if (!serviceResult.isSuccess()) {
e.onError(new Throwable(serviceResult.getMessage())); e.onError(new Throwable(serviceResult.getMessage()));
return; return;
} }
e.onSuccess("重置密码成功"); e.onSuccess("重置密码成功");
} catch (Exception e1) { } catch (Exception e1) {
e1.printStackTrace(); e1.printStackTrace();
e.onError(new Throwable(OldHttpErrorHandleUtil.handle(e1))); e.onError(new Throwable(OldHttpErrorHandleUtil.handle(e1)));
} }
} }
}) })
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()); .observeOn(AndroidSchedulers.mainThread());
@@ -776,8 +731,8 @@ public class AuthModel extends BaseModel implements IAuthModel {
} }
return api.isBindPhone( return api.isBindPhone(
String.valueOf(currentAccountInfo.getUid()) String.valueOf(currentAccountInfo.getUid())
) )
.flatMap(new Function<ServiceResult, SingleSource<? extends String>>() { .flatMap(new Function<ServiceResult, SingleSource<? extends String>>() {
@Override @Override
public SingleSource<? extends String> apply(ServiceResult serviceResult) throws Exception { public SingleSource<? extends String> apply(ServiceResult serviceResult) throws Exception {
@@ -804,11 +759,11 @@ public class AuthModel extends BaseModel implements IAuthModel {
return Single.error(new Throwable("获取不到当前用户UID")); return Single.error(new Throwable("获取不到当前用户UID"));
} }
return api.bindPhone( return api.bindPhone(
String.valueOf(currentAccountInfo.getUid()), String.valueOf(currentAccountInfo.getUid()),
DESUtils.DESAndBase64(phone), DESUtils.DESAndBase64(phone),
code, code,
getTicket() getTicket()
) )
.flatMap(serviceResult -> { .flatMap(serviceResult -> {
if (!serviceResult.isSuccess()) { if (!serviceResult.isSuccess()) {
return Single.error(new Throwable(serviceResult.getMessage())); return Single.error(new Throwable(serviceResult.getMessage()));
@@ -838,9 +793,9 @@ public class AuthModel extends BaseModel implements IAuthModel {
e.printStackTrace(); e.printStackTrace();
} }
return api.getSMSCode( return api.getSMSCode(
paramsStr, paramsStr,
signStr signStr
) )
.flatMap(new Function<ServiceResult, SingleSource<String>>() { .flatMap(new Function<ServiceResult, SingleSource<String>>() {
@Override @Override
public SingleSource<String> apply(ServiceResult serviceResult) throws Exception { public SingleSource<String> apply(ServiceResult serviceResult) throws Exception {
@@ -872,14 +827,14 @@ public class AuthModel extends BaseModel implements IAuthModel {
linkedmeChannel = linkedInfo.getChannel(); linkedmeChannel = linkedInfo.getChannel();
} }
return api.register( return api.register(
DESUtils.DESAndBase64(phone), DESUtils.DESAndBase64(phone),
sms_code, sms_code,
verifyCode, verifyCode,
DESAndBase64(password), DESAndBase64(password),
linkedmeChannel, linkedmeChannel,
yiDunToken, yiDunToken,
shuMeiDeviceId shuMeiDeviceId
) )
.flatMap(new Function<RegisterResult, SingleSource<String>>() { .flatMap(new Function<RegisterResult, SingleSource<String>>() {
@Override @Override
public SingleSource<String> apply(RegisterResult registerResult) throws Exception { public SingleSource<String> apply(RegisterResult registerResult) throws Exception {
@@ -944,7 +899,6 @@ public class AuthModel extends BaseModel implements IAuthModel {
EventBus.getDefault().post(new LogoutEvent()); EventBus.getDefault().post(new LogoutEvent());
} }
/** /**
* 修改登录密码 * 修改登录密码
* *
@@ -962,12 +916,12 @@ public class AuthModel extends BaseModel implements IAuthModel {
return Single.error(new Throwable("没有ticket信息")); return Single.error(new Throwable("没有ticket信息"));
} }
return api.changeLoginPwd( return api.changeLoginPwd(
DESUtils.DESAndBase64(phone), DESUtils.DESAndBase64(phone),
oldPwd, oldPwd,
newPwd, newPwd,
getTicket() getTicket()
) )
.flatMap(new Function<ServiceResult<String>, SingleSource<? extends String>>() { .flatMap(new Function<ServiceResult<String>, SingleSource<? extends String>>() {
@Override @Override
public SingleSource<? extends String> apply(ServiceResult<String> stringServiceResult) throws Exception { public SingleSource<? extends String> apply(ServiceResult<String> stringServiceResult) throws Exception {
@@ -1000,11 +954,11 @@ public class AuthModel extends BaseModel implements IAuthModel {
} }
return api.setLoginPwd( return api.setLoginPwd(
DESUtils.DESAndBase64(phone), DESUtils.DESAndBase64(phone),
newPwd, newPwd,
String.valueOf(getCurrentUid()), String.valueOf(getCurrentUid()),
getTicket() getTicket()
) )
.flatMap(new Function<ServiceResult<String>, SingleSource<String>>() { .flatMap(new Function<ServiceResult<String>, SingleSource<String>>() {
@Override @Override
public SingleSource<String> apply(ServiceResult<String> stringServiceResult) throws Exception { public SingleSource<String> apply(ServiceResult<String> stringServiceResult) throws Exception {
@@ -1024,10 +978,6 @@ public class AuthModel extends BaseModel implements IAuthModel {
.compose(RxHelper.handleSchedulers()); .compose(RxHelper.handleSchedulers());
} }
/****************************************************** IM *************************************************************/
private StatusCode statusCode;
/** /**
* 判断IM 登录状态 * 判断IM 登录状态
* *
@@ -1038,9 +988,6 @@ public class AuthModel extends BaseModel implements IAuthModel {
return statusCode == StatusCode.LOGINED; return statusCode == StatusCode.LOGINED;
} }
boolean isInit = false;
/** /**
* 观察Im连接状态 * 观察Im连接状态
*/ */
@@ -1099,53 +1046,53 @@ public class AuthModel extends BaseModel implements IAuthModel {
Log.i("IMLogin", "account:" + account.getUid() + " token:" + account.getNetEaseToken() + " appkey:" + info.getAppKey()); Log.i("IMLogin", "account:" + account.getUid() + " token:" + account.getNetEaseToken() + " appkey:" + info.getAppKey());
LogUtil.e(TAG, "执行imLogin方法"); LogUtil.e(TAG, "执行imLogin方法");
return Single.create(new SingleOnSubscribe<String>() { return Single.create(new SingleOnSubscribe<String>() {
@Override
public void subscribe(SingleEmitter<String> emitter) throws Exception {
NIMClient.getService(AuthService.class).login(info).setCallback(new RequestCallback<LoginInfo>() {
@Override @Override
public void onSuccess(LoginInfo loginInfo) { public void subscribe(SingleEmitter<String> emitter) throws Exception {
if (loginInfo == null) { NIMClient.getService(AuthService.class).login(info).setCallback(new RequestCallback<LoginInfo>() {
onException(new Throwable("登录信息为空"));
return;
}
NimUIKit.setAccount(loginInfo.getAccount());
DataCacheManager.buildDataCacheAsync();
NimUIKit.getImageLoaderKit().buildImageCache();
//更新消息提醒配置
initNotificationConfig();
NIMClient.getService(MixPushService.class).enable(true).setCallback(new RequestCallbackWrapper<Void>() {
@Override @Override
public void onResult(int code, Void result, Throwable exception) { public void onSuccess(LoginInfo loginInfo) {
Log.e(TAG, "onResult() called with: code = [" + code + "], result = [" + result + "], exception = [" + exception + "]"); if (loginInfo == null) {
onException(new Throwable("登录信息为空"));
return;
}
NimUIKit.setAccount(loginInfo.getAccount());
DataCacheManager.buildDataCacheAsync();
NimUIKit.getImageLoaderKit().buildImageCache();
//更新消息提醒配置
initNotificationConfig();
NIMClient.getService(MixPushService.class).enable(true).setCallback(new RequestCallbackWrapper<Void>() {
@Override
public void onResult(int code, Void result, Throwable exception) {
Log.e(TAG, "onResult() called with: code = [" + code + "], result = [" + result + "], exception = [" + exception + "]");
}
});
Log.i("IMLogin", "IM登录成功");
emitter.onSuccess("IM登录成功");
}
@Override
public void onFailed(int code) {
LogUtil.e(TAG, "失败错误码:" + code);
emitter.onError(new Throwable("IM登录失败错误码" + code));
}
@Override
public void onException(Throwable exception) {
//如果云信登录出现异常将info打印到埋点
String infoJson = JsonUtils.toJson(info);
String error = "IM登录失败异常信息" + exception.toString()
+ ", LoginInfo:" + infoJson;
LogUtil.e(TAG, error);
emitter.onError(new Throwable(error));
} }
}); });
Log.i("IMLogin", "IM登录成功");
emitter.onSuccess("IM登录成功");
} }
})
@Override
public void onFailed(int code) {
LogUtil.e(TAG, "失败错误码:" + code);
emitter.onError(new Throwable("IM登录失败错误码" + code));
}
@Override
public void onException(Throwable exception) {
//如果云信登录出现异常将info打印到埋点
String infoJson = JsonUtils.toJson(info);
String error = "IM登录失败异常信息" + exception.toString()
+ ", LoginInfo:" + infoJson;
LogUtil.e(TAG, error);
emitter.onError(new Throwable(error));
}
});
}
})
.subscribeOn(AndroidSchedulers.mainThread()) .subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread()); .observeOn(AndroidSchedulers.mainThread());

View File

@@ -1,14 +0,0 @@
package com.yizhuan.xchat_android_core.auth.exception;
public class ShowPhoneCodeException extends Exception {
private final boolean showPhoneCode;
public ShowPhoneCodeException(String message, boolean showPhoneCode) {
super(message);
this.showPhoneCode = showPhoneCode;
}
public boolean isShowPhoneCode() {
return showPhoneCode;
}
}

View File

@@ -9,20 +9,25 @@ import retrofit2.HttpException;
public class OldHttpErrorHandleUtil { public class OldHttpErrorHandleUtil {
public static String handle(Throwable throwable){ public static String handle(Throwable throwable) {
try { try {
if (throwable instanceof HttpException){ if (throwable instanceof HttpException) {
retrofit2.Response<?> response = ((HttpException) throwable).response(); retrofit2.Response<?> response = ((HttpException) throwable).response();
if (response.errorBody() == null){ if (response.errorBody() == null) {
return throwable.getMessage(); return throwable.getMessage();
} }
byte[] bodyByte = response.errorBody().bytes(); byte[] bodyByte = response.errorBody().bytes();
if (bodyByte.length <= 0){ if (bodyByte.length <= 0) {
return throwable.getMessage(); return throwable.getMessage();
} }
ServiceResult result = new Gson().fromJson(new String(bodyByte, Charset.forName("UTF-8")), ServiceResult.class); ServiceResult result;
try {
result = new Gson().fromJson(new String(bodyByte, Charset.forName("UTF-8")), ServiceResult.class);
} catch (Exception e) {
return "大鹅开小差中~请稍后再试";
}
return result.getMessage(); return result.getMessage();
}else { } else {
return throwable.getMessage(); return throwable.getMessage();
} }
} catch (Exception e) { } catch (Exception e) {