登录错误提示优化
This commit is contained in:
@@ -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.BigHeadPhoneException;
|
||||
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.bean.response.ServiceResult;
|
||||
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 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";
|
||||
|
||||
/**
|
||||
* 类型(1、手机号/耳伴号登陆,2、手机号/耳伴号登陆并绑定QQ)
|
||||
*/
|
||||
private static final int TYPE_LOGIN_NORMAL = 1;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 验证码结果不正确
|
||||
*/
|
||||
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_QQ_LOGIN = 2;//QQ登录类型
|
||||
private Platform wechat;
|
||||
private Platform qq;
|
||||
private volatile static AuthModel instance = null;
|
||||
/**
|
||||
* 是否来源于登录
|
||||
*/
|
||||
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() {
|
||||
api = RxNet.create(Api.class);
|
||||
@@ -222,16 +214,16 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
return Single.error(new Throwable(""));//没有账号信息
|
||||
}
|
||||
return requestTicket().flatMap(new Function<TicketResult, SingleSource<? extends String>>() {
|
||||
@Override
|
||||
public SingleSource<? extends String> apply(TicketResult ticketResult) throws Exception {
|
||||
if (!ticketResult.isSuccess()) {
|
||||
return Single.error(new Throwable(ticketResult.getMessage()));
|
||||
}
|
||||
ticketInfo = ticketResult.getData();
|
||||
DemoCache.saveTicketInfo(ticketInfo);
|
||||
return Single.just("自动登录成功");
|
||||
}
|
||||
})
|
||||
@Override
|
||||
public SingleSource<? extends String> apply(TicketResult ticketResult) throws Exception {
|
||||
if (!ticketResult.isSuccess()) {
|
||||
return Single.error(new Throwable(ticketResult.getMessage()));
|
||||
}
|
||||
ticketInfo = ticketResult.getData();
|
||||
DemoCache.saveTicketInfo(ticketInfo);
|
||||
return Single.just("自动登录成功");
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.flatMap(new Function<String, SingleSource<String>>() {
|
||||
@@ -261,67 +253,64 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
@Override
|
||||
public Single<String> login(String account, String password, String code, String yiDunToken, String shuMeiDeviceId) {
|
||||
return Single.create(new SingleOnSubscribe<String>() {
|
||||
@Override
|
||||
public void subscribe(SingleEmitter<String> emitter) throws Exception {
|
||||
//获取登录信息
|
||||
try {
|
||||
LoginResult loginResult = api.login(
|
||||
DESUtils.DESAndBase64(account),
|
||||
VersionUtil.getLocalName(BasicConfig.INSTANCE.getAppContext()),
|
||||
"erban-client",
|
||||
DESUtils.DESAndBase64(account),
|
||||
DESAndBase64(password),
|
||||
"password",
|
||||
"uyzjdhds",
|
||||
code,
|
||||
yiDunToken,
|
||||
shuMeiDeviceId
|
||||
).blockingGet();
|
||||
if (!loginResult.isSuccess()) {
|
||||
if (loginResult.getCode() == CODE_BAN_ACCOUNT || loginResult.getCode() == CODE_BAN_DEVICE) {
|
||||
emitter.onError(new BanAccountException(loginResult.getReason(), loginResult.getDate()));
|
||||
} else if (loginResult.getCode() == CODE_ACCOUNT_CANCEL) {
|
||||
emitter.onError(new AccountCancelException(loginResult.getMessage(), loginResult.getErbanNo(), loginResult.getCancelDate()));
|
||||
} else if (loginResult.getCode() == 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()));
|
||||
} else {
|
||||
emitter.onError(new Throwable(loginResult.getMessage()));
|
||||
@Override
|
||||
public void subscribe(SingleEmitter<String> emitter) throws Exception {
|
||||
//获取登录信息
|
||||
try {
|
||||
LoginResult loginResult = api.login(
|
||||
DESUtils.DESAndBase64(account),
|
||||
VersionUtil.getLocalName(BasicConfig.INSTANCE.getAppContext()),
|
||||
"erban-client",
|
||||
DESUtils.DESAndBase64(account),
|
||||
DESAndBase64(password),
|
||||
"password",
|
||||
"uyzjdhds",
|
||||
code,
|
||||
yiDunToken,
|
||||
shuMeiDeviceId
|
||||
).blockingGet();
|
||||
if (!loginResult.isSuccess()) {
|
||||
if (loginResult.getCode() == CODE_BAN_ACCOUNT || loginResult.getCode() == CODE_BAN_DEVICE) {
|
||||
emitter.onError(new BanAccountException(loginResult.getReason(), loginResult.getDate()));
|
||||
} else if (loginResult.getCode() == CODE_ACCOUNT_CANCEL) {
|
||||
emitter.onError(new AccountCancelException(loginResult.getMessage(), loginResult.getErbanNo(), loginResult.getCancelDate()));
|
||||
} else if (loginResult.getCode() == SUPER_CODE_SHOW_CODE) {
|
||||
//是否是超管
|
||||
if (loginResult.getSuperCodeVerify() == 1) {
|
||||
emitter.onError(new IsSuperAdminException(loginResult.getMessage()));
|
||||
} else {
|
||||
emitter.onError(new Throwable(loginResult.getMessage()));
|
||||
}
|
||||
} else {
|
||||
emitter.onError(new Throwable(loginResult.getMessage()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
emitter.onError(new Throwable(loginResult.getMessage()));
|
||||
currentAccountInfo = loginResult.getData();
|
||||
DemoCache.saveCurrentAccountInfo(currentAccountInfo);
|
||||
//成功获取到uid后,就通知首页刷新审核中状态的数据
|
||||
EventBus.getDefault().post(new GetCurrentUidEvent(true));
|
||||
} catch (Exception e) {
|
||||
emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
currentAccountInfo = loginResult.getData();
|
||||
DemoCache.saveCurrentAccountInfo(currentAccountInfo);
|
||||
//成功获取到uid后,就通知首页刷新审核中状态的数据
|
||||
EventBus.getDefault().post(new GetCurrentUidEvent(true));
|
||||
} catch (Exception e) {
|
||||
emitter.onError(handleException(e));
|
||||
//emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
|
||||
return;
|
||||
}
|
||||
//获取tick
|
||||
try {
|
||||
TicketResult ticketResult = requestTicket().blockingGet();
|
||||
if (!ticketResult.isSuccess()) {
|
||||
emitter.onError(new Throwable(ticketResult.getMessage()));
|
||||
return;
|
||||
}
|
||||
ticketInfo = ticketResult.getData();
|
||||
DemoCache.saveTicketInfo(ticketInfo);
|
||||
//获取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) {
|
||||
emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
|
||||
return;
|
||||
}
|
||||
emitter.onSuccess("登录成功!");
|
||||
}
|
||||
})
|
||||
} catch (Exception e) {
|
||||
emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
|
||||
return;
|
||||
}
|
||||
emitter.onSuccess("登录成功!");
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.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
|
||||
public Single<String> wxLogin(String yiDunToken, String shuMeiDeviceId) {
|
||||
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
|
||||
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);
|
||||
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
|
||||
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
|
||||
public void onError(Platform platform, int i, Throwable throwable) {
|
||||
e.onError(new Throwable("获取微信信息失败"));
|
||||
}
|
||||
@Override
|
||||
public void onError(Platform platform, int i, Throwable throwable) {
|
||||
e.onError(new Throwable("获取微信信息失败"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(Platform platform, int i) {
|
||||
e.onError(new Throwable("微信登录取消"));
|
||||
@Override
|
||||
public void onCancel(Platform platform, int i) {
|
||||
e.onError(new Throwable("微信登录取消"));
|
||||
}
|
||||
});
|
||||
wechat.SSOSetting(false);
|
||||
wechat.showUser(null);
|
||||
}
|
||||
});
|
||||
wechat.SSOSetting(false);
|
||||
wechat.showUser(null);
|
||||
}
|
||||
})
|
||||
})
|
||||
.flatMap(new Function<Platform, SingleSource<String>>() {
|
||||
@Override
|
||||
public SingleSource<String> apply(Platform platform) throws Exception {
|
||||
@@ -453,48 +412,48 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
@Override
|
||||
public Single<String> qqLogin(String yiDunToken, String shuMeiDeviceId) {
|
||||
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
|
||||
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());
|
||||
|
||||
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);
|
||||
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
|
||||
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
|
||||
public void onError(Platform platform, int i, Throwable throwable) {
|
||||
e.onError(new Throwable("获取QQ登录信息错误"));
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(Platform platform, int i) {
|
||||
e.onError(new Throwable("QQ登录取消"));
|
||||
}
|
||||
});
|
||||
qq.SSOSetting(false);
|
||||
qq.showUser(null);
|
||||
@Override
|
||||
public void onError(Platform platform, int i, Throwable throwable) {
|
||||
e.onError(new Throwable("获取QQ登录信息错误"));
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
@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>>() {
|
||||
@Override
|
||||
public SingleSource<String> apply(Platform platform) throws Exception {
|
||||
@@ -537,52 +496,52 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
|
||||
String finalLinkedmeChannel = linkedmeChannel;
|
||||
return Single.create(new SingleOnSubscribe<String>() {
|
||||
@Override
|
||||
public void subscribe(SingleEmitter<String> e) throws Exception {
|
||||
try {
|
||||
LoginResult loginResult = api.thirdLogin(
|
||||
openid,
|
||||
unionid,
|
||||
String.valueOf(type),
|
||||
finalLinkedmeChannel,
|
||||
yiDunToken,
|
||||
shuMeiDeviceId
|
||||
).blockingGet();
|
||||
if (!loginResult.isSuccess()) {
|
||||
if (loginResult.getCode() == CODE_BAN_ACCOUNT || loginResult.getCode() == CODE_BAN_DEVICE) {
|
||||
e.onError(new BanAccountException(loginResult.getReason(), loginResult.getDate()));
|
||||
} else if (loginResult.getCode() == CODE_ACCOUNT_CANCEL) {
|
||||
e.onError(new AccountCancelException(loginResult.getMessage(), loginResult.getErbanNo(), loginResult.getCancelDate()));
|
||||
} else {
|
||||
e.onError(new Throwable(loginResult.getMessage()));
|
||||
@Override
|
||||
public void subscribe(SingleEmitter<String> e) throws Exception {
|
||||
try {
|
||||
LoginResult loginResult = api.thirdLogin(
|
||||
openid,
|
||||
unionid,
|
||||
String.valueOf(type),
|
||||
finalLinkedmeChannel,
|
||||
yiDunToken,
|
||||
shuMeiDeviceId
|
||||
).blockingGet();
|
||||
if (!loginResult.isSuccess()) {
|
||||
if (loginResult.getCode() == CODE_BAN_ACCOUNT || loginResult.getCode() == CODE_BAN_DEVICE) {
|
||||
e.onError(new BanAccountException(loginResult.getReason(), loginResult.getDate()));
|
||||
} else if (loginResult.getCode() == CODE_ACCOUNT_CANCEL) {
|
||||
e.onError(new AccountCancelException(loginResult.getMessage(), loginResult.getErbanNo(), loginResult.getCancelDate()));
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
currentAccountInfo = loginResult.getData();
|
||||
DemoCache.saveCurrentAccountInfo(currentAccountInfo);
|
||||
//成功获取到uid后,就通知首页刷新审核中状态的数据
|
||||
EventBus.getDefault().post(new GetCurrentUidEvent(true));
|
||||
} catch (Exception e1) {
|
||||
e.onError(new Throwable(OldHttpErrorHandleUtil.handle(e1)));
|
||||
return;
|
||||
}
|
||||
//获取tick
|
||||
try {
|
||||
TicketResult ticketResult = requestTicket().blockingGet();
|
||||
if (!ticketResult.isSuccess()) {
|
||||
e.onError(new Throwable(ticketResult.getMessage()));
|
||||
return;
|
||||
}
|
||||
ticketInfo = ticketResult.getData();
|
||||
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) {
|
||||
e.onError(new Throwable(OldHttpErrorHandleUtil.handle(e1)));
|
||||
return;
|
||||
}
|
||||
e.onSuccess("登录成功!");
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
} catch (Exception e1) {
|
||||
e.onError(new Throwable(OldHttpErrorHandleUtil.handle(e1)));
|
||||
return;
|
||||
}
|
||||
e.onSuccess("登录成功!");
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
|
||||
}
|
||||
@@ -590,58 +549,55 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
@Override
|
||||
public Single<String> quickPassLogin(String token, String accessToken, String shuMeiDeviceId, String yiDunToken) {
|
||||
return Single.create(new SingleOnSubscribe<String>() {
|
||||
@Override
|
||||
public void subscribe(SingleEmitter<String> emitter) throws Exception {
|
||||
//获取登录信息
|
||||
try {
|
||||
LoginResult loginResult = api.quickPassLogin(token, accessToken, yiDunToken, shuMeiDeviceId).blockingGet();
|
||||
if (!loginResult.isSuccess()) {
|
||||
if (loginResult.getCode() == CODE_BAN_ACCOUNT || loginResult.getCode() == CODE_BAN_DEVICE) {
|
||||
emitter.onError(new BanAccountException(loginResult.getReason(), loginResult.getDate()));
|
||||
} else if (loginResult.getCode() == CODE_ACCOUNT_CANCEL) {
|
||||
emitter.onError(new AccountCancelException(loginResult.getMessage(), loginResult.getErbanNo(), loginResult.getCancelDate()));
|
||||
} else if (loginResult.getCode() == 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()));
|
||||
} else {
|
||||
emitter.onError(new Throwable(loginResult.getMessage()));
|
||||
@Override
|
||||
public void subscribe(SingleEmitter<String> emitter) throws Exception {
|
||||
//获取登录信息
|
||||
try {
|
||||
LoginResult loginResult = api.quickPassLogin(token, accessToken, yiDunToken, shuMeiDeviceId).blockingGet();
|
||||
if (!loginResult.isSuccess()) {
|
||||
if (loginResult.getCode() == CODE_BAN_ACCOUNT || loginResult.getCode() == CODE_BAN_DEVICE) {
|
||||
emitter.onError(new BanAccountException(loginResult.getReason(), loginResult.getDate()));
|
||||
} else if (loginResult.getCode() == CODE_ACCOUNT_CANCEL) {
|
||||
emitter.onError(new AccountCancelException(loginResult.getMessage(), loginResult.getErbanNo(), loginResult.getCancelDate()));
|
||||
} else if (loginResult.getCode() == SUPER_CODE_SHOW_CODE) {
|
||||
//是否是超管
|
||||
if (loginResult.getSuperCodeVerify() == 1) {
|
||||
emitter.onError(new IsSuperAdminException(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) {
|
||||
emitter.onError(new BigHeadPhoneException(loginResult.getMessage()));
|
||||
} else {
|
||||
emitter.onError(new Throwable(loginResult.getMessage()));
|
||||
currentAccountInfo = loginResult.getData();
|
||||
DemoCache.saveCurrentAccountInfo(currentAccountInfo);
|
||||
//成功获取到uid后,就通知首页刷新审核中状态的数据
|
||||
EventBus.getDefault().post(new GetCurrentUidEvent(true));
|
||||
} catch (Exception e) {
|
||||
emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
currentAccountInfo = loginResult.getData();
|
||||
DemoCache.saveCurrentAccountInfo(currentAccountInfo);
|
||||
//成功获取到uid后,就通知首页刷新审核中状态的数据
|
||||
EventBus.getDefault().post(new GetCurrentUidEvent(true));
|
||||
} catch (Exception e) {
|
||||
emitter.onError(handleException(e));
|
||||
//emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
|
||||
return;
|
||||
}
|
||||
//获取tick
|
||||
try {
|
||||
TicketResult ticketResult = requestTicket().blockingGet();
|
||||
if (!ticketResult.isSuccess()) {
|
||||
emitter.onError(new Throwable(ticketResult.getMessage()));
|
||||
return;
|
||||
}
|
||||
ticketInfo = ticketResult.getData();
|
||||
DemoCache.saveTicketInfo(ticketInfo);
|
||||
//获取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) {
|
||||
emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
|
||||
return;
|
||||
}
|
||||
emitter.onSuccess("登录成功!");
|
||||
}
|
||||
})
|
||||
} catch (Exception e) {
|
||||
emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
|
||||
return;
|
||||
}
|
||||
emitter.onSuccess("登录成功!");
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.flatMap(new Function<String, SingleSource<String>>() {
|
||||
@@ -697,7 +653,6 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
return pwd;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取短信验证码
|
||||
*
|
||||
@@ -708,23 +663,23 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
@Override
|
||||
public Single<String> requestSMSCode(String phone, int type) {
|
||||
return Single.create(new SingleOnSubscribe<String>() {
|
||||
@Override
|
||||
public void subscribe(SingleEmitter<String> emitter) throws Exception {
|
||||
try {
|
||||
ServiceResult serviceResult = api.requestSMSCode(
|
||||
DESUtils.DESAndBase64(phone),
|
||||
String.valueOf(type)
|
||||
).blockingGet();
|
||||
if (!serviceResult.isSuccess()) {
|
||||
emitter.onError(new Throwable(serviceResult.getMessage()));
|
||||
return;
|
||||
@Override
|
||||
public void subscribe(SingleEmitter<String> emitter) throws Exception {
|
||||
try {
|
||||
ServiceResult serviceResult = api.requestSMSCode(
|
||||
DESUtils.DESAndBase64(phone),
|
||||
String.valueOf(type)
|
||||
).blockingGet();
|
||||
if (!serviceResult.isSuccess()) {
|
||||
emitter.onError(new Throwable(serviceResult.getMessage()));
|
||||
return;
|
||||
}
|
||||
emitter.onSuccess("获取短信验证码成功");
|
||||
} catch (Exception e) {
|
||||
emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
|
||||
}
|
||||
}
|
||||
emitter.onSuccess("获取短信验证码成功");
|
||||
} catch (Exception e) {
|
||||
emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
|
||||
}
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
@@ -739,26 +694,26 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
@Override
|
||||
public Single<String> requestResetPsw(String phone, String sms_code, String newPsw) {
|
||||
return Single.create(new SingleOnSubscribe<String>() {
|
||||
@Override
|
||||
public void subscribe(SingleEmitter<String> e) throws Exception {
|
||||
try {
|
||||
ServiceResult serviceResult = api.requestResetPsw(
|
||||
DESUtils.DESAndBase64(phone),
|
||||
sms_code,
|
||||
DESAndBase64(newPsw)
|
||||
).blockingGet();
|
||||
if (!serviceResult.isSuccess()) {
|
||||
e.onError(new Throwable(serviceResult.getMessage()));
|
||||
return;
|
||||
}
|
||||
e.onSuccess("重置密码成功");
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
e.onError(new Throwable(OldHttpErrorHandleUtil.handle(e1)));
|
||||
}
|
||||
@Override
|
||||
public void subscribe(SingleEmitter<String> e) throws Exception {
|
||||
try {
|
||||
ServiceResult serviceResult = api.requestResetPsw(
|
||||
DESUtils.DESAndBase64(phone),
|
||||
sms_code,
|
||||
DESAndBase64(newPsw)
|
||||
).blockingGet();
|
||||
if (!serviceResult.isSuccess()) {
|
||||
e.onError(new Throwable(serviceResult.getMessage()));
|
||||
return;
|
||||
}
|
||||
e.onSuccess("重置密码成功");
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
e.onError(new Throwable(OldHttpErrorHandleUtil.handle(e1)));
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
|
||||
@@ -776,8 +731,8 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
}
|
||||
|
||||
return api.isBindPhone(
|
||||
String.valueOf(currentAccountInfo.getUid())
|
||||
)
|
||||
String.valueOf(currentAccountInfo.getUid())
|
||||
)
|
||||
.flatMap(new Function<ServiceResult, SingleSource<? extends String>>() {
|
||||
@Override
|
||||
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 api.bindPhone(
|
||||
String.valueOf(currentAccountInfo.getUid()),
|
||||
DESUtils.DESAndBase64(phone),
|
||||
code,
|
||||
getTicket()
|
||||
)
|
||||
String.valueOf(currentAccountInfo.getUid()),
|
||||
DESUtils.DESAndBase64(phone),
|
||||
code,
|
||||
getTicket()
|
||||
)
|
||||
.flatMap(serviceResult -> {
|
||||
if (!serviceResult.isSuccess()) {
|
||||
return Single.error(new Throwable(serviceResult.getMessage()));
|
||||
@@ -838,9 +793,9 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return api.getSMSCode(
|
||||
paramsStr,
|
||||
signStr
|
||||
)
|
||||
paramsStr,
|
||||
signStr
|
||||
)
|
||||
.flatMap(new Function<ServiceResult, SingleSource<String>>() {
|
||||
@Override
|
||||
public SingleSource<String> apply(ServiceResult serviceResult) throws Exception {
|
||||
@@ -872,14 +827,14 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
linkedmeChannel = linkedInfo.getChannel();
|
||||
}
|
||||
return api.register(
|
||||
DESUtils.DESAndBase64(phone),
|
||||
sms_code,
|
||||
verifyCode,
|
||||
DESAndBase64(password),
|
||||
linkedmeChannel,
|
||||
yiDunToken,
|
||||
shuMeiDeviceId
|
||||
)
|
||||
DESUtils.DESAndBase64(phone),
|
||||
sms_code,
|
||||
verifyCode,
|
||||
DESAndBase64(password),
|
||||
linkedmeChannel,
|
||||
yiDunToken,
|
||||
shuMeiDeviceId
|
||||
)
|
||||
.flatMap(new Function<RegisterResult, SingleSource<String>>() {
|
||||
@Override
|
||||
public SingleSource<String> apply(RegisterResult registerResult) throws Exception {
|
||||
@@ -944,7 +899,6 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
EventBus.getDefault().post(new LogoutEvent());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改登录密码
|
||||
*
|
||||
@@ -962,12 +916,12 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
return Single.error(new Throwable("没有ticket信息"));
|
||||
}
|
||||
return api.changeLoginPwd(
|
||||
DESUtils.DESAndBase64(phone),
|
||||
oldPwd,
|
||||
newPwd,
|
||||
getTicket()
|
||||
DESUtils.DESAndBase64(phone),
|
||||
oldPwd,
|
||||
newPwd,
|
||||
getTicket()
|
||||
|
||||
)
|
||||
)
|
||||
.flatMap(new Function<ServiceResult<String>, SingleSource<? extends String>>() {
|
||||
@Override
|
||||
public SingleSource<? extends String> apply(ServiceResult<String> stringServiceResult) throws Exception {
|
||||
@@ -1000,11 +954,11 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
}
|
||||
|
||||
return api.setLoginPwd(
|
||||
DESUtils.DESAndBase64(phone),
|
||||
newPwd,
|
||||
String.valueOf(getCurrentUid()),
|
||||
getTicket()
|
||||
)
|
||||
DESUtils.DESAndBase64(phone),
|
||||
newPwd,
|
||||
String.valueOf(getCurrentUid()),
|
||||
getTicket()
|
||||
)
|
||||
.flatMap(new Function<ServiceResult<String>, SingleSource<String>>() {
|
||||
@Override
|
||||
public SingleSource<String> apply(ServiceResult<String> stringServiceResult) throws Exception {
|
||||
@@ -1024,10 +978,6 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
/****************************************************** IM *************************************************************/
|
||||
|
||||
private StatusCode statusCode;
|
||||
|
||||
/**
|
||||
* 判断IM 登录状态
|
||||
*
|
||||
@@ -1038,9 +988,6 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
return statusCode == StatusCode.LOGINED;
|
||||
}
|
||||
|
||||
|
||||
boolean isInit = false;
|
||||
|
||||
/**
|
||||
* 观察Im连接状态
|
||||
*/
|
||||
@@ -1099,53 +1046,53 @@ public class AuthModel extends BaseModel implements IAuthModel {
|
||||
Log.i("IMLogin", "account:" + account.getUid() + " token:" + account.getNetEaseToken() + " appkey:" + info.getAppKey());
|
||||
LogUtil.e(TAG, "执行imLogin方法");
|
||||
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
|
||||
public void onSuccess(LoginInfo loginInfo) {
|
||||
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>() {
|
||||
public void subscribe(SingleEmitter<String> emitter) throws Exception {
|
||||
NIMClient.getService(AuthService.class).login(info).setCallback(new RequestCallback<LoginInfo>() {
|
||||
@Override
|
||||
public void onResult(int code, Void result, Throwable exception) {
|
||||
Log.e(TAG, "onResult() called with: code = [" + code + "], result = [" + result + "], exception = [" + exception + "]");
|
||||
public void onSuccess(LoginInfo loginInfo) {
|
||||
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())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -9,20 +9,25 @@ import retrofit2.HttpException;
|
||||
|
||||
public class OldHttpErrorHandleUtil {
|
||||
|
||||
public static String handle(Throwable throwable){
|
||||
public static String handle(Throwable throwable) {
|
||||
try {
|
||||
if (throwable instanceof HttpException){
|
||||
if (throwable instanceof HttpException) {
|
||||
retrofit2.Response<?> response = ((HttpException) throwable).response();
|
||||
if (response.errorBody() == null){
|
||||
if (response.errorBody() == null) {
|
||||
return throwable.getMessage();
|
||||
}
|
||||
byte[] bodyByte = response.errorBody().bytes();
|
||||
if (bodyByte.length <= 0){
|
||||
if (bodyByte.length <= 0) {
|
||||
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();
|
||||
}else {
|
||||
} else {
|
||||
return throwable.getMessage();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
Reference in New Issue
Block a user