完善微信登录不同情况的逻辑

This commit is contained in:
2026-09-04 17:53:46 +08:00
parent 5dd4afa056
commit 6b9e5de48c
16 changed files with 109 additions and 54 deletions

View File

@@ -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)
}
//不做强制类型转换

View File

@@ -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,"")
}
/**

View File

@@ -92,7 +92,7 @@ class RegisterCNStartFragment :
}
activity.mPhone = phone
mRegisterCNViewModel.validatePhoneCode(this, phone, code, 3)
mRegisterCNViewModel.validatePhoneCode(this, phone, code, 3,"")
}
/**

View File

@@ -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>
/**

View File

@@ -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)
}
/**

View File

@@ -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
)

View File

@@ -8,24 +8,25 @@ 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) {
switchFragment(2)
}.apply {
mFragmentList.add(
AccountCnPhoneFragment.newInstance(
this@WXLoginActivity, ConstantInt.Type4
mWXOpenid = intent.getStringExtra(MMKVKey.CountryCode) ?: ""
mEmailValidFragment =
EmailValidFragment.newInstance(this, ConstantInt.Type4, openid = mWXOpenid) {
switchFragment(2)
}.apply {
mFragmentList.add(
AccountCnPhoneFragment.newInstance(
this@WXLoginActivity, ConstantInt.Type4
)
)
)
mFragmentList.add(this)
mFragmentList.add(
CreateAccountV2ThreeFragment.newInstance(
this@WXLoginActivity, mWXCode
mFragmentList.add(this)
mFragmentList.add(
CreateAccountV2ThreeFragment.newInstance(
this@WXLoginActivity, mWXOpenid
)
)
)
}
}
super.initData()
}

View File

@@ -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
)

View File

@@ -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,14 +304,24 @@ open class EmailValidFragment : BaseFragment<FragmentBaseEmailValidBinding>(
setButtonEnabled(mViewBinding.btnForgotPasswordV2TwoContinue, ConstantInt.Type0)
if (AppUtils.isChina()) {
if (mVerifyCodeType == ConstantInt.Type3) {
mLoginCNViewModel.phoneLogin(
this@EmailValidFragment, mEmail, content
)
} else {
mRegisterCNViewModel.validatePhoneCode(
this@EmailValidFragment, mEmail, content, mVerifyCodeType
)
when (mVerifyCodeType) {
ConstantInt.Type3 -> {
mLoginCNViewModel.phoneLogin(
this@EmailValidFragment, mEmail, content
)
}
ConstantInt.Type4 -> {
mRegisterCNViewModel.validatePhoneCode(
this@EmailValidFragment, mEmail, content, mVerifyCodeType, mOpenid
)
}
else -> {
mRegisterCNViewModel.validatePhoneCode(
this@EmailValidFragment, mEmail, content, mVerifyCodeType, ""
)
}
}
} else {
mRegisterViewModel.validateCode(

View File

@@ -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)
}
/**

View File

@@ -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
}
}

View File

@@ -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)
}