如何解决有关“代码:60202,消息:需要令牌”的问题

时间:2019-10-25 03:04:01

标签: android kotlin retrofit2 zxing

D / OkHttp:{“代码”:60202,“消息”:“需要令牌”}

我打Qrcode时服务器错误代码。 让我们检查我的Qrcode onActivityResult,API等。 然后我应该如何修复代码。谢谢你。

我已经尝试在onActivityResult中添加securitytoken。 但仍然是同样的问题。 我该如何解决我的代码?

Router
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

        val securitytoken = SaveSharedPreference.getUserInfo(this)
        val result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
        if (securitytoken != null) {
            if (result == null) {
                Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show()
            } else {
                Toast.makeText(this, "Scanned: " + result.contents, Toast.LENGTH_LONG).show()
                Client.retrofitService.request(result.contents).enqueue(object : Callback<String?> {

                    override fun onResponse(
                        call: Call<String?>?,
                        response: Response<String?>?
                    ) {
                        Log.d(toString(), "status: ${response?.code()}. body: ${response?.body()}")

                    }


                    override fun onFailure(call: Call<String?>, t: Throwable) {

                    }

                })
            }

        }
    }

object SaveSharedPreference {
    private var keyToken = "key.token"

    private fun getSharedPreferences(ctx: Context): SharedPreferences {
        return PreferenceManager.getDefaultSharedPreferences(ctx)
    }

    fun setUserInfo(ctx: Context, token: String) {
        val editor: Editor =
            getSharedPreferences(ctx).edit()
        editor.putString(keyToken, token)
        editor.apply()
    }

    fun getUserInfo(ctx: Context): String? {
        return getSharedPreferences(ctx)
            .getString(keyToken, null)
    }


}

0 个答案:

没有答案