[Modify]修復測試提的bug

This commit is contained in:
wushaocheng
2023-08-16 23:57:28 +08:00
parent c36f127bce
commit 8c47c3e717
37 changed files with 284 additions and 323 deletions

View File

@@ -56,11 +56,11 @@ import com.yizhuan.xchat_android_library.utils.constant.PackageNameConstants;
import com.yizhuan.xchat_android_library.utils.json.JsonUtils;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.List;
import cn.sharesdk.facebook.Facebook;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
@@ -220,13 +220,13 @@ public class AuthModel extends BaseModel implements IAuthModel {
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));
})
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));
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.flatMap((Function<String, SingleSource<String>>) s -> {
@@ -253,62 +253,62 @@ public class AuthModel extends BaseModel implements IAuthModel {
@Override
public Single<String> login(String phoneAreaCode, String account, String password, String code, String yiDunToken, String shuMeiDeviceId) {
return Single.create((SingleOnSubscribe<String>) emitter -> {
//获取登录信息
try {
LoginResult loginResult = api.login(
phoneAreaCode,
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()));
//获取登录信息
try {
LoginResult loginResult = api.login(
phoneAreaCode,
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(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(ResUtil.getString(R.string.xchat_android_core_auth_authmodel_02));
})
} catch (Exception e) {
emitter.onError(new Throwable(OldHttpErrorHandleUtil.handle(e)));
return;
}
emitter.onSuccess(ResUtil.getString(R.string.xchat_android_core_auth_authmodel_02));
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.flatMap(new Function<String, SingleSource<String>>() {
@@ -332,51 +332,26 @@ public class AuthModel extends BaseModel implements IAuthModel {
* @return
*/
@Override
public Single<String> facebookLogin() {
return Single.create((SingleOnSubscribe<Platform>) e -> {
facebook = ShareSDK.getPlatform(Facebook.NAME);
//是否安装客户端
if (!DeviceUtils.isAppInstalled(getContext(), PackageNameConstants.FACEBOOK_NAME)) {
e.onError(new Throwable(ResUtil.getString(R.string.xchat_android_core_auth_authmodel_03)));
return;
}
if (facebook.isAuthValid()) {
facebook.removeAccount(true);
}
facebook.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(platform.getDb().getUserGender() + "----openid" + openid + "unionid" + unionid + platform.getDb().getUserIcon());
thirdUserInfo = new ThirdUserInfo();
thirdUserInfo.setType(ThirdUserInfo.TYPE_FACEBOOK);
thirdUserInfo.setPlatform("Facebook");
thirdUserInfo.setUserName(platform.getDb().getUserName());
thirdUserInfo.setUserGender(platform.getDb().getUserGender());
thirdUserInfo.setUserIcon(platform.getDb().getUserIcon());
e.onSuccess(platform);
}
}
public Single<String> facebookLogin(JSONObject object) {
return Single.create((SingleOnSubscribe<JSONObject>) e -> {
String name = object.optString("name");
String gender = object.optString("gender"); //性别
//获取用户头像
JSONObject object_pic = object.optJSONObject("picture");
JSONObject object_data = object_pic.optJSONObject("data");
String photo = object_data.optString("url");
@Override
public void onError(Platform platform, int i, Throwable throwable) {
e.onError(new Throwable(ResUtil.getString(R.string.xchat_android_core_auth_authmodel_04) + i));
throwable.printStackTrace();
}
@Override
public void onCancel(Platform platform, int i) {
e.onError(new Throwable(ResUtil.getString(R.string.xchat_android_core_auth_authmodel_05)));
}
});
facebook.SSOSetting(false);
facebook.showUser(null);
thirdUserInfo = new ThirdUserInfo();
thirdUserInfo.setType(ThirdUserInfo.TYPE_FACEBOOK);
thirdUserInfo.setPlatform("Facebook");
thirdUserInfo.setUserName(name);
thirdUserInfo.setUserGender(gender);
thirdUserInfo.setUserIcon(photo);
e.onSuccess(object);
})
.flatMap(platform -> {
String openid = platform.getDb().getUserId();
String unionid = platform.getDb().getUserId();
String openid = platform.optString("id");
String unionid = platform.optString("id");
String avatar = thirdUserInfo.getUserIcon();
if (avatar != null && avatar.equals("null")) {
avatar = null;

View File

@@ -1,8 +1,11 @@
package com.yizhuan.xchat_android_core.auth;
import com.facebook.CallbackManager;
import com.yizhuan.xchat_android_core.auth.entity.ThirdUserInfo;
import com.yizhuan.xchat_android_core.base.IModel;
import org.json.JSONObject;
import io.reactivex.Single;
public interface IAuthModel extends IModel {
@@ -57,7 +60,7 @@ public interface IAuthModel extends IModel {
*/
Single<String> login(String phoneAreaCode, String account, String password, String code, String yiDunToken, String shuMeiDeviceId);
Single<String> facebookLogin();
Single<String> facebookLogin(JSONObject object);
Single<String> lineLogin();

View File

@@ -201,7 +201,7 @@
<string name="xchat_android_core_auth_authmodel_032">IM登錄成功</string>
<string name="xchat_android_core_auth_authmodel_033">IM登錄成功</string>
<string name="xchat_android_core_auth_authmodel_034">失敗錯誤碼:</string>
<string name="xchat_android_core_auth_authmodel_035">IM登錄失敗錯誤碼</string>
<string name="xchat_android_core_auth_authmodel_035">網絡異常,請切換網絡后重試</string>
<string name="xchat_android_core_auth_authmodel_036">IM登錄失敗異常信息</string>
<string name="auth_exception_oldmemberexception_01">不存在對應賬號</string>
<string name="xchat_android_core_base_basemodel_01">未知錯誤!</string>