package com.cheng.blzb.utils

import com.cheng.blzb.common.Constants
import com.example.base.utils.Utils
import com.tencent.mm.opensdk.constants.ConstantsAPI.WXApp
import com.tencent.mm.opensdk.openapi.IWXAPI
import com.tencent.mm.opensdk.openapi.WXAPIFactory

object WxUtils {
    var api: IWXAPI? = null

    init {
        api = WXAPIFactory.createWXAPI(Utils.getApp(), Constants.WechatAppId)
    }

    fun isWxInstalled(): Boolean {
        return api!!.isWXAppInstalled
    }

    fun getWxVersionName(): String {
        try {
            val packageInfo = Utils.getApp().packageManager.getPackageInfo(WXApp.WXAPP_PACKAGE_NAME, 0)
            return packageInfo.versionName
        } catch (e: Exception) {
            e.printStackTrace()
        }
        return ""
    }
}