Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
YDL-Component-Medical
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨凯
YDL-Component-Medical
Commits
c277bcf1
Commit
c277bcf1
authored
Jan 13, 2022
by
刘鹏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat : 一键登录非key部分提交
parent
cf4c9be1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
190 additions
and
13 deletions
+190
-13
OneKeyLoginHelp.kt
m-user/src/main/java/com/yidianling/user/ui/login/OneKeyLoginHelp.kt
+48
-11
RegisterAndLoginActivity.kt
m-user/src/main/java/com/yidianling/user/ui/login/RegisterAndLoginActivity.kt
+113
-2
ILoginContract.kt
m-user/src/main/java/com/yidianling/user/ui/login/contract/ILoginContract.kt
+29
-0
No files found.
m-user/src/main/java/com/yidianling/user/ui/login/OneKeyLoginHelp.kt
View file @
c277bcf1
package
com.yidianling.user.ui.login
import
android.Manifest
import
android.annotation.SuppressLint
import
android.app.Activity
import
android.content.Context
...
...
@@ -18,6 +19,7 @@ import com.fm.openinstall.model.AppData
import
com.meituan.android.walle.WalleChannelReader
import
com.mobile.auth.gatewayauth.*
import
com.mobile.auth.gatewayauth.model.TokenRet
import
com.tbruyelle.rxpermissions2.RxPermissions
import
com.ydl.ydlcommon.base.BaseActivity
import
com.ydl.ydlcommon.base.BaseApp
import
com.ydl.ydlcommon.utils.JPushUtils
...
...
@@ -132,7 +134,11 @@ object OneKeyLoginHelp {
*/
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 {
@Deprecated
(
"mActivity有销毁的可能"
)
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 {
setAuthListener
()
}
// 打开页面
if
(
isOpenDialog
)
{
if
(
false
)
{
openDialog
(
it
)
}
else
{
openPage
(
it
)
...
...
@@ -553,9 +568,13 @@ object OneKeyLoginHelp {
* */
fun
startLoginByStatus
(
context
:
Context
,
isOpenDialog
:
Boolean
):
Boolean
{
if
(!
UserHelper
.
isLogin
())
{
//如果mActivity未初始化,使用正常登录
RegisterAndLoginActivity
.
start
(
context
)
if
(
this
::
mActivity
.
isInitialized
)
{
//如果mActivity有初始化,代表项目使用了一键登录
startLogin
(
context
as
Activity
,
isOpenDialog
)
}
else
{
//如果mActivity未初始化,使用正常登录
RegisterAndLoginActivity
.
start
(
context
)
}
}
return
UserHelper
.
isLogin
()
}
...
...
@@ -566,11 +585,29 @@ object OneKeyLoginHelp {
@SuppressLint
(
"CheckResult"
)
fun
startLogin
(
context
:
Activity
,
isOpenDialog
:
Boolean
)
{
RegisterAndLoginActivity
.
start
(
context
,
isFromOneKey
=
false
,
isFromGuide
=
true
)
try
{
RxPermissions
(
context
)
.
request
(
Manifest
.
permission
.
READ_PHONE_STATE
)
.
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
()
}
}
}
m-user/src/main/java/com/yidianling/user/ui/login/RegisterAndLoginActivity.kt
View file @
c277bcf1
...
...
@@ -13,19 +13,29 @@ import android.view.animation.AnimationUtils
import
androidx.core.content.ContextCompat
import
com.alibaba.android.arouter.facade.annotation.Route
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.ydl.ydlcommon.base.BaseApp
import
com.ydl.ydlcommon.base.BaseMvpActivity
import
com.ydl.ydlcommon.base.config.HttpConfig
import
com.ydl.ydlcommon.data.PlatformRamImpl
import
com.ydl.ydlcommon.utils.ActivityManager
import
com.ydl.ydlcommon.utils.JPushUtils
import
com.ydl.ydlcommon.utils.StatusBarUtils
import
com.ydl.ydlcommon.utils.YDLCacheUtils
import
com.ydl.ydlcommon.view.dialog.CommonDialog
import
com.yidianling.common.tools.LogUtil
import
com.yidianling.common.tools.RxAppTool
import
com.yidianling.common.tools.RxKeyboardTool
import
com.yidianling.common.tools.ToastUtil
import
com.yidianling.user.LoginUtils
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.route.UserIn
import
com.yidianling.user.ui.CountryListActivity
...
...
@@ -45,15 +55,19 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont
ILoginContract
.
View
{
private
var
userPhoneNumber
:
String
?
=
null
// 是否支持号码认证
private
var
isCanAuth
:
Boolean
=
false
private
var
chcekPhoneResponeBean
:
ChcekPhoneResponeBean
?
=
null
// 手机号校验结果
private
var
countryCode
:
String
?
=
"0086"
//国家或地区手机区号
private
var
handler
:
Handler
?
=
null
private
var
isFromGuide
=
false
//是否来自启动页
private
var
isFromOneKeyLogin
=
false
// 是否来自一键登录界面
companion
object
{
private
var
IS_FROM_GUIDE
=
"isFromGuide"
//是否来自启动页
private
var
IS_FROM_ONE_KEY_LOGIN
=
"isFromOneKeyLogin"
//是否来自启动页
var
REQUEST_CODE_COUNTRY
=
1024
fun
start
(
context
:
Context
)
{
start
(
context
,
false
)
...
...
@@ -75,6 +89,8 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont
fun
start
(
context
:
Context
,
isFromOneKey
:
Boolean
,
isFromGuide
:
Boolean
)
{
val
intent
=
Intent
(
context
,
RegisterAndLoginActivity
::
class
.
java
)
intent
.
putExtra
(
IS_FROM_GUIDE
,
isFromGuide
)
intent
.
putExtra
(
IS_FROM_ONE_KEY_LOGIN
,
isFromOneKey
)
context
.
startActivity
(
intent
)
}
...
...
@@ -102,8 +118,10 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont
override
fun
initDataAndEvent
()
{
isFromGuide
=
intent
.
getBooleanExtra
(
IS_FROM_GUIDE
,
false
)
isFromOneKeyLogin
=
intent
.
getBooleanExtra
(
IS_FROM_ONE_KEY_LOGIN
,
false
)
setWindowStatusBarColor
()
initAuthHelper
()
initView
()
setClickEvent
()
}
...
...
@@ -112,7 +130,35 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont
StatusBarUtils
.
Companion
.
setWindowStatusBarColor
(
this
,
R
.
color
.
white
)
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
()
{
val
str
=
"壹点灵用户使用协议、隐私保护政策"
...
...
@@ -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
)
{
...
...
@@ -440,7 +536,22 @@ class RegisterAndLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginCont
ActivityManager
.
finishOtherActivity
(
this
)
UserIn
.
mainIntent
(
this
,
2
)
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
()
}
}
...
...
m-user/src/main/java/com/yidianling/user/ui/login/contract/ILoginContract.kt
View file @
c277bcf1
...
...
@@ -4,8 +4,12 @@ import com.ydl.ydlcommon.data.http.BaseResponse
import
com.ydl.ydlcommon.mvp.base.IModel
import
com.ydl.ydlcommon.mvp.base.IPresenter
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.CheckAliAuthParam
import
com.yidianling.user.http.request.PhoneLoginAutoParam
import
com.yidianling.user.http.response.ChcekPhoneResponeBean
import
com.yidianling.user.http.response.PhoneAuthResponseBean
import
io.reactivex.Observable
/**
...
...
@@ -63,6 +67,21 @@ interface ILoginContract {
* 校验手机号:是否是用户版号码、是否有设置密码、是否被绑定
*/
fun
checkPhoneStatus
(
phone
:
String
,
countryCode
:
String
,
isBind
:
Boolean
,
gatewayUrl
:
String
)
/**
* 服务端阿里认证失败
*/
fun
aliAuthFailed
()
/**
* 服务端校验阿里一键认证
*/
fun
checkAliAuth
(
param
:
CheckAliAuthParam
)
/**
* 通过一键认证服务登陆
*/
fun
autoLogin
(
bean
:
PhoneLoginAutoParam
)
}
interface
Model
:
IModel
{
...
...
@@ -72,5 +91,15 @@ interface ILoginContract {
*/
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
>>
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment