完善微信登录不同情况的逻辑
This commit is contained in:
@@ -461,7 +461,7 @@ abstract class BaseActivity<T : ViewBinding>(val inflater: (inflater: LayoutInfl
|
||||
}
|
||||
|
||||
fun showNoCancelableLoading(show: Boolean, message: String = getString(R.string.txt_loading)) {
|
||||
if (!isFrontRunning) {
|
||||
if (!isFrontRunning && show) {
|
||||
return
|
||||
}
|
||||
if (show) {
|
||||
@@ -601,8 +601,11 @@ abstract class BaseActivity<T : ViewBinding>(val inflater: (inflater: LayoutInfl
|
||||
getResultCallback.onRequestError(exceptionCode)
|
||||
return
|
||||
}
|
||||
//处理注册用户已存在的情况
|
||||
else if (exceptionCode == ErrorCode.USER_HAS_EXIST.toString()) {
|
||||
//拦截错误吐司不显示
|
||||
//处理注册用户已存在的情况,微信没有注册用户,微信绑定的手机号没有注册用户
|
||||
else if (exceptionCode == ErrorCode.USER_HAS_EXIST.toString() || exceptionCode == ErrorCode.WX_NO_EXIST.toString() ||
|
||||
exceptionCode == ErrorCode.PHONE_NO_REGISTER.toString()
|
||||
) {
|
||||
getResultCallback.onRequestError(exceptionCode)
|
||||
return
|
||||
} else if (exceptionCode == ErrorCode.DEVICE_HAS_BIND.toString()) {
|
||||
@@ -640,7 +643,7 @@ abstract class BaseActivity<T : ViewBinding>(val inflater: (inflater: LayoutInfl
|
||||
}
|
||||
} else {
|
||||
mNetworkRequestsFailRetryCount = 0
|
||||
if (isShowNoDataTip && data is MutableList<*> && data.size == 0) {
|
||||
if (isShowNoDataTip && data is MutableList<*> && data.isEmpty()) {
|
||||
showToast(R.string.no_data)
|
||||
}
|
||||
//不做强制类型转换
|
||||
|
||||
@@ -13,8 +13,8 @@ import com.abbidot.tracker.constant.ConstantInt
|
||||
import com.abbidot.tracker.constant.GetResultCallback
|
||||
import com.abbidot.tracker.databinding.FragmentForgetPasswordCnStartBinding
|
||||
import com.abbidot.tracker.deprecated.ui.activity.LoginRegisterCNActivity
|
||||
import com.abbidot.tracker.vm.cn.RegisterCNViewModel
|
||||
import com.abbidot.tracker.vm.CountDownTimerViewModel
|
||||
import com.abbidot.tracker.vm.cn.RegisterCNViewModel
|
||||
|
||||
|
||||
/**
|
||||
@@ -109,7 +109,7 @@ class ForgetPasswordCNStartFragment : BaseFragment<FragmentForgetPasswordCnStart
|
||||
}
|
||||
val activity = activity as LoginRegisterCNActivity
|
||||
activity.mPhone = phone
|
||||
mRegisterCNViewModel.validatePhoneCode(this, phone, code, 4)
|
||||
mRegisterCNViewModel.validatePhoneCode(this, phone, code, 4,"")
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -92,7 +92,7 @@ class RegisterCNStartFragment :
|
||||
}
|
||||
|
||||
activity.mPhone = phone
|
||||
mRegisterCNViewModel.validatePhoneCode(this, phone, code, 3)
|
||||
mRegisterCNViewModel.validatePhoneCode(this, phone, code, 3,"")
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1434,8 +1434,10 @@ interface INetworkService {
|
||||
@POST("user/phoneValidateCode")
|
||||
suspend fun validatePhoneCode(
|
||||
@Field("phone") phone: String, @Field("code") code: String,
|
||||
//验证码类型 1是注册 2是忘记密码
|
||||
@Field("type") type: Int
|
||||
//验证码类型 1注册 2忘记密码 3验证码登录 4微信绑定
|
||||
@Field("type") type: Int,
|
||||
//微信标识(type:4的时候,必传)
|
||||
@Field("openidIdentifier") openidIdentifier: String
|
||||
): BaseResponse<UserBean>
|
||||
|
||||
/**
|
||||
|
||||
@@ -1321,8 +1321,8 @@ object NetworkApi : BaseNetworkApi<INetworkService>(INetworkService.BASE_URL) {
|
||||
/**
|
||||
* 手机号验证码验证
|
||||
*/
|
||||
suspend fun validatePhoneCode(phone: String, code: String, type: Int) = getResult {
|
||||
service.validatePhoneCode(phone, code, type)
|
||||
suspend fun validatePhoneCode(phone: String, code: String, type: Int,openidIdentifier: String) = getResult {
|
||||
service.validatePhoneCode(phone, code, type,openidIdentifier)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.abbidot.tracker.util.Util
|
||||
|
||||
class SayHelloActivity : BaseActivity<ActivitySayHelloBinding>(ActivitySayHelloBinding::inflate) {
|
||||
|
||||
private var mWXCode = ""
|
||||
private var mOpenid = ""
|
||||
|
||||
override fun getTopBar() = null
|
||||
|
||||
@@ -47,34 +47,37 @@ class SayHelloActivity : BaseActivity<ActivitySayHelloBinding>(ActivitySayHelloB
|
||||
}
|
||||
|
||||
XEventBus.observe(this, EventName.PostValue) { s: String ->
|
||||
mWXCode = s
|
||||
mOpenid = s
|
||||
}
|
||||
|
||||
//微信登录成功返回
|
||||
XEventBus.observe(this, EventName.WXLoginResult) { it: Result<UserBean> ->
|
||||
dealRequestResult(it, object : GetResultCallback {
|
||||
override fun onResult(any: Any) {
|
||||
showNoCancelableLoading(false)
|
||||
it.getOrNull()?.let { userBean ->
|
||||
Util.dealLoginSuccessData(mContext, userBean)
|
||||
showToast(R.string.txt_login_successful, gravity = Gravity.CENTER)
|
||||
Util.dealLoginSuccessData(mContext, userBean, false)
|
||||
Util.loginSuccessGo(this@SayHelloActivity, mViewBinding.root)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onInterceptCode() {
|
||||
showNoCancelableLoading(false)
|
||||
setButtonEnabled(
|
||||
mViewBinding.btnSayHelloLoginWechat, ConstantInt.Type1
|
||||
)
|
||||
}
|
||||
|
||||
override fun onRequestError(exceptionCode: String?) {
|
||||
showNoCancelableLoading(false)
|
||||
setButtonEnabled(
|
||||
mViewBinding.btnSayHelloLoginWechat, ConstantInt.Type1
|
||||
)
|
||||
exceptionCode?.let { code ->
|
||||
if (code == ErrorCode.USER_NO_EXIST.toString()) {
|
||||
if (code == ErrorCode.WX_NO_EXIST.toString()) {
|
||||
Intent(mContext, WXLoginActivity::class.java).let { i ->
|
||||
i.putExtra(MMKVKey.CountryCode, mWXCode)
|
||||
i.putExtra(MMKVKey.CountryCode, mOpenid)
|
||||
startActivity(i)
|
||||
}
|
||||
}
|
||||
@@ -110,6 +113,7 @@ class SayHelloActivity : BaseActivity<ActivitySayHelloBinding>(ActivitySayHelloB
|
||||
}
|
||||
|
||||
btnSayHelloLoginWechat -> {
|
||||
showNoCancelableLoading(true)
|
||||
setButtonEnabled(
|
||||
mViewBinding.btnSayHelloLoginWechat, ConstantInt.Type0
|
||||
)
|
||||
|
||||
@@ -8,10 +8,11 @@ import com.abbidot.tracker.ui.fragment.account.EmailValidFragment
|
||||
import com.abbidot.tracker.ui.fragment.account.cn.AccountCnPhoneFragment
|
||||
|
||||
class WXLoginActivity : AddEmailValidActivity() {
|
||||
private var mWXCode = ""
|
||||
private var mWXOpenid = ""
|
||||
override fun initData() {
|
||||
mWXCode = intent.getStringExtra(MMKVKey.CountryCode) ?: ""
|
||||
mEmailValidFragment = EmailValidFragment.newInstance(this, ConstantInt.Type4) {
|
||||
mWXOpenid = intent.getStringExtra(MMKVKey.CountryCode) ?: ""
|
||||
mEmailValidFragment =
|
||||
EmailValidFragment.newInstance(this, ConstantInt.Type4, openid = mWXOpenid) {
|
||||
switchFragment(2)
|
||||
}.apply {
|
||||
mFragmentList.add(
|
||||
@@ -22,7 +23,7 @@ class WXLoginActivity : AddEmailValidActivity() {
|
||||
mFragmentList.add(this)
|
||||
mFragmentList.add(
|
||||
CreateAccountV2ThreeFragment.newInstance(
|
||||
this@WXLoginActivity, mWXCode
|
||||
this@WXLoginActivity, mWXOpenid
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -172,7 +172,9 @@ class LiveActivityV3 : BaseActivity<ActivityLiveV3Binding>(ActivityLiveV3Binding
|
||||
Utils.DATE_FORMAT_PATTERN_EN12,
|
||||
isLiveJump
|
||||
) { mapLoadOk() }
|
||||
if (AppUtils.isChina()) BaiduLocationManager.setScanSpan(10)
|
||||
|
||||
if (AppUtils.isChina()) BaiduLocationManager.setScanSpan(15)
|
||||
|
||||
ViewUtil.instance.setMapSwitchLocationButtonImage(
|
||||
ivMapLiveV2RefreshBtn, mShowCenterLocation
|
||||
)
|
||||
|
||||
@@ -44,6 +44,7 @@ open class EmailValidFragment : BaseFragment<FragmentBaseEmailValidBinding>(
|
||||
private var mEmail = ""
|
||||
private var mBtnString = ""
|
||||
private var mVerifyCodeType = 0
|
||||
private var mOpenid = ""
|
||||
|
||||
private var mOnOkClickListener: OnClickListener? = null
|
||||
|
||||
@@ -53,9 +54,11 @@ open class EmailValidFragment : BaseFragment<FragmentBaseEmailValidBinding>(
|
||||
context: Context,
|
||||
verifyCodeType: Int,
|
||||
btnString: String = "",
|
||||
openid: String = "",
|
||||
okClickListener: OnClickListener
|
||||
) = EmailValidFragment().apply {
|
||||
mContext = context
|
||||
mOpenid = openid
|
||||
mBtnString = btnString
|
||||
mVerifyCodeType = verifyCodeType
|
||||
mOnOkClickListener = okClickListener
|
||||
@@ -209,9 +212,9 @@ open class EmailValidFragment : BaseFragment<FragmentBaseEmailValidBinding>(
|
||||
)
|
||||
if (mVerifyCodeType == ConstantInt.Type4) {
|
||||
exceptionCode?.let { code ->
|
||||
if (code == "519") {
|
||||
if (code == ErrorCode.PHONE_NO_REGISTER.toString()) {
|
||||
mOnOkClickListener?.onClick(view)
|
||||
} else if (code == "520") {
|
||||
} else if (code == ErrorCode.PHONE_HAS_BIND.toString()) {
|
||||
showToast(
|
||||
R.string.txt_phone_has_bound, gravity = Gravity.CENTER
|
||||
)
|
||||
@@ -301,15 +304,25 @@ open class EmailValidFragment : BaseFragment<FragmentBaseEmailValidBinding>(
|
||||
|
||||
setButtonEnabled(mViewBinding.btnForgotPasswordV2TwoContinue, ConstantInt.Type0)
|
||||
if (AppUtils.isChina()) {
|
||||
if (mVerifyCodeType == ConstantInt.Type3) {
|
||||
when (mVerifyCodeType) {
|
||||
ConstantInt.Type3 -> {
|
||||
mLoginCNViewModel.phoneLogin(
|
||||
this@EmailValidFragment, mEmail, content
|
||||
)
|
||||
} else {
|
||||
}
|
||||
|
||||
ConstantInt.Type4 -> {
|
||||
mRegisterCNViewModel.validatePhoneCode(
|
||||
this@EmailValidFragment, mEmail, content, mVerifyCodeType
|
||||
this@EmailValidFragment, mEmail, content, mVerifyCodeType, mOpenid
|
||||
)
|
||||
}
|
||||
|
||||
else -> {
|
||||
mRegisterCNViewModel.validatePhoneCode(
|
||||
this@EmailValidFragment, mEmail, content, mVerifyCodeType, ""
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mRegisterViewModel.validateCode(
|
||||
this@EmailValidFragment, mEmail, content, mVerifyCodeType
|
||||
|
||||
@@ -561,10 +561,10 @@ class Util {
|
||||
/**
|
||||
* 处理登录成功后的数据
|
||||
*/
|
||||
fun dealLoginSuccessData(context: Context, userBean: UserBean) {
|
||||
fun dealLoginSuccessData(
|
||||
context: Context, userBean: UserBean, isNotifyFinish: Boolean = true
|
||||
) {
|
||||
LogUtil.e("处理登录成功后的数据:$userBean")
|
||||
//通知相关页面关闭
|
||||
XEventBus.post(EventName.FinishActivity)
|
||||
userBean.apply {
|
||||
MMKVUtil.putString(MMKVKey.UserId, userId)
|
||||
MMKVUtil.putString(MMKVKey.Email, email)
|
||||
@@ -580,6 +580,8 @@ class Util {
|
||||
//极光推送设置别名
|
||||
JPushInterface.setAlias(context, rand.nextInt(1000), userId)
|
||||
}
|
||||
//通知相关页面关闭
|
||||
if (isNotifyFinish) XEventBus.post(EventName.FinishActivity)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,8 @@ import kotlinx.coroutines.launch
|
||||
class RegisterCNViewModel : ViewModel() {
|
||||
val mSendCodeResultLiveData = MutableLiveData<Result<String>>()
|
||||
val mValidateCodeResultLiveData = MutableLiveData<Result<UserBean>>()
|
||||
// val mPhoneRegisterResultLiveData = MutableLiveData<Result<String>>()
|
||||
|
||||
// val mPhoneRegisterResultLiveData = MutableLiveData<Result<String>>()
|
||||
val mSetNewPasswordResultLiveData = MutableLiveData<Result<String>>()
|
||||
|
||||
/**
|
||||
@@ -35,10 +36,12 @@ class RegisterCNViewModel : ViewModel() {
|
||||
/**
|
||||
* 手机号验证码验证
|
||||
*/
|
||||
fun validatePhoneCode(fragment: BaseFragment<*>, phone: String, code: String, type: Int) {
|
||||
fun validatePhoneCode(
|
||||
fragment: BaseFragment<*>, phone: String, code: String, type: Int, openidIdentifier: String
|
||||
) {
|
||||
fragment.showLoading(true)
|
||||
viewModelScope.launch {
|
||||
val result = NetworkApi.validatePhoneCode(phone, code, type)
|
||||
val result = NetworkApi.validatePhoneCode(phone, code, type, openidIdentifier)
|
||||
mValidateCodeResultLiveData.value = result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.abbidot.tracker.wxapi
|
||||
|
||||
import com.abbidot.baselibrary.constant.EventName
|
||||
import com.abbidot.baselibrary.eventbus.XEventBus
|
||||
import com.abbidot.baselibrary.network.exception.ErrorCode
|
||||
import com.abbidot.baselibrary.util.LogUtil
|
||||
import com.abbidot.tracker.vm.cn.LoginCNViewModel
|
||||
import com.hjq.toast.Toaster
|
||||
@@ -22,7 +25,17 @@ class WXEntryActivity : WXBaseActivity() {
|
||||
override fun initData() {
|
||||
mLoginCNViewModel.mWXLoginResultLiveData.observe(this) {
|
||||
LogUtil.e("mWXLoginResultLiveData:$it")
|
||||
// XEventBus.post(EventName.WXLoginResult, it)
|
||||
if (null != it.exceptionOrNull()) {
|
||||
//服务器返回错误信息
|
||||
val exceptionMessage = it.exceptionOrNull()?.message
|
||||
//服务器返回错误code
|
||||
val exceptionCode = it.exceptionOrNull()?.toString()
|
||||
if (exceptionCode == ErrorCode.WX_NO_EXIST.toString()) {
|
||||
//传递openid
|
||||
XEventBus.post(EventName.PostValue, exceptionMessage)
|
||||
}
|
||||
}
|
||||
XEventBus.post(EventName.WXLoginResult, it)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
@@ -35,8 +48,7 @@ class WXEntryActivity : WXBaseActivity() {
|
||||
BaseResp.ErrCode.ERR_OK -> {
|
||||
result = "登录成功"
|
||||
val code = r.code
|
||||
LogUtil.e("${result}TAG_WECHAT_CODE:${r.openId}")
|
||||
// XEventBus.post(EventName.PostValue, code)
|
||||
LogUtil.e("${result}TAG_WECHAT_CODE:$code")
|
||||
mLoginCNViewModel.wxLogin(code)
|
||||
}
|
||||
|
||||
|
||||
@@ -85,8 +85,8 @@ abstract class BaseNetworkApi<I>(private val baseUrl: String) : IService<I> {
|
||||
return Result.success("${ErrorCode.CREDIT_CARD_PAY_FAIL}" as T)
|
||||
}
|
||||
}
|
||||
//设备已被绑定
|
||||
else if (response.code == ErrorCode.DEVICE_HAS_BIND) {
|
||||
//设备已被绑定 微信绑定不存在
|
||||
else if (response.code == ErrorCode.DEVICE_HAS_BIND || response.code == ErrorCode.WX_NO_EXIST) {
|
||||
throw NetworkErrorCodeException.of(response.code, response.message + "")
|
||||
}
|
||||
|
||||
|
||||
@@ -7,5 +7,6 @@ data class BaseResponse<T>(
|
||||
var code: Int = 0,
|
||||
val message: String? = null,
|
||||
val redirect: String? = null,
|
||||
val data: T? = null
|
||||
val data: T? = null,
|
||||
val errorData: ErrorDataBean? = null
|
||||
)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.abbidot.baselibrary.network.base
|
||||
|
||||
data class ErrorDataBean(val openid: String)
|
||||
@@ -18,6 +18,9 @@ import androidx.annotation.IntDef
|
||||
ErrorCode.EMAIL_FORMAT_ERROR,
|
||||
ErrorCode.NO_SHARE_MYSELF,
|
||||
ErrorCode.DEVICE_HAS_BOUND,
|
||||
ErrorCode.WX_NO_EXIST,
|
||||
ErrorCode.PHONE_NO_REGISTER,
|
||||
ErrorCode.PHONE_HAS_BIND,
|
||||
ErrorCode.DEVICE_HAS_BIND,
|
||||
ErrorCode.DEVICE_NOT_EXIST
|
||||
)
|
||||
@@ -69,6 +72,12 @@ annotation class ErrorCode {
|
||||
|
||||
//515 设备未存在
|
||||
const val DEVICE_NOT_EXIST = 515
|
||||
//519 手机号未注册
|
||||
const val PHONE_NO_REGISTER = 519
|
||||
//520 手机号已绑定
|
||||
const val PHONE_HAS_BIND = 520
|
||||
//微信绑定不存在
|
||||
const val WX_NO_EXIST = 521
|
||||
|
||||
//信用卡支付成功
|
||||
const val CREDIT_CARD_PAY_SUCCESS = 1
|
||||
|
||||
Reference in New Issue
Block a user