2025-05-15 11:08:23 +08:00
|
|
|
|
package com.qxcm.modulelogin.present;
|
|
|
|
|
|
|
2025-05-22 19:03:01 +08:00
|
|
|
|
import android.app.Activity;
|
2025-05-15 11:08:23 +08:00
|
|
|
|
import android.content.Context;
|
2025-05-22 19:03:01 +08:00
|
|
|
|
import android.content.Intent;
|
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
|
import android.text.TextUtils;
|
2025-05-15 11:08:23 +08:00
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
2025-05-22 19:03:01 +08:00
|
|
|
|
import com.alipay.sdk.app.AuthTask;
|
2025-05-15 11:08:23 +08:00
|
|
|
|
import com.blankj.utilcode.util.AppUtils;
|
2025-05-22 19:03:01 +08:00
|
|
|
|
import com.blankj.utilcode.util.LogUtils;
|
|
|
|
|
|
import com.blankj.utilcode.util.ToastUtils;
|
|
|
|
|
|
import com.qxcm.modulelogin.activity.ImproveInfoActivity;
|
|
|
|
|
|
import com.qxcm.modulelogin.activity.LoginActivity;
|
|
|
|
|
|
import com.qxcm.modulelogin.activity.SwitchAccountsActivity;
|
|
|
|
|
|
import com.qxcm.modulemain.activity.MainActivity;
|
2025-05-15 11:08:23 +08:00
|
|
|
|
import com.qxcm.moduleutil.activity.IPresenter;
|
2025-05-22 19:03:01 +08:00
|
|
|
|
import com.qxcm.moduleutil.base.CommonAppContext;
|
|
|
|
|
|
import com.qxcm.moduleutil.bean.UserBean;
|
|
|
|
|
|
import com.qxcm.moduleutil.http.BaseObserver;
|
2025-05-15 11:08:23 +08:00
|
|
|
|
import com.qxcm.moduleutil.presenter.BasePresenter;
|
2025-05-22 19:03:01 +08:00
|
|
|
|
import com.qxcm.moduleutil.utils.PreferencesUtils;
|
|
|
|
|
|
import com.tencent.mm.opensdk.modelmsg.SendAuth;
|
|
|
|
|
|
import com.tencent.mm.opensdk.openapi.IWXAPI;
|
2025-05-15 11:08:23 +08:00
|
|
|
|
|
2025-05-22 19:03:01 +08:00
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
2025-05-15 11:08:23 +08:00
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
2025-05-22 19:03:01 +08:00
|
|
|
|
import io.reactivex.disposables.Disposable;
|
|
|
|
|
|
|
|
|
|
|
|
public class LoginPresenter extends BasePresenter<LoginContacter.View> implements LoginContacter.ILoginPre {
|
2025-05-15 11:08:23 +08:00
|
|
|
|
public LoginPresenter(LoginContacter.View view, Context context) {
|
|
|
|
|
|
super(view, context);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void sendCode(String phoneNumber, int type) {
|
2025-05-22 19:03:01 +08:00
|
|
|
|
api.sendCode(phoneNumber,"default", new BaseObserver<Object>() {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onSubscribe(Disposable d) {
|
|
|
|
|
|
addDisposable(d);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onNext(Object o) {
|
|
|
|
|
|
MvpRef.get().sendCodeSuccess1(o+"");
|
|
|
|
|
|
}
|
2025-05-15 11:08:23 +08:00
|
|
|
|
|
2025-05-22 19:03:01 +08:00
|
|
|
|
|
|
|
|
|
|
});
|
2025-05-15 11:08:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-22 19:03:01 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 登录
|
|
|
|
|
|
* @param mobile 手机号
|
|
|
|
|
|
* @param password 密码
|
|
|
|
|
|
* @param code 验证码
|
|
|
|
|
|
* @param type 1:手机号登录 2:密码登录
|
|
|
|
|
|
*/
|
2025-05-15 11:08:23 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public void login(String mobile, String password, String code, int type) {
|
2025-05-22 19:03:01 +08:00
|
|
|
|
if (type==1){
|
|
|
|
|
|
api.login(mobile, code, new BaseObserver<List<UserBean>>() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onSubscribe(Disposable d) {
|
|
|
|
|
|
addDisposable(d);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onNext(List<UserBean> userBeans) {
|
|
|
|
|
|
loginSuccess(userBeans);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
}else if (type==2){
|
|
|
|
|
|
api.userLogin(mobile,password, new BaseObserver<List<UserBean>>(){
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onSubscribe(Disposable d) {
|
|
|
|
|
|
addDisposable(d);
|
|
|
|
|
|
}
|
2025-05-15 11:08:23 +08:00
|
|
|
|
|
2025-05-22 19:03:01 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public void onNext(List<UserBean> userBeans) {
|
|
|
|
|
|
loginSuccess(userBeans);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-05-15 11:08:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-22 19:03:01 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 支付宝登录
|
|
|
|
|
|
* @param auth_code
|
|
|
|
|
|
* @param type type=1:微信登录;type=2:支付宝登录
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2025-05-15 11:08:23 +08:00
|
|
|
|
@Override
|
2025-05-22 19:03:01 +08:00
|
|
|
|
public void oauthLogin(String auth_code, int type) {
|
|
|
|
|
|
api.authCode(auth_code,type, new BaseObserver<List<UserBean>>() {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onSubscribe(Disposable d) {
|
|
|
|
|
|
addDisposable(d);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onNext(List<UserBean> userBeans) {
|
|
|
|
|
|
loginSuccess(userBeans);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-05-15 11:08:23 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2025-05-22 19:03:01 +08:00
|
|
|
|
public void switchAccounts(String loginId) {
|
|
|
|
|
|
api.switchAccounts(loginId, new BaseObserver<List<UserBean>>() {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onSubscribe(Disposable d) {
|
|
|
|
|
|
addDisposable(d);
|
|
|
|
|
|
}
|
2025-05-15 11:08:23 +08:00
|
|
|
|
|
2025-05-22 19:03:01 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public void onNext(List<UserBean> userBeans) {
|
|
|
|
|
|
loginSuccess(userBeans);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
2025-05-15 11:08:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void detachView() {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-05-22 19:03:01 +08:00
|
|
|
|
public void loginSuccess(List<UserBean> userBean) {
|
|
|
|
|
|
if (userBean==null) {
|
|
|
|
|
|
ToastUtils.showShort("登录失败请重试");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (userBean.size()==1) {
|
|
|
|
|
|
|
|
|
|
|
|
CommonAppContext.getInstance().setUser(userBean.get(0));
|
|
|
|
|
|
|
|
|
|
|
|
// PreferencesUtils.putString( CommonAppContext.getInstance(), "mobile", userBean.get());
|
|
|
|
|
|
|
|
|
|
|
|
if (isViewAttach()) {
|
|
|
|
|
|
// MvpRef.get().disLoadings();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (userBean.get(0).getSex() == 0) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
Intent intent = new Intent(com.blankj.utilcode.util.ActivityUtils.getTopActivity(), ImproveInfoActivity.class);
|
|
|
|
|
|
|
|
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
|
|
bundle.putSerializable("userBean", userBean.get(0));
|
|
|
|
|
|
intent.putExtras(bundle);
|
|
|
|
|
|
com.blankj.utilcode.util.ActivityUtils.startActivity(intent);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2025-05-29 08:59:34 +08:00
|
|
|
|
EventBus.getDefault().post(userBean.get(0));
|
2025-05-22 19:03:01 +08:00
|
|
|
|
com.blankj.utilcode.util.ActivityUtils.startActivity(MainActivity.class);
|
|
|
|
|
|
}
|
|
|
|
|
|
}else {
|
|
|
|
|
|
Intent intent=new Intent(com.blankj.utilcode.util.ActivityUtils.getTopActivity(), SwitchAccountsActivity.class);
|
|
|
|
|
|
Bundle bundle=new Bundle();
|
|
|
|
|
|
bundle.putSerializable("userBean", userBean.get(0));
|
|
|
|
|
|
intent.putExtras(bundle);
|
|
|
|
|
|
com.blankj.utilcode.util.ActivityUtils.startActivity(intent);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
// EventBus.getDefault().post(new LoginFinishEvent());
|
|
|
|
|
|
// EventBus.getDefault().post(new SplashFinishEvent());
|
|
|
|
|
|
// AppLog.setUserUniqueID(userBean.getUser_id()); // 设置您自己的账号体系ID, 并保证其唯一性 !
|
2025-05-15 11:08:23 +08:00
|
|
|
|
}
|
2025-05-22 19:03:01 +08:00
|
|
|
|
public void authorization(String type) {
|
|
|
|
|
|
|
|
|
|
|
|
if (type.equals("wx")) {
|
|
|
|
|
|
if (!AppUtils.isAppInstalled("com.tencent.mm")) {
|
|
|
|
|
|
ToastUtils.showShort("请安装微信客户端");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
// IWXAPI api = WXEntryActivity.getWXAPI();
|
|
|
|
|
|
// final SendAuth.Req req = new SendAuth.Req();
|
|
|
|
|
|
// req.scope = "snsapi_userinfo"; // 只能填 snsapi_userinfo
|
|
|
|
|
|
// req.state = "wechat_sdk_demo_test";
|
|
|
|
|
|
// api.sendReq(req);
|
|
|
|
|
|
}else if (type.equals("zfb")){
|
|
|
|
|
|
// Map<String, String> result = authTask.authV2(authInfo, true);
|
|
|
|
|
|
api.authorization(new BaseObserver<String>() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onSubscribe(Disposable d) {
|
|
|
|
|
|
addDisposable(d);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onNext(String s) {
|
|
|
|
|
|
MvpRef.get().authorizationSuccess(s);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-15 11:08:23 +08:00
|
|
|
|
public void ysxl() {
|
|
|
|
|
|
// ARouter.getInstance().build(ARouters.H5).withString("url", Constant.URL.URL_USER_YSXY).withString("title", "隐私协议").navigation();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void yhxy() {
|
|
|
|
|
|
// ARouter.getInstance().build(ARouters.H5).withString("url", Constant.URL.URL_USER_YHXY).withString("title", "用户协议").navigation();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|