Commit 027b183d by YKai

feat:一键登录代码优化,登录界面号码验证

parent 6ff932cd
......@@ -12,6 +12,7 @@ import android.provider.Settings
import android.util.Log
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.mobile.auth.gatewayauth.PhoneNumberAuthHelper
import com.tbruyelle.rxpermissions2.RxPermissions
import com.umeng.analytics.MobclickAgent
import com.ydl.component.music.FragmentContainerActivity
......@@ -74,7 +75,7 @@ class MainActivity : BaseLceActivity<DemoContract.View, DemoContract.Presenter>(
YdlCommonRouterManager.initYdlCommonRoute(PlatformTempCommonRouteImpl())
// 初始化一键登录sdk
OneKeyLoginHelp.sdkInit(this, OneKeyLoginHelp.YDL_USER_APP, OneKeyLoginHelp.ONE_KEY_LOGIN)
OneKeyLoginHelp.sdkInit(this, OneKeyLoginHelp.YDL_USER_APP, PhoneNumberAuthHelper.SERVICE_TYPE_LOGIN)
bindService()
reLoadData()
......@@ -92,9 +93,6 @@ class MainActivity : BaseLceActivity<DemoContract.View, DemoContract.Presenter>(
// .withBoolean("bind_phone", false)
// .withBoolean("isFromGuide", true)
// .navigation()
if (!OneKeyLoginHelp.mIsGetTokenSuccess) {
OneKeyLoginHelp.setAuthListener()
}
OneKeyLoginHelp.getLoginToken(false)
}
bt_to_consultant.setOnClickListener {
......
......@@ -23,6 +23,9 @@ object UserHelper {
private val user_setting_name_sp = "ydl_user_setting"
private val user_setting_key_sp = "ydl_user_setting_key"
// 存储用户的手机号
public const val USER_PHONE = "user_phone"
//用户信息//缓存
private var userTemp: UserResponseBean? = null
......@@ -35,6 +38,8 @@ object UserHelper {
userTemp = userInfo
var str = gson.toJson(userTemp)
SharedPreferencesEditor.putFileString(user_info_name_sp, user_info_key_sp, str)
// 存储登录所使用的手机号
SharedPreferencesEditor.putString(USER_PHONE,userInfo?.userInfo?.phone)
UserInfoCache.getInstance().saveYDLUser("\"" + userInfo?.uid + "\"",
userInfo?.userInfo?.nick_name, userInfo?.userInfo?.head)
......
......@@ -360,9 +360,6 @@ public class MineFragment extends BaseFragment implements SwipeRefreshLayout.OnR
*/
private void startLogin(){
if (OneKeyLoginHelp.INSTANCE.getMIsOpenOneKeyLogin()) {
if (!OneKeyLoginHelp.INSTANCE.getMIsGetTokenSuccess()) {
OneKeyLoginHelp.INSTANCE.setAuthListener();
}
OneKeyLoginHelp.INSTANCE.getLoginToken(true);
}else {
RegisterAndLoginActivity.Companion.start(getActivity());
......
......@@ -30,14 +30,12 @@ object OneKeyLoginHelp {
"i4Y/PVRAz4P/aqajQF7SOd3JUIKEsJbRurH04azLyX6N2upi292OrLHECRmtTVAqY24HFjwUjW1QjRwJA9aFbNzl3zl7L5DEDBZ4+QSU28vq34HccmAjAeUCC7qCHbN7QLVZqhVpuYUCMZ5fp2NdhANJl/741wHccdPk/Un5c4larDNuv1KEo2OZOds2J1WFiBx7giWtzli4NwMq9x+9sb0aXPZZQ9C9Kr8T/0+/ccYdotwFm7XWenNs/G3Jy1HHVqqOCDecKPbyXR+cV0jBUisSjv+SEUTfpcc3iUGH5OjZyQ6OfaLkdjATsr5K9oVP"
const val YDL_USER_APP = 1
const val YDL_EXPERT_APP = 2
const val PHONE_CHECK = 1 // 本机号码验证
const val ONE_KEY_LOGIN = 2 // 一键登录
var mPhoneNumberAuthHelper: PhoneNumberAuthHelper? = null
private var mAppType: Int = YDL_USER_APP
var mIsGetTokenSuccess = true // 获取token是否成功,默认是成功
var mIsOpenOneKeyLogin = false // 是否开启一键登录
var mIsFromGuide = true
var mAuthType = ONE_KEY_LOGIN // 1:本机号码校验 2: ⼀键登录
var mAuthType = PhoneNumberAuthHelper.SERVICE_TYPE_LOGIN // 1:本机号码校验 2: ⼀键登录
private lateinit var mActivity: BaseActivity
......@@ -55,17 +53,27 @@ object OneKeyLoginHelp {
} else if (appType == YDL_EXPERT_APP) {
it.setAuthSDKInfo(YDL_EXPERT_APP_KEY)
}
// 检查认证环境
// it.checkEnvAvailable(authType) // type 1:本机号码校验 2: ⼀键登录
}
}
/**
* 检查认证环境
*
*/
fun checkEnvAvailable(authType: Int) {
mAuthType = authType
if (!mIsGetTokenSuccess) {
setAuthListener()
}
mPhoneNumberAuthHelper?.checkEnvAvailable(authType) // type 1:本机号码校验 2: ⼀键登录
}
/**
* 设置token监听
*
*/
fun setAuthListener() {
private fun setAuthListener() {
mPhoneNumberAuthHelper?.setAuthListener(mTokenListener)
}
......@@ -86,7 +94,10 @@ object OneKeyLoginHelp {
*
*/
fun getVerifyToken() {
mAuthType = PHONE_CHECK
mAuthType = PhoneNumberAuthHelper.SERVICE_TYPE_AUTH
if (!mIsGetTokenSuccess) {
setAuthListener()
}
mPhoneNumberAuthHelper?.getVerifyToken(5000) // 5000表示超时时间 单位ms
}
......@@ -97,8 +108,11 @@ object OneKeyLoginHelp {
*/
fun getLoginToken(isOpenDialog: Boolean) {
mIsFromGuide = isOpenDialog
mAuthType = ONE_KEY_LOGIN
mAuthType = PhoneNumberAuthHelper.SERVICE_TYPE_LOGIN
mPhoneNumberAuthHelper?.let {
if (!mIsGetTokenSuccess) {
setAuthListener()
}
// 打开页面
if (isOpenDialog) {
openDialog(it)
......@@ -281,28 +295,31 @@ object OneKeyLoginHelp {
// 一键登录token监听器
private var mTokenListener: TokenResultListener = object : TokenResultListener {
override fun onTokenSuccess(s: String) {
val tokenRet = TokenRet.fromJson(s)
when (tokenRet.code) {
ResultCode.CODE_START_AUTHPAGE_SUCCESS -> { // 唤起一键登录页面成功
LogUtil.e("唤起授权页成功:$s")
}
ResultCode.CODE_SUCCESS -> { // 点击登录后获取token成功
val token = tokenRet.token
if (mAuthType == PHONE_CHECK) { // 本机号码校验
verifyTokenResultListener.onTokenSuccess(token)
}else{
// 登录
if (mAuthType == PhoneNumberAuthHelper.SERVICE_TYPE_AUTH) { // 本机号码校验
verifyTokenResultListener.onTokenSuccess(s)
} else {
val tokenRet = TokenRet.fromJson(s)
when (tokenRet.code) {
ResultCode.CODE_START_AUTHPAGE_SUCCESS -> { // 唤起一键登录页面成功
LogUtil.e("唤起授权页成功:$s")
}
ResultCode.CODE_SUCCESS -> { // 获取token成功
val token = tokenRet.token
mPhoneNumberAuthHelper?.setAuthListener(null)
mIsGetTokenSuccess = false
}
mPhoneNumberAuthHelper?.setAuthListener(null)
}
}
}
override fun onTokenFailed(s: String) {
LogUtil.e(s)
mIsGetTokenSuccess = false
val tokenRet = TokenRet.fromJson(s)
if (mAuthType == PHONE_CHECK) { // 本机号码校验
if (mAuthType == PhoneNumberAuthHelper.SERVICE_TYPE_AUTH) { // 本机号码校验
verifyTokenResultListener.onTokenFailed(tokenRet)
} else {
// 一键登录
......@@ -324,7 +341,7 @@ object OneKeyLoginHelp {
private lateinit var verifyTokenResultListener: VerifyTokenResultListener
interface VerifyTokenResultListener {
fun onTokenSuccess(result: String?)
fun onTokenSuccess(result: String)
fun onTokenFailed(result: TokenRet)
}
......
......@@ -62,11 +62,6 @@ interface ILoginContract {
fun checkPhoneStatusSuccess(bean: ChcekPhoneResponeBean?, phone: String)
/**
* 设置阿里一键认证sdk token
*/
fun getAuthToken(configDTOs: List<VendorConfig>)
/**
* 服务端阿里认证失败
*/
fun aliAuthFailed()
......
......@@ -59,7 +59,7 @@ import kotlinx.android.synthetic.main.user_activity_register_and_login.*
* @Company 壹点灵
* @date 2018/11/28
*/
@Route(path = "/user/login")
//@Route(path = "/user/login")
class testLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginContract.Presenter>(),
ILoginContract.View {
......@@ -434,19 +434,6 @@ class testLoginActivity : BaseMvpActivity<ILoginContract.View, ILoginContract.Pr
}
/**
* 服务端校验阿里一键认证成功,设置sdk token
*
* 成功的回调 :
* @see getAuthToken
*
* 失败的回调 :
* @see aliAuthFailed
*/
override fun getAuthToken(configDTOs: List<VendorConfig>) {
// mAlicomAuthHelper!!.getAuthToken(5000)
}
/**
* 服务端校验阿里一键认证认证失败
*
* 成功的回调 :
......
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