package cn.net.wzj.mall

import io.flutter.embedding.android.FlutterActivity

import android.os.Bundle
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import com.tencent.mm.opensdk.openapi.WXAPIFactory
import com.tencent.mm.opensdk.modelbiz.WXOpenBusinessView

class MainActivity: FlutterActivity(){
    //集成拉起微信确认收款
    private val CHANNEL = "wechat_business_view"
    private val appId = "wxebcdaea31881caab"

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)

        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
            .setMethodCallHandler { call, result ->
                if (call.method == "openBusinessView") {
                    val args = call.arguments as Map<*, *>
                    val packageInfo = args["package"] as String
                    openBusinessView(packageInfo)
                    result.success(true)
                } else {
                    result.notImplemented()
                }
            }
    }

    private fun openBusinessView(packageInfo: String) {
        val api = WXAPIFactory.createWXAPI(this, appId)
        val req = WXOpenBusinessView.Req()
        req.businessType = "requestMerchantTransfer"
        req.query = packageInfo
        api.sendReq(req)
    }
}
