提交 3a8263ba authored 作者: weoil's avatar weoil

微信开放标签打开App时获取信息(冷启动获)

上级 bf9ca9a7
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<activity <activity
android:name=".wxapi.FluwxWXEntryActivity" android:name=".wxapi.FluwxWXEntryActivity"
android:launchMode="singleTask" android:launchMode="singleTask"
android:taskAffinity="${applicationId}"
android:theme="@style/DisablePreviewTheme" /> android:theme="@style/DisablePreviewTheme" />
<activity-alias <activity-alias
...@@ -17,6 +18,7 @@ ...@@ -17,6 +18,7 @@
android:exported="true" android:exported="true"
android:launchMode="singleTop" android:launchMode="singleTop"
android:targetActivity="com.jarvan.fluwx.wxapi.FluwxWXEntryActivity" android:targetActivity="com.jarvan.fluwx.wxapi.FluwxWXEntryActivity"
android:taskAffinity="${applicationId}"
android:theme="@style/DisablePreviewTheme"> android:theme="@style/DisablePreviewTheme">
<intent-filter> <intent-filter>
......
...@@ -24,6 +24,7 @@ public class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { ...@@ -24,6 +24,7 @@ public class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
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) 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.authHandler = authHandler this.authHandler = authHandler
...@@ -42,6 +43,7 @@ public class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { ...@@ -42,6 +43,7 @@ public class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
val channel = MethodChannel(flutterPluginBinding.binaryMessenger, "com.jarvanmo/fluwx") val channel = MethodChannel(flutterPluginBinding.binaryMessenger, "com.jarvanmo/fluwx")
channel.setMethodCallHandler(this) channel.setMethodCallHandler(this)
FluwxResponseHandler.setMethodChannel(channel) FluwxResponseHandler.setMethodChannel(channel)
FluwxRequestHandler.setMethodChannel(channel)
authHandler = FluwxAuthHandler(channel) authHandler = FluwxAuthHandler(channel)
shareHandler = FluwxShareHandlerEmbedding(flutterPluginBinding.flutterAssets, flutterPluginBinding.applicationContext) shareHandler = FluwxShareHandlerEmbedding(flutterPluginBinding.flutterAssets, flutterPluginBinding.applicationContext)
} }
......
/*
* Copyright (C) 2020 The OpenFlutter Organization
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jarvan.fluwx.handlers
import com.tencent.mm.opensdk.modelmsg.ShowMessageFromWX
import io.flutter.plugin.common.MethodChannel
import com.tencent.mm.opensdk.modelbase.BaseReq
object FluwxRequestHandler {
private var channel: MethodChannel? = null
fun setMethodChannel(channel: MethodChannel) {
FluwxRequestHandler.channel = channel
}
fun handleRequest(req: BaseReq) {
when (req) {
is ShowMessageFromWX.Req -> hanleWXShowMessageFromWX(req)
}
}
private fun hanleWXShowMessageFromWX(req: ShowMessageFromWX.Req) {
val result = mapOf(
"extMsg" to req.message.messageExt, )
channel?.invokeMethod("onWXShowMessageFromWX", result)
}
}
\ No newline at end of file
...@@ -19,9 +19,11 @@ import android.app.Activity ...@@ -19,9 +19,11 @@ import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import com.jarvan.fluwx.handlers.FluwxResponseHandler import com.jarvan.fluwx.handlers.FluwxResponseHandler
import com.jarvan.fluwx.handlers.FluwxRequestHandler
import com.jarvan.fluwx.handlers.WXAPiHandler import com.jarvan.fluwx.handlers.WXAPiHandler
import com.tencent.mm.opensdk.modelbase.BaseReq import com.tencent.mm.opensdk.modelbase.BaseReq
import com.tencent.mm.opensdk.modelbase.BaseResp import com.tencent.mm.opensdk.modelbase.BaseResp
import com.tencent.mm.opensdk.modelmsg.ShowMessageFromWX
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler
...@@ -61,6 +63,7 @@ open class FluwxWXEntryActivity : Activity(), IWXAPIEventHandler { ...@@ -61,6 +63,7 @@ open class FluwxWXEntryActivity : Activity(), IWXAPIEventHandler {
// 稳定复现场景:微信版本为7.0.5,小程序SDK为2.7.7 // 稳定复现场景:微信版本为7.0.5,小程序SDK为2.7.7
if (baseReq.type == 4) { if (baseReq.type == 4) {
// com.tencent.mm.opensdk.constants.ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX = 4 // com.tencent.mm.opensdk.constants.ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX = 4
FluwxRequestHandler.handleRequest(baseReq)
startSpecifiedActivity() startSpecifiedActivity()
} }
} }
......
...@@ -73,7 +73,7 @@ packages: ...@@ -73,7 +73,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "2.4.0" version: "2.4.2"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:
......
...@@ -40,6 +40,8 @@ Map<String, _WeChatResponseInvoker> _nameAndResponseMapper = { ...@@ -40,6 +40,8 @@ Map<String, _WeChatResponseInvoker> _nameAndResponseMapper = {
WeChatAuthGotQRCodeResponse.fromMap(argument), WeChatAuthGotQRCodeResponse.fromMap(argument),
"onQRCodeScanned": (Map argument) => "onQRCodeScanned": (Map argument) =>
WeChatQRCodeScannedResponse.fromMap(argument), WeChatQRCodeScannedResponse.fromMap(argument),
"onWXShowMessageFromWX": (Map argument) =>
WeChatShowMessageFromWXRequest.fromMap(argument),
}; };
class BaseWeChatResponse { class BaseWeChatResponse {
...@@ -173,6 +175,15 @@ class WeChatQRCodeScannedResponse extends BaseWeChatResponse { ...@@ -173,6 +175,15 @@ class WeChatQRCodeScannedResponse extends BaseWeChatResponse {
: super._(map[_errCode], map[_errStr]); : super._(map[_errCode], map[_errStr]);
} }
// 获取微信打开App时携带的参数
class WeChatShowMessageFromWXRequest extends BaseWeChatResponse {
final String extMsg;
WeChatShowMessageFromWXRequest.fromMap(Map map)
: extMsg = map["extMsg"],
super._(0, '');
}
///WechatAuth_Err_OK(0), ///WechatAuth_Err_OK(0),
///WechatAuth_Err_NormalErr(-1), ///WechatAuth_Err_NormalErr(-1),
///WechatAuth_Err_NetworkErr(-2), ///WechatAuth_Err_NetworkErr(-2),
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论