firebase 的短信代码不匹配

Posted

技术标签:

【中文标题】firebase 的短信代码不匹配【英文标题】:The sms code from firebase does not match 【发布时间】:2021-12-05 06:03:15 【问题描述】:

我使用 Firebase 电话身份验证创建了一个号码发送活动和确认/otp 片段。当定向到确认页面时,来自 Firebase 的 6 位短信代码会发送到输入的电话号码,但无论我做什么,输入的 edittext 和来自 firebase 的代码都不匹配。 当我将编辑文本留空时,它会重定向到我想要的片段,就好像它是正确的一样。你能帮我在哪里犯错吗?我在确认片段中的代码如下;

类 FragmentRegisterTelOnay : Fragment() varcomingNumber = "" lateinit var auth : FirebaseAuth lateinit var 回调:PhoneAuthProvider.OnVerificationStateChangedCallbacks var 验证 ID = "" varcomingCode : 字符串 = "" 覆盖 fun onCreateView(inflater: LayoutInflater,container: ViewGroup?,savedInstanceState: Bundle?): View? var view = inflater.inflate(R.layout.fragment_register_activity_phone,container,false) view.tvKullaniciTelNo.setText("+90"+comingNumber) auth = Firebase.auth setupCallBack()

  view.ileriButton.setOnClickListener 
      if (comingCode.equals(editTextOnayKodu.text.toString()))

        EventBus.getDefault().postSticky(EventBusDataEvents.KayitBilgileriniGonder("+90$comingNumber",null,verificationID,comingCode))
        val transaction = requireActivity().supportFragmentManager.beginTransaction()
        transaction.replace(R.id.telefonOnayKod,FragmentRegisterDetailPhone())
        transaction.addToBackStack("TelOnayfragmentEklendi")
        transaction.commit()
        else
          Toast.makeText(activity,"Wrong Code",Toast.LENGTH_LONG).show()
      

  

    val options = PhoneAuthOptions.newBuilder(auth)
        .setPhoneNumber("+90"+comingNumber)       // Phone number to verify
        .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit
        .setActivity(requireActivity()) // Activity (for callback binding)
        .setCallbacks(callbacks)          // OnVerificationStateChangedCallbacks
        .build()
    PhoneAuthProvider.verifyPhoneNumber(options)

    return view


private fun setupCallBack() 
    callbacks = object : PhoneAuthProvider.OnVerificationStateChangedCallbacks() 

        override fun onVerificationCompleted(credential: PhoneAuthCredential) 
            if(!credential.smsCode.isNullOrEmpty())
            comingCode = credential.smsCode!!
            progressBarOnayKod.visibility = View.GONE
            Log.e("Success","on verificationcompleted sms: " + comingCode)
            else
                Log.e("Error","onverification has not completed")
            
        

        override fun onVerificationFailed(e: FirebaseException) 
            Log.e("Error: ",e.localizedMessage)
            progressBarOnayKod.visibility = View.GONE
        

        override fun onCodeSent(verificationId: String,token: PhoneAuthProvider.ForceResendingToken) 
            verificationID = verificationId
            progressBarOnayKod.visibility = View.VISIBLE
            Log.e("Codesent","oncodesent worked")
        
    


@Subscribe (sticky = true)
internal fun onTelefonEvent(kayitBilgileri: EventBusDataEvents.KayitBilgileriniGonder)
    comingNumber = kayitBilgileri.telNo.toString()
    Log.e("test",comingNumber)


override fun onAttach(context: Context) 
    super.onAttach(context)
    EventBus.getDefault().register(this)


override fun onDetach() 
    super.onDetach()
    EventBus.getDefault().unregister(this)

【问题讨论】:

【参考方案1】:

首先将 sha1 设置为 firebase 设置并生成 google config.json 然后添加到 poject 的根目录并添加到 build.gradle 依赖项。 它会正常工作

资源:https://github.com/firebase/quickstart-android/issues/283

【讨论】:

嗨哈立德。你说的我都已经做了。尽管如此,事实并非如此。短信代码来了。存在不匹配问题。

以上是关于firebase 的短信代码不匹配的主要内容,如果未能解决你的问题,请参考以下文章

Firebase 电话身份验证未发送带有代码的短信

Firebase 短信验证

firebase 和 BigQuery 的保留结果不匹配

在 Firebase 电话身份验证中未接收代码。

Flutter Firebase 电话身份验证未发送短信代码。直接调用 PhoneCodeAutoRetrievalTimeout 方法。这是我的代码

Firebase Phone Auth 不会用我的代码向我发送短信