@file:OptIn(DelicateCoroutinesApi::class)

package com.img.rabbit.wxapi

import com.img.rabbit.provider.storage.GlobalStateManager
import com.tencent.mm.opensdk.constants.ConstantsAPI
import com.tencent.mm.opensdk.modelbase.BaseResp
import com.tencent.mm.opensdk.modelmsg.SendAuth
import com.umeng.socialize.weixin.view.WXCallbackActivity
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch


class WXEntryActivity : WXCallbackActivity() {
    override fun onResp(resp: BaseResp?) {
        if (resp?.type == ConstantsAPI.COMMAND_SENDAUTH) {
            when (resp.errCode) {
                BaseResp.ErrCode.ERR_OK -> {
                    val authResp = resp as SendAuth.Resp
                    //val wxState = WxBean(code = authResp.code,state = authResp.state)

                    GlobalScope.launch {
                        GlobalStateManager(this@WXEntryActivity).storeGlobalWxAuthorization(authResp.code)

                        finish()
                    }
                }

                else -> {}
            }
        }
    }
}