提交 64b90d85 authored 作者: JarvanMo's avatar JarvanMo

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

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