提交 202c225d authored 作者: JarvanMo's avatar JarvanMo

Merge branch 'dev' of https://github.com/OpenFlutter/fluwx into dev

## 2.6.2
* Fix #338 on Android
## 2.6.1
* Fix #338
......
......@@ -19,14 +19,16 @@ import io.flutter.plugin.common.PluginRegistry
class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
companion object {
var callingChannel:MethodChannel? = null
@JvmStatic
fun registerWith(registrar: PluginRegistry.Registrar) {
val channel = MethodChannel(registrar.messenger(), "com.jarvanmo/fluwx")
val authHandler = FluwxAuthHandler(channel)
FluwxResponseHandler.setMethodChannel(channel)
FluwxRequestHandler.setMethodChannel(channel)
WXAPiHandler.setContext(registrar.activity().applicationContext)
channel.setMethodCallHandler(FluwxPlugin().apply {
this.fluwxChannel = channel
this.authHandler = authHandler
this.shareHandler = FluwxShareHandlerCompat(registrar).apply {
permissionHandler = PermissionHandler(registrar.activity())
......@@ -42,19 +44,15 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
private var fluwxChannel: MethodChannel? = null
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
if (fluwxChannel == null) {
fluwxChannel = MethodChannel(flutterPluginBinding.binaryMessenger, "com.jarvanmo/fluwx")
fluwxChannel?.setMethodCallHandler(this)
}
fluwxChannel?.let {
FluwxResponseHandler.setMethodChannel(it)
FluwxRequestHandler.setMethodChannel(it)
authHandler = FluwxAuthHandler(it)
}
val channel = MethodChannel(flutterPluginBinding.binaryMessenger, "com.jarvanmo/fluwx")
channel.setMethodCallHandler(this)
fluwxChannel = channel
authHandler = FluwxAuthHandler(channel)
shareHandler = FluwxShareHandlerEmbedding(flutterPluginBinding.flutterAssets, flutterPluginBinding.applicationContext)
}
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
FluwxPlugin.callingChannel = fluwxChannel
when {
call.method == "registerApp" -> WXAPiHandler.registerApp(call, result)
call.method == "sendAuth" -> authHandler?.sendAuth(call, result)
......
......@@ -21,6 +21,7 @@ import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
import com.jarvan.fluwx.FluwxPlugin
import com.tencent.mm.opensdk.modelmsg.ShowMessageFromWX
import io.flutter.plugin.common.MethodChannel
import com.tencent.mm.opensdk.modelbase.BaseReq
......@@ -31,13 +32,6 @@ object FluwxRequestHandler {
var customOnReqDelegate: ((baseReq: BaseReq, activity: Activity) -> Unit)? = null
private var channel: MethodChannel? = null
fun setMethodChannel(channel: MethodChannel) {
FluwxRequestHandler.channel = channel
}
fun handleRequestInfoFromIntent(intent: Intent) {
intent.getBundleExtra(KEY_FLUWX_REQUEST_INFO_BUNDLE)?.run {
val type = getInt("_wxapi_command_type", -9999)
......@@ -59,7 +53,7 @@ object FluwxRequestHandler {
val result = mapOf(
"extMsg" to req.message.messageExt
)
channel?.invokeMethod("onWXShowMessageFromWX", result)
FluwxPlugin.callingChannel?.invokeMethod("onWXShowMessageFromWX", result)
}
private fun defaultOnReqDelegate(baseReq: BaseReq, activity: Activity) {
......
......@@ -15,6 +15,7 @@
*/
package com.jarvan.fluwx.handlers
import com.jarvan.fluwx.FluwxPlugin
import com.tencent.mm.opensdk.modelbase.BaseResp
import com.tencent.mm.opensdk.modelbiz.SubscribeMessage
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram
......@@ -25,17 +26,12 @@ import com.tencent.mm.opensdk.modelpay.PayResp
import io.flutter.plugin.common.MethodChannel
object FluwxResponseHandler {
private var channel: MethodChannel? = null
private const val errStr = "errStr"
private const val errCode = "errCode"
private const val openId = "openId"
private const val type = "type"
fun setMethodChannel(channel: MethodChannel) {
FluwxResponseHandler.channel = channel
}
fun handleResponse(response: BaseResp) {
when (response) {
is SendAuth.Resp -> handleAuthResponse(response)
......@@ -56,7 +52,7 @@ object FluwxResponseHandler {
"scene" to response.scene,
type to response.type)
channel?.invokeMethod("onSubscribeMsgResp", result)
FluwxPlugin.callingChannel?.invokeMethod("onSubscribeMsgResp", result)
}
private fun handleLaunchMiniProgramResponse(response: WXLaunchMiniProgram.Resp) {
......@@ -71,7 +67,7 @@ object FluwxResponseHandler {
result["extMsg"] = response.extMsg
}
channel?.invokeMethod("onLaunchMiniProgramResponse", result)
FluwxPlugin.callingChannel?.invokeMethod("onLaunchMiniProgramResponse", result)
}
private fun handlePayResp(response: PayResp) {
......@@ -83,7 +79,7 @@ object FluwxResponseHandler {
type to response.type,
errCode to response.errCode
)
channel?.invokeMethod("onPayResponse", result)
FluwxPlugin.callingChannel?.invokeMethod("onPayResponse", result)
}
private fun handleSendMessageResp(response: SendMessageToWX.Resp) {
......@@ -93,7 +89,7 @@ object FluwxResponseHandler {
errCode to response.errCode,
openId to response.openId)
channel?.invokeMethod("onShareResponse", result)
FluwxPlugin.callingChannel?.invokeMethod("onShareResponse", result)
}
private fun handleAuthResponse(response: SendAuth.Resp) {
......@@ -108,7 +104,7 @@ object FluwxResponseHandler {
"url" to response.url,
type to response.type)
channel?.invokeMethod("onAuthResponse", result)
FluwxPlugin.callingChannel?.invokeMethod("onAuthResponse", result)
}
......@@ -121,6 +117,6 @@ object FluwxResponseHandler {
openId to response.openId,
type to response.type)
channel?.invokeMethod("onWXOpenBusinessWebviewResponse", result)
FluwxPlugin.callingChannel?.invokeMethod("onWXOpenBusinessWebviewResponse", result)
}
}
\ No newline at end of file
name: fluwx
description: The capability of implementing WeChat SDKs in Flutter. With Fluwx, developers can use WeChatSDK easily, such as sharing, payment, lanuch mini program and etc.
version: 2.6.1
version: 2.6.2
homepage: https://github.com/JarvanMo/fluwx
environment:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论