664 lines
25 KiB
Java
664 lines
25 KiB
Java
package com.qxcm.qxlive;
|
||
|
||
import static android.view.View.VISIBLE;
|
||
|
||
import android.content.Intent;
|
||
import android.graphics.Color;
|
||
import android.os.Build;
|
||
import android.os.Bundle;
|
||
import android.os.CountDownTimer;
|
||
import android.text.Editable;
|
||
import android.text.TextUtils;
|
||
import android.text.TextWatcher;
|
||
import android.text.method.PasswordTransformationMethod;
|
||
import android.view.Gravity;
|
||
import android.view.View;
|
||
import android.widget.ImageView;
|
||
|
||
import androidx.annotation.Nullable;
|
||
|
||
import com.alibaba.fastjson.JSON;
|
||
import com.alipay.sdk.app.AuthTask;
|
||
import com.blankj.utilcode.util.LogUtils;
|
||
import com.blankj.utilcode.util.ThreadUtils;
|
||
import com.hjq.toast.ToastUtils;
|
||
import com.mobile.auth.gatewayauth.AuthUIConfig;
|
||
import com.mobile.auth.gatewayauth.PhoneNumberAuthHelper;
|
||
import com.mobile.auth.gatewayauth.PreLoginResultListener;
|
||
import com.mobile.auth.gatewayauth.TokenResultListener;
|
||
import com.mobile.auth.gatewayauth.model.TokenRet;
|
||
import com.qxcm.qxlive.databinding.ActivityPasswordLoginBinding;
|
||
import com.xscm.modulelogin.activity.ImproveInfoActivity;
|
||
import com.xscm.modulelogin.even.LoginFinishEvent;
|
||
import com.xscm.modulelogin.present.LoginContacter;
|
||
import com.xscm.modulelogin.present.LoginPresenter;
|
||
import com.xscm.modulemain.activity.MainActivity;
|
||
import com.xscm.moduleutil.activity.BaseMvpActivity;
|
||
import com.xscm.moduleutil.base.CommonAppContext;
|
||
import com.xscm.moduleutil.bean.ThemeBean;
|
||
import com.xscm.moduleutil.bean.UserBean;
|
||
import com.xscm.moduleutil.utils.BarUtils;
|
||
import com.xscm.moduleutil.utils.PreferencesUtils;
|
||
import com.xscm.moduleutil.utils.logger.Logger;
|
||
import com.tencent.mm.opensdk.modelbase.BaseResp;
|
||
import com.tencent.mm.opensdk.modelmsg.SendAuth;
|
||
import com.tencent.mm.opensdk.openapi.IWXAPI;
|
||
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
||
|
||
import org.greenrobot.eventbus.EventBus;
|
||
import org.greenrobot.eventbus.Subscribe;
|
||
import org.greenrobot.eventbus.ThreadMode;
|
||
|
||
import java.util.Map;
|
||
import java.util.regex.Matcher;
|
||
import java.util.regex.Pattern;
|
||
|
||
public class PasswordLoginActivity extends BaseMvpActivity<LoginPresenter, ActivityPasswordLoginBinding> implements LoginContacter.View, View.OnClickListener {
|
||
|
||
private CountDownTimer mTimer;
|
||
public String mobile;
|
||
private int type;//1:验证码登录2:密码登录
|
||
boolean isPasswordVisible = false;
|
||
public PhoneNumberAuthHelper phoneNumberAuthHelper;
|
||
private TokenResultListener tokenResultListener;
|
||
private boolean canOnePass;
|
||
|
||
@Override
|
||
protected void initData() {
|
||
|
||
}
|
||
|
||
@Override
|
||
protected int getLayoutId() {
|
||
return R.layout.activity_password_login;
|
||
}
|
||
|
||
@Override
|
||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||
// 检查是否已经创建过该Activity
|
||
if (!isTaskRoot()) {
|
||
Intent intent = getIntent();
|
||
if (intent != null) {
|
||
String action = intent.getAction();
|
||
// 如果是从Launcher启动的,并且Activity已经存在,则finish当前实例
|
||
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(action)) {
|
||
finish();
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
// 新增版本检查逻辑
|
||
checkAppVersion();
|
||
super.onCreate(savedInstanceState);
|
||
// EventBus.getDefault().register(this);
|
||
// AppLogUtil.reportAppLog(AppLogEvent.A0101);
|
||
}
|
||
|
||
private void checkAppVersion() {
|
||
// 获取当前版本号
|
||
int currentVersionCode = 0;
|
||
try {
|
||
currentVersionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
|
||
// 从SharedPreferences中获取上次运行的版本号
|
||
int lastVersionCode = PreferencesUtils.getInt(CommonAppContext.getInstance(), "last_version_code", 0);
|
||
|
||
// 如果版本号不同,说明应用已更新
|
||
if (currentVersionCode != lastVersionCode) {
|
||
// 保存当前版本号
|
||
PreferencesUtils.putInt(CommonAppContext.getInstance(), "last_version_code", currentVersionCode);
|
||
|
||
// 如果不是首次安装,则需要清理任务栈
|
||
if (lastVersionCode != 0) {
|
||
clearTaskAndRestart();
|
||
}
|
||
}
|
||
}
|
||
|
||
private void clearTaskAndRestart() {
|
||
// 清理所有Activity并重启应用
|
||
Intent intent = new Intent(this, PasswordLoginActivity.class);
|
||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||
startActivity(intent);
|
||
finish();
|
||
}
|
||
|
||
@Override
|
||
protected void onDestroy() {
|
||
EventBus.getDefault().unregister(this);
|
||
if (phoneNumberAuthHelper != null) {
|
||
phoneNumberAuthHelper.hideLoginLoading();
|
||
//获取成功 dimiss就去登录、登录成功
|
||
phoneNumberAuthHelper.quitLoginPage();
|
||
}
|
||
super.onDestroy();
|
||
}
|
||
|
||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||
public void finishEvent(LoginFinishEvent event) {
|
||
finish();
|
||
}
|
||
|
||
|
||
@Override
|
||
protected void initView() {
|
||
super.initView();
|
||
MvpPre.getThemeData();
|
||
initQuickLogin();
|
||
checkOnePass();
|
||
|
||
BarUtils.setStatusBarAlpha(this, 0);
|
||
mBinding.edPhone.addTextChangedListener(new TextWatcher() {
|
||
@Override
|
||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||
setUpLoginBtn();
|
||
}
|
||
|
||
@Override
|
||
public void afterTextChanged(Editable s) {
|
||
|
||
}
|
||
});
|
||
mBinding.edPhone.setOnFocusChangeListener(new View.
|
||
OnFocusChangeListener() {
|
||
@Override
|
||
public void onFocusChange(View v, boolean hasFocus) {
|
||
if (mBinding.edPhone == null) {
|
||
return;
|
||
}
|
||
if (hasFocus) {
|
||
mBinding.relPhone.setSelected(true);
|
||
} else {
|
||
// 此处为失去焦点时的处理内容
|
||
mBinding.relPhone.setSelected(false);
|
||
}
|
||
}
|
||
});
|
||
mBinding.edPhone.setText(PreferencesUtils.getString(CommonAppContext.getInstance(), "mobile"));
|
||
if (!TextUtils.isEmpty(mobile)) {
|
||
mBinding.edPhone.setText(mobile);
|
||
}
|
||
mBinding.tvCodeText.setOnClickListener(this::onClick);
|
||
mBinding.flLogin.setOnClickListener(this::onClick);
|
||
mBinding.tvYhxy.setOnClickListener(this::onClick);
|
||
mBinding.tvYsxy.setOnClickListener(this::onClick);
|
||
mBinding.ivZfb.setOnClickListener(this::onClick);
|
||
mBinding.ivWeixin.setOnClickListener(this::onClick);
|
||
mBinding.tvSendCode.setOnClickListener(this::onClick);
|
||
mBinding.ivEye.setOnClickListener(this::onClick);
|
||
|
||
if (mBinding.tvCodeText.getText().equals("切换密码登录")) {
|
||
type = 1;
|
||
} else {
|
||
type = 2;
|
||
}
|
||
|
||
}
|
||
|
||
private void initQuickLogin() {
|
||
tokenResultListener = new TokenResultListener() {
|
||
@Override
|
||
public void onTokenSuccess(String s) {
|
||
Logger.e("onTokenSuccess", s);
|
||
ThreadUtils.runOnUiThread(new Runnable() {
|
||
@Override
|
||
public void run() {
|
||
TokenRet tokenRet = null;
|
||
try {
|
||
tokenRet = JSON.parseObject(s, TokenRet.class);
|
||
if (tokenRet != null && ("600000").equals(tokenRet.getCode())) {
|
||
|
||
LogUtils.e("@@@", tokenRet.getToken());
|
||
MvpPre.oauthLoginLogin(tokenRet.getToken());
|
||
// phoneNumberAuthHelper.hideLoginLoading();
|
||
// //获取成功 dimiss就去登录、登录成功
|
||
// phoneNumberAuthHelper.quitLoginPage();
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
@Override
|
||
public void onTokenFailed(String s) {
|
||
Logger.e("onTokenFailed", s);
|
||
ThreadUtils.runOnUiThread(new Runnable() {
|
||
@Override
|
||
public void run() {
|
||
phoneNumberAuthHelper.hideLoginLoading();
|
||
phoneNumberAuthHelper.quitLoginPage();
|
||
}
|
||
});
|
||
}
|
||
};
|
||
|
||
try {
|
||
phoneNumberAuthHelper = PhoneNumberAuthHelper.getInstance(getApplicationContext(), null);
|
||
phoneNumberAuthHelper.getReporter().setLoggerEnable(true);
|
||
// phoneNumberAuthHelper.setAuthSDKInfo("6rdWuz058oq5OahdbFiGEybUcdahd12J83L34Uc7MrPIrxtFG+rXiwDvRcqNvjwbClbbmvMrmxKVkIysFByBsl0Qe9kqd2w8T/nhK5G6eXXlk2V9AjYCieIU+jRnjZBB+Cfechr6rCGJ2aeBARIsXcRPW7wm9WFK9euh5T+v6Pyte68yNaNdcYCll3+U4/uCEog7HygCnMIbAU+kqoPdmn2H+51YOHW+VsnsHd4w1+I3f8Tt0xLIXGM4GWnQueZ5GR46GTWiSYMy8dCIh9SPIMRyC91GosVcfGPMJSdcXqc=");
|
||
phoneNumberAuthHelper.setAuthSDKInfo(((CommonAppContext) getApplication()).getCurrentEnvironment().getALI_AUTH_KEY());
|
||
phoneNumberAuthHelper.checkEnvAvailable(2);
|
||
|
||
} catch (Throwable ignored) {
|
||
Logger.e("initAuthSDK", ignored);
|
||
}
|
||
}
|
||
|
||
|
||
private void checkOnePass() {
|
||
if (!TextUtils.isEmpty(CommonAppContext.getInstance().getToken()) && !TextUtils.isEmpty(CommonAppContext.getInstance().getUser().getTencent_im())) {
|
||
isRoot();
|
||
return;
|
||
}
|
||
showLoadings();
|
||
if (phoneNumberAuthHelper != null) {
|
||
phoneNumberAuthHelper.accelerateLoginPage(3 * 1000, new PreLoginResultListener() {
|
||
@Override
|
||
public void onTokenSuccess(String s) {
|
||
Logger.e("onTokenSuccess", s);
|
||
canOnePass = true;
|
||
isRoot();
|
||
}
|
||
|
||
@Override
|
||
public void onTokenFailed(String s, String s1) {
|
||
Logger.e("onTokenFailed", "错误信息" + s, s1);
|
||
isRoot();
|
||
}
|
||
});
|
||
} else {
|
||
canOnePass = false;
|
||
isRoot();
|
||
}
|
||
}
|
||
|
||
private void isRoot() {
|
||
runOnUiThread(new Runnable() {
|
||
@Override
|
||
public void run() {
|
||
disLoadings();
|
||
if (!PasswordLoginActivity.this.isTaskRoot()) {
|
||
Intent intent = getIntent();
|
||
if (intent != null) {
|
||
String action = intent.getAction();
|
||
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(action)) {
|
||
finish();
|
||
} else {
|
||
goNextActivity();
|
||
}
|
||
} else {
|
||
goNextActivity();
|
||
}
|
||
} else {
|
||
goNextActivity();
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
private void goNextActivity() {
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||
if (isFinishing() || isDestroyed()) {
|
||
return;
|
||
}
|
||
}
|
||
if (TextUtils.isEmpty(CommonAppContext.getInstance().getToken()) || TextUtils.isEmpty(CommonAppContext.getInstance().getUser().getTencent_im())) {
|
||
Logger.e("SplashEnd", "ARouters.CODE_LOGIN");
|
||
if (canOnePass) {
|
||
phoneNumberAuthHelper.setAuthListener(tokenResultListener);
|
||
doOnePass();
|
||
} else {
|
||
|
||
}
|
||
} else {
|
||
Logger.e("SplashEnd", "ARouters.MAIN");
|
||
|
||
UserBean userBean = CommonAppContext.getInstance().getUser();
|
||
|
||
// TUILogin.login(getBaseContext(), CommonAppContext.getInstance().getCurrentEnvironment().getSdkAppId(), "u"+userBean.getUser_id(), userBean.getTencent_im(), new TUICallback() {
|
||
// @Override
|
||
// public void onError(final int code, final String desc) {
|
||
// LogUtils.e("@@@",code,"描述:",desc);
|
||
// }
|
||
// @Override
|
||
// public void onSuccess() {
|
||
// LogUtils.e("@@@","成功");
|
||
//
|
||
// }
|
||
// });
|
||
if (userBean.getSex() == 0) {
|
||
Intent intent = new Intent(this, ImproveInfoActivity.class);
|
||
Bundle bundle = new Bundle();
|
||
bundle.putSerializable("userBean", userBean);
|
||
intent.putExtras(bundle);
|
||
startActivity(intent);
|
||
finish();
|
||
} else {
|
||
EventBus.getDefault().post(userBean);
|
||
startActivity(new Intent(this, MainActivity.class));
|
||
finish();
|
||
}
|
||
// finish();
|
||
}
|
||
}
|
||
|
||
private void doOnePass() {
|
||
AuthUIConfig authUIConfig = new AuthUIConfig.Builder()
|
||
//导航栏
|
||
.setNavColor(Color.TRANSPARENT)
|
||
.setNavReturnHidden(true)
|
||
.setNavHidden(true)
|
||
.setNavText("")
|
||
.setNavTextColor(Color.BLACK)
|
||
.setWebNavColor(Color.TRANSPARENT)
|
||
.setWebNavTextColor(Color.BLACK)
|
||
.setWebNavReturnImgPath("ic_topbar_back_dark")
|
||
//状态栏区
|
||
.setStatusBarColor(Color.TRANSPARENT)
|
||
.setLightColor(false)
|
||
.setWebViewStatusBarColor(Color.TRANSPARENT)
|
||
.setStatusBarUIFlag(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
|
||
//logo区
|
||
.setLogoImgPath("login_log")
|
||
.setLogoWidth(142)
|
||
.setLogoHeight(142)
|
||
.setLogoOffsetY(54)
|
||
.setLogoHidden(false)
|
||
.setLogoScaleType(ImageView.ScaleType.FIT_XY)
|
||
//Slogan
|
||
.setSloganText("本机号码")
|
||
.setSloganTextColor(Color.parseColor("#A8A8A8"))
|
||
.setSloganTextSize(12)
|
||
.setSloganOffsetY(236)
|
||
//掩码栏
|
||
.setNumberColor(Color.BLACK)
|
||
.setNumberSize(30)
|
||
.setNumFieldOffsetY(263)
|
||
.setNumberLayoutGravity(Gravity.CENTER_HORIZONTAL)
|
||
//登录按钮
|
||
.setLogBtnText("一键登录")
|
||
.setLogBtnWidth(300)
|
||
.setLogBtnHeight(42)
|
||
.setLogBtnOffsetY(325)
|
||
.setLogBtnTextSize(14)
|
||
.setLogBtnTextColor(getResources().getColor(R.color.white))
|
||
// .setLogBtnBackgroundPath("theme_bg")
|
||
.setLogBtnBackgroundDrawable(getResources().getDrawable(com.xscm.moduleutil.R.mipmap.login_btn_bg))
|
||
//切换到其他方式
|
||
.setSwitchAccText("其他登录方式")
|
||
.setSwitchAccTextColor(Color.parseColor("#333333"))
|
||
.setSwitchAccTextSize(12)
|
||
.setSwitchOffsetY(390)
|
||
//协议栏
|
||
.setAppPrivacyOne("《用户协议》", CommonAppContext.getInstance().getCurrentEnvironment().getServerUrl() + "/api/Page/page_show?id=6")
|
||
.setAppPrivacyTwo("《隐私协议》", CommonAppContext.getInstance().getCurrentEnvironment().getServerUrl() + "/api/Page/page_show?id=4")
|
||
.setAppPrivacyColor(Color.parseColor("#000000"), Color.parseColor("#22BB79"))
|
||
.setPrivacyBefore("登录即代表同意")
|
||
.setPrivacyEnd("并授权获得号码")
|
||
.setPrivacyTextSize(11)
|
||
.setPrivacyAlertContentVerticalMargin(20)
|
||
.setPrivacyMargin(39)
|
||
.setPrivacyState(false)
|
||
.setCheckboxHidden(false)
|
||
.setCheckedImgPath("ic_agreement_selected")
|
||
.setUncheckedImgPath("ic_agreement_unselect")
|
||
.setPrivacyOffsetX(2)
|
||
.setVendorPrivacyPrefix("《")
|
||
.setVendorPrivacySuffix("》")
|
||
.setProtocolAction("com.qxcm.qxlive.PROTOCOL_WEBVIEW")//跳转到自定义的页面展示隐私协议
|
||
.setPackageName("com.qxcm.qxlive")
|
||
//全页面属性
|
||
.setAuthPageActIn("in_activity", "out_activity")
|
||
.setAuthPageActOut("in_activity", "out_activity")
|
||
// .setPageBackgroundPath("log_bj")
|
||
.setPageBackgroundDrawable(getResources().getDrawable(com.xscm.moduleutil.R.mipmap.log_bj))
|
||
.create();
|
||
phoneNumberAuthHelper.setAuthUIConfig(authUIConfig);
|
||
phoneNumberAuthHelper.getLoginToken(getApplicationContext(), 5000);
|
||
}
|
||
|
||
@Override
|
||
protected LoginPresenter bindPresenter() {
|
||
return new LoginPresenter(this, this);
|
||
}
|
||
|
||
|
||
@Override
|
||
public void showLoadings() {
|
||
showLoading();
|
||
}
|
||
|
||
@Override
|
||
public void disLoadings() {
|
||
disLoading();
|
||
}
|
||
|
||
private void setUpLoginBtn() {
|
||
String text = mBinding.edPhone.getText().toString();
|
||
if (text.length() == 11) {
|
||
mBinding.flLogin.setEnabled(true);
|
||
mBinding.ivLoginBg.setAlpha(1f);
|
||
} else {
|
||
mBinding.ivLoginBg.setAlpha(0.3f);
|
||
mBinding.flLogin.setEnabled(false);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void onClick(View v) {
|
||
int id = v.getId();
|
||
if (id == R.id.tv_code_text) {
|
||
// Intent intent = new Intent(this, LoginActivity.class);
|
||
// intent.putExtra("mobile", mBinding.edPhone.getText().toString());
|
||
// startActivity(intent);
|
||
// finish();
|
||
|
||
if (mBinding.tvCodeText.getText().equals("切换密码登录")) {
|
||
mBinding.rlPassCode.setVisibility(VISIBLE);
|
||
mBinding.rlCode.setVisibility(View.GONE);
|
||
mBinding.tvCodeText.setText("切换验证码登录");
|
||
mBinding.tvLoginText.setText("密码登录");
|
||
type = 2;
|
||
} else {
|
||
mBinding.rlPassCode.setVisibility(View.GONE);
|
||
mBinding.rlCode.setVisibility(VISIBLE);
|
||
mBinding.tvCodeText.setText("切换密码登录");
|
||
mBinding.tvLoginText.setText("验证码登录");
|
||
type = 1;
|
||
}
|
||
|
||
|
||
} else if (id == R.id.fl_login) {
|
||
if (!mBinding.cbPrivacy.isChecked()) {
|
||
ToastUtils.show("请先勾选服务条款");
|
||
return;
|
||
}
|
||
String phone = mBinding.edPhone.getText().toString().trim();
|
||
if (TextUtils.isEmpty(phone)) {
|
||
ToastUtils.show("请输入手机号");
|
||
return;
|
||
}
|
||
if (type == 1) {
|
||
String code = mBinding.edPassword.getText().toString().trim();
|
||
if (TextUtils.isEmpty(code)) {
|
||
ToastUtils.show("请输入验证码");
|
||
return;
|
||
}
|
||
MvpPre.login(phone, "", code, 1);
|
||
} else if (type == 2) {
|
||
String password = mBinding.edPasswordCode.getText().toString().trim();
|
||
if (TextUtils.isEmpty(password)) {
|
||
ToastUtils.show("请输入密码");
|
||
return;
|
||
}
|
||
MvpPre.login(phone, password, "", 2);
|
||
}
|
||
|
||
} else if (id == R.id.tv_yhxy) {
|
||
MvpPre.ysxl();
|
||
} else if (id == R.id.tv_ysxy) {
|
||
MvpPre.yhxy();
|
||
} else if (id == R.id.iv_zfb) {
|
||
if (!mBinding.cbPrivacy.isChecked()) {
|
||
ToastUtils.show("请先勾选服务条款");
|
||
return;
|
||
}
|
||
MvpPre.authorization("zfb");
|
||
// MvpPre.authorization(SHARE_MEDIA.QQ);
|
||
} else if (id == R.id.iv_weixin) {
|
||
if (!mBinding.cbPrivacy.isChecked()) {
|
||
ToastUtils.show("请先勾选服务条款");
|
||
return;
|
||
}
|
||
// MvpPre.authorization("wx");
|
||
wcLogin();
|
||
} else if (id == R.id.tv_send_code) {
|
||
String phone = mBinding.edPhone.getText().toString().trim();
|
||
if (TextUtils.isEmpty(phone)) {
|
||
ToastUtils.show("请输入手机号");
|
||
return;
|
||
}
|
||
sendCodeSuccess(phone);
|
||
MvpPre.sendCode(phone, 1);
|
||
} else if (id == R.id.iv_eye) {
|
||
|
||
if (!isPasswordVisible) {
|
||
mBinding.edPassword.setInputType(android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
|
||
mBinding.ivEye.setImageResource(com.xscm.moduleutil.R.mipmap.eye_visible); // 设置按钮文本为隐藏密码
|
||
} else {
|
||
mBinding.edPassword.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||
mBinding.edPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
|
||
mBinding.ivEye.setImageResource(com.xscm.moduleutil.R.mipmap.eye_close); // 设置按钮文本为显示密码
|
||
}
|
||
mBinding.edPassword.setSelection(mBinding.edPassword.getText().length()); // 将光标移动到文字末尾
|
||
isPasswordVisible = !isPasswordVisible; // 切换状态
|
||
}
|
||
}
|
||
|
||
private void wcLogin() {
|
||
//发起登陆请求前先注册微信api
|
||
IWXAPI api = WXAPIFactory.createWXAPI(this, CommonAppContext.getInstance().getCurrentEnvironment().getWxAppId(), true);
|
||
api.registerApp(CommonAppContext.getInstance().getCurrentEnvironment().getWxAppId());
|
||
if (!api.isWXAppInstalled()) {
|
||
//todo 提醒未安装微信
|
||
com.blankj.utilcode.util.ToastUtils.showShort("请安装微信客户端");
|
||
return;
|
||
}
|
||
//开始发起登陆请求
|
||
final SendAuth.Req req = new SendAuth.Req();
|
||
req.scope = "snsapi_userinfo";
|
||
req.state = "wechat_sdk_demo_test";
|
||
api.sendReq(req);
|
||
}
|
||
|
||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||
public void loginEvent(BaseResp event) {
|
||
if (event.errCode == BaseResp.ErrCode.ERR_OK) {
|
||
SendAuth.Resp authResp = (SendAuth.Resp) event;
|
||
LogUtils.e("@@@", authResp.code);
|
||
MvpPre.oauthLogin(authResp.code, 1);
|
||
}
|
||
}
|
||
|
||
private void releaseTimer() {
|
||
if (mTimer != null) {
|
||
mTimer.cancel();
|
||
mTimer = null;
|
||
}
|
||
}
|
||
|
||
public void sendCodeSuccess(String phoneNumber) {
|
||
com.blankj.utilcode.util.ToastUtils.showShort("短信验证码发送成功请注意查收");
|
||
mBinding.tvSendCode.setEnabled(false);
|
||
mBinding.tvSendCode.setAlpha(0.5f);
|
||
releaseTimer();
|
||
if (mTimer != null) {
|
||
mTimer.cancel();
|
||
}
|
||
mTimer = new CountDownTimer(60000L, 1000L) {
|
||
@Override
|
||
public void onTick(long millisUntilFinished) {
|
||
if (mBinding.tvSendCode != null) {
|
||
mBinding.tvSendCode.setText(String.format("重新发送(%s)", millisUntilFinished / 1000));
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void onFinish() {
|
||
mBinding.tvSendCode.setAlpha(1f);
|
||
mBinding.tvSendCode.setEnabled(true);
|
||
mBinding.tvSendCode.setText("重新发送");
|
||
}
|
||
};
|
||
mTimer.start();
|
||
}
|
||
|
||
@Override
|
||
public void sendCodeSuccess1(String s) {
|
||
LogUtils.e(s);
|
||
}
|
||
|
||
@Override
|
||
public void loginSuccess(UserBean userBean) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void authorizationSuccess(String s) {
|
||
zfbLogin(s);
|
||
}
|
||
|
||
@Override
|
||
public void ysxlSuccess(String s) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void getThemeData(ThemeBean themeBean) {
|
||
|
||
}
|
||
|
||
private void zfbLogin(String s) {
|
||
LogUtils.e("@@@", s);
|
||
CommonAppContext.getInstance();
|
||
if (!CommonAppContext.isAlipayInstalled(this)) {
|
||
com.blankj.utilcode.util.ToastUtils.showShort("请安装支付宝客户端");
|
||
return;
|
||
}
|
||
String authInfo = s;
|
||
// String authInfo = "apiname=com.alipay.account.auth&app_id=2021005152631691&app_name=yusheng&auth_type=AUTHACCOUNT&biz_type=openservice&method=alipay.open.auth.sdk.code.get&pid=2088170624624316&product_id=APP_FAST_LOGIN&scope=kuaijie&sign_type=RSA2&target_id=20141225xxxx&sign=fMcp4GtiM6rxSIeFnJCVePJKV43eXrUP86CQgiLhDHH2u%2FdN75eEvmywc2ulkm7qKRetkU9fbVZtJIqFdMJcJ9Yp%2BJI%2FF%2FpESafFR6rB2fRjiQQLGXvxmDGVMjPSxHxVtIqpZy5FDoKUSjQ2%2FILDKpu3%2F%2BtAtm2jRw1rUoMhgt0%3D";
|
||
Runnable authRunnable = new Runnable() {
|
||
|
||
@Override
|
||
public void run() {
|
||
// 构造AuthTask 对象
|
||
AuthTask authTask = new AuthTask(PasswordLoginActivity.this);
|
||
// 调用授权接口,获取授权结果
|
||
Map<String, String> result = authTask.authV2(authInfo, true);
|
||
LogUtils.e(result);
|
||
if (result.get("resultStatus").equals("9000")) {
|
||
Pattern pattern = Pattern.compile("auth_code=([^&]*)");
|
||
Matcher matcher = pattern.matcher(result.get("result"));
|
||
|
||
if (matcher.find()) {
|
||
String authCode = matcher.group(1);
|
||
LogUtils.e("AuthCode", authCode);
|
||
MvpPre.oauthLogin(authCode, 2);
|
||
}
|
||
}
|
||
}
|
||
};
|
||
Thread authThread = new Thread(authRunnable);
|
||
authThread.start();
|
||
}
|
||
} |