Commit c277bcf1 by 刘鹏

feat : 一键登录非key部分提交

parent cf4c9be1
package com.yidianling.user.ui.login package com.yidianling.user.ui.login
import android.Manifest
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
...@@ -18,6 +19,7 @@ import com.fm.openinstall.model.AppData ...@@ -18,6 +19,7 @@ import com.fm.openinstall.model.AppData
import com.meituan.android.walle.WalleChannelReader import com.meituan.android.walle.WalleChannelReader
import com.mobile.auth.gatewayauth.* import com.mobile.auth.gatewayauth.*
import com.mobile.auth.gatewayauth.model.TokenRet import com.mobile.auth.gatewayauth.model.TokenRet
import com.tbruyelle.rxpermissions2.RxPermissions
import com.ydl.ydlcommon.base.BaseActivity import com.ydl.ydlcommon.base.BaseActivity
import com.ydl.ydlcommon.base.BaseApp import com.ydl.ydlcommon.base.BaseApp
import com.ydl.ydlcommon.utils.JPushUtils import com.ydl.ydlcommon.utils.JPushUtils
...@@ -132,7 +134,11 @@ object OneKeyLoginHelp { ...@@ -132,7 +134,11 @@ object OneKeyLoginHelp {
*/ */
private fun toLoginActivity() { private fun toLoginActivity() {
RegisterAndLoginActivity.start(mActivity, false, mIsFromGuide) if (mOpenPageIsSuccess) {
RegisterAndLoginActivity.start(mActivity, isFromOneKey = true, isFromGuide = false)
} else {
RegisterAndLoginActivity.start(mActivity, false, mIsFromGuide)
}
} }
/** /**
...@@ -142,7 +148,16 @@ object OneKeyLoginHelp { ...@@ -142,7 +148,16 @@ object OneKeyLoginHelp {
@Deprecated("mActivity有销毁的可能") @Deprecated("mActivity有销毁的可能")
fun toLoginActivity(isOpenDialog: Boolean) { fun toLoginActivity(isOpenDialog: Boolean) {
RegisterAndLoginActivity.start(mActivity, isFromOneKey = false, isFromGuide = true) if (mIsOpenOneKeyLogin) {
getLoginToken(false)
} else {
// 一键登录页面打开成功
if (mOpenPageIsSuccess) {
RegisterAndLoginActivity.start(mActivity)
} else {
RegisterAndLoginActivity.start(mActivity, isFromOneKey = false, isFromGuide = true)
}
}
} }
/** /**
...@@ -181,7 +196,7 @@ object OneKeyLoginHelp { ...@@ -181,7 +196,7 @@ object OneKeyLoginHelp {
setAuthListener() setAuthListener()
} }
// 打开页面 // 打开页面
if (isOpenDialog) { if (false) {
openDialog(it) openDialog(it)
} else { } else {
openPage(it) openPage(it)
...@@ -553,9 +568,13 @@ object OneKeyLoginHelp { ...@@ -553,9 +568,13 @@ object OneKeyLoginHelp {
* */ * */
fun startLoginByStatus(context: Context, isOpenDialog: Boolean): Boolean { fun startLoginByStatus(context: Context, isOpenDialog: Boolean): Boolean {
if (!UserHelper.isLogin()) { if (!UserHelper.isLogin()) {
if (this::mActivity.isInitialized) {
//如果mActivity未初始化,使用正常登录 //如果mActivity有初始化,代表项目使用了一键登录
RegisterAndLoginActivity.start(context) startLogin(context as Activity, isOpenDialog)
} else {
//如果mActivity未初始化,使用正常登录
RegisterAndLoginActivity.start(context)
}
} }
return UserHelper.isLogin() return UserHelper.isLogin()
} }
...@@ -566,11 +585,29 @@ object OneKeyLoginHelp { ...@@ -566,11 +585,29 @@ object OneKeyLoginHelp {
@SuppressLint("CheckResult") @SuppressLint("CheckResult")
fun startLogin(context: Activity, isOpenDialog: Boolean) { fun startLogin(context: Activity, isOpenDialog: Boolean) {
RegisterAndLoginActivity.start( try {
context, RxPermissions(context)
isFromOneKey = false, .request(Manifest.permission.READ_PHONE_STATE)
isFromGuide = true .subscribe { hasPermission: Boolean? ->
) if (hasPermission == true && mIsOpenOneKeyLogin) {
getLoginToken(isOpenDialog)
} else {
// 一键登录页面打开成功
if (mOpenPageIsSuccess) {
RegisterAndLoginActivity.start(context)
} else {
RegisterAndLoginActivity.start(
context,
isFromOneKey = false,
isFromGuide = true
)
}
}
}
} catch (e: Exception) {
RegisterAndLoginActivity.start(context)
e.printStackTrace()
}
} }
} }
...@@ -13,19 +13,29 @@ import android.view.animation.AnimationUtils ...@@ -13,19 +13,29 @@ import android.view.animation.AnimationUtils
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.alibaba.android.arouter.facade.annotation.Route import com.alibaba.android.arouter.facade.annotation.Route
import com.meituan.android.walle.WalleChannelReader import com.meituan.android.walle.WalleChannelReader
import com.mobile.auth.gatewayauth.PhoneNumberAuthHelper
import com.mobile.auth.gatewayauth.PhoneNumberAuthHelper.*
import com.mobile.auth.gatewayauth.ResultCode
import com.mobile.auth.gatewayauth.model.TokenRet
import com.umeng.socialize.UMShareAPI import com.umeng.socialize.UMShareAPI
import com.ydl.ydlcommon.base.BaseApp
import com.ydl.ydlcommon.base.BaseMvpActivity import com.ydl.ydlcommon.base.BaseMvpActivity
import com.ydl.ydlcommon.base.config.HttpConfig import com.ydl.ydlcommon.base.config.HttpConfig
import com.ydl.ydlcommon.data.PlatformRamImpl import com.ydl.ydlcommon.data.PlatformRamImpl
import com.ydl.ydlcommon.utils.ActivityManager import com.ydl.ydlcommon.utils.ActivityManager
import com.ydl.ydlcommon.utils.JPushUtils
import com.ydl.ydlcommon.utils.StatusBarUtils import com.ydl.ydlcommon.utils.StatusBarUtils
import com.ydl.ydlcommon.utils.YDLCacheUtils import com.ydl.ydlcommon.utils.YDLCacheUtils
import com.ydl.ydlcommon.view.dialog.CommonDialog import com.ydl.ydlcommon.view.dialog.CommonDialog
import com.yidianling.common.tools.LogUtil import com.yidianling.common.tools.LogUtil
import com.yidianling.common.tools.RxAppTool
import com.yidianling.common.tools.RxKeyboardTool import com.yidianling.common.tools.RxKeyboardTool
import com.yidianling.common.tools.ToastUtil import com.yidianling.common.tools.ToastUtil
import com.yidianling.user.LoginUtils import com.yidianling.user.LoginUtils
import com.yidianling.user.R import com.yidianling.user.R
import com.yidianling.user.UserHelper.isLogin
import com.yidianling.user.http.LoginApiRequestUtil.Companion.autoLogin
import com.yidianling.user.http.request.PhoneLoginAutoParam
import com.yidianling.user.http.response.ChcekPhoneResponeBean import com.yidianling.user.http.response.ChcekPhoneResponeBean
import com.yidianling.user.route.UserIn import com.yidianling.user.route.UserIn
import com.yidianling.user.ui.CountryListActivity import com.yidianling.user.ui.CountryListActivity
...@@ -45,15 +55,19 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont ...@@ -45,15 +55,19 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont
ILoginContract.View { ILoginContract.View {
private var userPhoneNumber: String? = null private var userPhoneNumber: String? = null
// 是否支持号码认证
private var isCanAuth: Boolean = false
private var chcekPhoneResponeBean: ChcekPhoneResponeBean? = null // 手机号校验结果 private var chcekPhoneResponeBean: ChcekPhoneResponeBean? = null // 手机号校验结果
private var countryCode: String? = "0086"//国家或地区手机区号 private var countryCode: String? = "0086"//国家或地区手机区号
private var handler: Handler? = null private var handler: Handler? = null
private var isFromGuide = false//是否来自启动页 private var isFromGuide = false//是否来自启动页
private var isFromOneKeyLogin = false // 是否来自一键登录界面
companion object { companion object {
private var IS_FROM_GUIDE = "isFromGuide"//是否来自启动页 private var IS_FROM_GUIDE = "isFromGuide"//是否来自启动页
private var IS_FROM_ONE_KEY_LOGIN = "isFromOneKeyLogin"//是否来自启动页
var REQUEST_CODE_COUNTRY = 1024 var REQUEST_CODE_COUNTRY = 1024
fun start(context: Context) { fun start(context: Context) {
start(context, false) start(context, false)
...@@ -75,6 +89,8 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont ...@@ -75,6 +89,8 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont
fun start(context: Context, isFromOneKey: Boolean, isFromGuide: Boolean) { fun start(context: Context, isFromOneKey: Boolean, isFromGuide: Boolean) {
val intent = Intent(context, RegisterAndLoginActivity::class.java) val intent = Intent(context, RegisterAndLoginActivity::class.java)
intent.putExtra(IS_FROM_GUIDE, isFromGuide) intent.putExtra(IS_FROM_GUIDE, isFromGuide)
intent.putExtra(IS_FROM_ONE_KEY_LOGIN, isFromOneKey)
context.startActivity(intent) context.startActivity(intent)
} }
...@@ -102,8 +118,10 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont ...@@ -102,8 +118,10 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont
override fun initDataAndEvent() { override fun initDataAndEvent() {
isFromGuide = intent.getBooleanExtra(IS_FROM_GUIDE, false) isFromGuide = intent.getBooleanExtra(IS_FROM_GUIDE, false)
isFromOneKeyLogin = intent.getBooleanExtra(IS_FROM_ONE_KEY_LOGIN, false)
setWindowStatusBarColor() setWindowStatusBarColor()
initAuthHelper()
initView() initView()
setClickEvent() setClickEvent()
} }
...@@ -112,7 +130,35 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont ...@@ -112,7 +130,35 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont
StatusBarUtils.Companion.setWindowStatusBarColor(this, R.color.white) StatusBarUtils.Companion.setWindowStatusBarColor(this, R.color.white)
StatusBarUtils.Companion.setStatusBarLightMode(this, true) StatusBarUtils.Companion.setStatusBarLightMode(this, true)
} }
private fun initAuthHelper() {
// requestPermission()
OneKeyLoginHelp.checkEnvAvailable(SERVICE_TYPE_AUTH)
OneKeyLoginHelp.setVerifyTokenResultListener(object :
OneKeyLoginHelp.VerifyTokenResultListener {
override fun onTokenSuccess(result: String) {
val tokenRet = TokenRet.fromJson(result)
when (tokenRet.code) {
ResultCode.CODE_ERROR_ENV_CHECK_SUCCESS -> { // 终端环境支持认证
isCanAuth = true
}
ResultCode.CODE_SUCCESS -> { // 获取token成功
autoLogin(tokenRet.token)
OneKeyLoginHelp.mPhoneNumberAuthHelper?.setAuthListener(null)
OneKeyLoginHelp.mIsGetTokenSuccess = false
}
}
}
override fun onTokenFailed(result: TokenRet) {
if (isCanAuth) {
//验证失败跳转到验证码/密码界面
aliAuthFailed()
}
}
})
}
private fun initView() { private fun initView() {
val str = "壹点灵用户使用协议、隐私保护政策" val str = "壹点灵用户使用协议、隐私保护政策"
...@@ -403,8 +449,58 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont ...@@ -403,8 +449,58 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont
} }
} }
/**
* 服务端校验阿里一键认证认证失败
*
* 成功的回调 :
* @see getAuthToken
*
* 失败的回调 :
* @see aliAuthFailed
*/
override fun aliAuthFailed() {
//验证失败跳转到验证码/密码界面
RxKeyboardTool.hideSoftInput(this)
runOnUiThread {
showLoading(false)
}
if (chcekPhoneResponeBean != null && chcekPhoneResponeBean?.hasPwd == 1) {//用户码有设置密码:跳转到密登录
ToastUtil.toastShort("跳转到密登录")
InputPassWordActivity.start(
this,
userPhoneNumber!!,
countryCode!!,
InputPassWordActivity.STATUS_INPUT_PWD
)
} else {//否则跳转验证码页面
ToastUtil.toastShort("跳转验证码页面")
if (!TextUtils.isEmpty(userPhoneNumber) && !TextUtils.isEmpty(countryCode)) {
VerificationCodeActivity.start(
this,
userPhoneNumber!!,
countryCode!!,
VerificationCodeActivity.STATUS_LOGIN_BY_CODE,
isBindPhone = false,
hasPassword = false
)
}
}
}
/** /**
* 通过阿里sdk一键认证服务登陆
*/
private fun autoLogin(token: String) {
val param = PhoneLoginAutoParam(
token, JPushUtils.getRegistrationID(), 2, 1, userPhoneNumber!!,
RxAppTool.getAppVersionName(BaseApp.Companion.getApp())
)
mPresenter.autoLogin(param)
}
/**
*菊花框 *菊花框
*/ */
override fun showLoading(state: Boolean) { override fun showLoading(state: Boolean) {
...@@ -440,7 +536,22 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont ...@@ -440,7 +536,22 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont
ActivityManager.finishOtherActivity(this) ActivityManager.finishOtherActivity(this)
UserIn.mainIntent(this, 2) UserIn.mainIntent(this, 2)
finish() finish()
} else { }else if (isFromOneKeyLogin) { // 来自一键登录界面
// 如果已经登录
if (isLogin()) {
OneKeyLoginHelp.quitLoginPage()
if (OneKeyLoginHelp.mIsFromGuide) {
ActivityManager.finishOtherActivity(this)
UserIn.mainIntent(this, 4)
finish()
} else {
super.onBackPressed()
}
} else {
OneKeyLoginHelp.checkEnvAvailable(PhoneNumberAuthHelper.SERVICE_TYPE_LOGIN)
super.onBackPressed()
}
} else {
super.onBackPressed() super.onBackPressed()
} }
} }
......
...@@ -4,8 +4,12 @@ import com.ydl.ydlcommon.data.http.BaseResponse ...@@ -4,8 +4,12 @@ import com.ydl.ydlcommon.data.http.BaseResponse
import com.ydl.ydlcommon.mvp.base.IModel import com.ydl.ydlcommon.mvp.base.IModel
import com.ydl.ydlcommon.mvp.base.IPresenter import com.ydl.ydlcommon.mvp.base.IPresenter
import com.ydl.ydlcommon.mvp.base.IView import com.ydl.ydlcommon.mvp.base.IView
import com.yidianling.user.api.bean.UserResponseBean
import com.yidianling.user.http.request.BindPhoneJavaParam import com.yidianling.user.http.request.BindPhoneJavaParam
import com.yidianling.user.http.request.CheckAliAuthParam
import com.yidianling.user.http.request.PhoneLoginAutoParam
import com.yidianling.user.http.response.ChcekPhoneResponeBean import com.yidianling.user.http.response.ChcekPhoneResponeBean
import com.yidianling.user.http.response.PhoneAuthResponseBean
import io.reactivex.Observable import io.reactivex.Observable
/** /**
...@@ -63,6 +67,21 @@ interface ILoginContract { ...@@ -63,6 +67,21 @@ interface ILoginContract {
* 校验手机号:是否是用户版号码、是否有设置密码、是否被绑定 * 校验手机号:是否是用户版号码、是否有设置密码、是否被绑定
*/ */
fun checkPhoneStatus(phone: String, countryCode: String, isBind: Boolean,gatewayUrl :String) fun checkPhoneStatus(phone: String, countryCode: String, isBind: Boolean,gatewayUrl :String)
/**
* 服务端阿里认证失败
*/
fun aliAuthFailed()
/**
* 服务端校验阿里一键认证
*/
fun checkAliAuth(param: CheckAliAuthParam)
/**
* 通过一键认证服务登陆
*/
fun autoLogin(bean: PhoneLoginAutoParam)
} }
interface Model : IModel { interface Model : IModel {
...@@ -72,5 +91,15 @@ interface ILoginContract { ...@@ -72,5 +91,15 @@ interface ILoginContract {
*/ */
fun checkPhoneStatus(phone: String, countryCode: String,gatewayUrl :String): Observable<BaseResponse<ChcekPhoneResponeBean>> fun checkPhoneStatus(phone: String, countryCode: String,gatewayUrl :String): Observable<BaseResponse<ChcekPhoneResponeBean>>
/**
* 服务端校验阿里一键认证
*/
fun checkAliAuth(param: CheckAliAuthParam): Observable<BaseResponse<PhoneAuthResponseBean>>
/**
* 通过一键认证服务登陆
*/
fun autoLogin(bean: PhoneLoginAutoParam): Observable<BaseResponse<UserResponseBean>>
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment