1、修改登录功能并验证,除了支付宝登录其他都已验证
2、完成个人中心的功能,个人主页完成、钱包完成、背包完成
This commit is contained in:
@@ -1,104 +1,214 @@
|
||||
package com.qxcm.modulelogin.present;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alipay.sdk.app.AuthTask;
|
||||
import com.blankj.utilcode.util.AppUtils;
|
||||
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;
|
||||
import com.qxcm.moduleutil.activity.IPresenter;
|
||||
import com.qxcm.moduleutil.base.CommonAppContext;
|
||||
import com.qxcm.moduleutil.bean.UserBean;
|
||||
import com.qxcm.moduleutil.http.BaseObserver;
|
||||
import com.qxcm.moduleutil.presenter.BasePresenter;
|
||||
import com.qxcm.moduleutil.utils.PreferencesUtils;
|
||||
import com.tencent.mm.opensdk.modelmsg.SendAuth;
|
||||
import com.tencent.mm.opensdk.openapi.IWXAPI;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class LoginPresenter extends BasePresenter<LoginContacter.View> implements LoginContacter.ILoginPre {
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
public class LoginPresenter extends BasePresenter<LoginContacter.View> implements LoginContacter.ILoginPre {
|
||||
public LoginPresenter(LoginContacter.View view, Context context) {
|
||||
super(view, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendCode(String phoneNumber, int type) {
|
||||
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+"");
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @param mobile 手机号
|
||||
* @param password 密码
|
||||
* @param code 验证码
|
||||
* @param type 1:手机号登录 2:密码登录
|
||||
*/
|
||||
@Override
|
||||
public void login(String mobile, String password, String code, int type) {
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(List<UserBean> userBeans) {
|
||||
loginSuccess(userBeans);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付宝登录
|
||||
* @param auth_code
|
||||
* @param type type=1:微信登录;type=2:支付宝登录
|
||||
*/
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void thirdPartyLogin(String oldOpenId, String openId, int three_party, String nickname, String head_pic) {
|
||||
public void switchAccounts(String loginId) {
|
||||
api.switchAccounts(loginId, new BaseObserver<List<UserBean>>() {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
addDisposable(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void oauthLogin(String netease_token, String access_token, int type) {
|
||||
@Override
|
||||
public void onNext(List<UserBean> userBeans) {
|
||||
loginSuccess(userBeans);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
|
||||
}
|
||||
public void authorization() {
|
||||
// if (share_media.getName().equals(SHARE_MEDIA.QQ.getName())) {
|
||||
// AppLogUtil.reportAppLog(AppLogEvent.A010304_qq, "be_null", "be_null");
|
||||
// if (!AppUtils.isAppInstalled("com.tencent.mobileqq")) {
|
||||
// ToastUtils.showShort("请安装QQ客户端");
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// if (share_media.getName().equals(SHARE_MEDIA.WEIXIN.getName())) {
|
||||
// AppLogUtil.reportAppLog(AppLogEvent.A010304_wx, "be_null", "be_null");
|
||||
// if (!AppUtils.isAppInstalled("com.tencent.mm")) {
|
||||
// ToastUtils.showShort("请安装微信客户端");
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// UMShareAPI.get(MvpRef.get().getSelfActivity()).getPlatformInfo(MvpRef.get().getSelfActivity(), share_media, new UMAuthListener() {
|
||||
// @Override
|
||||
// public void onStart(SHARE_MEDIA share_media) {
|
||||
// Log.d(TAG, "onStart " + "授权开始");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
|
||||
// Log.d(TAG, "onComplete " + "授权完成");
|
||||
//
|
||||
// //sdk是6.4.4的,但是获取值的时候用的是6.2以前的(access_token)才能获取到值,未知原因
|
||||
// String uid = map.get("uid");
|
||||
// String openid = map.get("openid");//微博没有
|
||||
// String unionid = map.get("unionid");//微博没有
|
||||
// String access_token = map.get("access_token");
|
||||
// String refresh_token = map.get("refresh_token");//微信,qq,微博都没有获取到
|
||||
// String expires_in = map.get("expires_in");
|
||||
// String name = map.get("name");
|
||||
// String gender = map.get("gender");
|
||||
// String iconurl = map.get("iconurl");
|
||||
//
|
||||
// if (isViewAttach() && MvpRef.get().getSelfActivity() != null) {
|
||||
// MvpRef.get().getSelfActivity().runOnUiThread(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// if (share_media.getName().equals(SHARE_MEDIA.QQ.getName())) {
|
||||
// thirdPartyLogin(uid, openid, 2, name, iconurl);
|
||||
// } else {
|
||||
// thirdPartyLogin(uid, openid, 1, name, iconurl);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {
|
||||
// Log.d(TAG, "onError " + "授权失败");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onCancel(SHARE_MEDIA share_media, int i) {
|
||||
// Log.d(TAG, "onCancel " + "授权取消");
|
||||
// }
|
||||
// });
|
||||
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 {
|
||||
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, 并保证其唯一性 !
|
||||
}
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void ysxl() {
|
||||
// ARouter.getInstance().build(ARouters.H5).withString("url", Constant.URL.URL_USER_YSXY).withString("title", "隐私协议").navigation();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user