tanghao
2022-08-03 fd7255883cff7f3518a8e4efd97b1866ec38ae55
app/src/main/java/com/okgoincar/base/MainBroadCastReceiver.kt
@@ -23,57 +23,61 @@
class MainBroadCastReceiver : BroadcastReceiver() {
    override fun onReceive(contexts: Context?, intent: Intent?) {
        if (intent == null) {
            toast("内容获取为空,广播接收消息错误")
            return
        }
        try {
            Handler(Looper.getMainLooper()).post {
                val b = intent.getBooleanExtra("isLogin", true)
                if (!b) {
                    loginOut(contexts)
                    CacheUtil.get().clear()
                    EventBus.getDefault().post(BaseEvent(BaseEvent.OUT_APP))
                } else {
                    if (getToken().isNullOrEmpty()) {
                        Handler(Looper.getMainLooper()).post {
                            toast("开始登录")
                        }
                        var driverCertificate = intent.getStringExtra("driverCertificate")
                        if (driverCertificate == null) {
//                            toast("身份证获取失败")
                        } else {
                            if (contexts == null) {
//                                toast("上下文为空,使用全局跳转")
                                toLoginActivity(MyApplication.getInstance(), driverCertificate)
                            } else {
                                toLoginActivity(MyApplication.getInstance(), driverCertificate)
                            }
                        }
                    }
                }
            }
        } catch (e: Exception) {
        }
//        if (intent == null) {
//            toast("内容获取为空,广播接收消息错误")
//            return
//        }
//        try {
//            Handler(Looper.getMainLooper()).post {
//                val b = intent.getBooleanExtra("isLogin", true)
//                if (!b) {
//                    loginOut(contexts)
//                    CacheUtil.get().clear()
//                    EventBus.getDefault().post(BaseEvent(BaseEvent.OUT_APP))
//                } else {
//                    if (getToken().isNullOrEmpty()) {
//                        Handler(Looper.getMainLooper()).post {
////                            toast("开始登录")
//                        }
//                        var driverCertificate = intent.getStringExtra("driverCertificate")
//                        if (driverCertificate == null) {
////                            toast("身份证获取失败")
//                        } else {
//                            if (contexts == null) {
////                                toast("上下文为空,使用全局跳转")
//                                toLoginActivity(MyApplication.getInstance(), driverCertificate)
//                            } else {
//                                toLoginActivity(MyApplication.getInstance(), driverCertificate)
//                            }
//                        }
//
//                    }
//                }
//            }
//        } catch (e: Exception) {
//
//        }
    }
    private fun loginOut(context: Context?) {
        var map = getMapByAny()
        callNet(context!!, Api.loginOut, map) {
            toast("Ok退签")
        }
    }
    private fun toLoginActivity(context: Context?, driverCertificate: String?) {
        var map = getMapByAny()
        map["identification"] = driverCertificate
        callNet(context!!, Api.loginByIdentification, map) {
        if (driverCertificate.isNullOrEmpty()){
            toast("资格证号:空")
            return
        }
        map["taxiAptitudeCard"] = driverCertificate
        callNet(context!!, Api.loginByTaxiAptitudeCard, map) {
            toast("登录成功")
            var bean = Gson().fromJson<LoginBean>(it, LoginBean::class.java)
            CacheKey.putKeyStr("identification", driverCertificate!!)
            CacheKey.putKeyStr("identification", driverCertificate)
            CacheKey.putKeyStr("appid", bean.data.appid)
            CacheKey.putKeyStr("token", bean.data.token)
            CacheKey.putKeyStr("userId", bean.data.id.toString())