Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-fluwx
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx-fluwx
Commits
1c0802f0
提交
1c0802f0
authored
5月 16, 2023
作者:
JarvanMo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor android side
上级
583d58bd
全部展开
显示空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
84 行增加
和
423 行删除
+84
-423
README_CN.md
README_CN.md
+1
-1
build.gradle
android/build.gradle
+27
-30
gen.gradle.kts
android/gen.gradle.kts
+33
-0
AndroidManifest.xml
android/src/main/AndroidManifest.xml
+0
-11
FluwxPlugin.kt
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
+0
-0
FluwxRequestHandler.kt
...n/kotlin/com/jarvan/fluwx/handlers/FluwxRequestHandler.kt
+0
-110
FluwxResponseHandler.kt
.../kotlin/com/jarvan/fluwx/handlers/FluwxResponseHandler.kt
+0
-157
WXAPiHandler.kt
...src/main/kotlin/com/jarvan/fluwx/handlers/WXAPiHandler.kt
+1
-49
FluwxExtensions.kt
...src/main/kotlin/com/jarvan/fluwx/utils/FluwxExtensions.kt
+16
-17
FluwxWXEntryActivity.kt
...ain/kotlin/com/jarvan/fluwx/wxapi/FluwxWXEntryActivity.kt
+6
-48
没有找到文件。
README_CN.md
浏览文件 @
1c0802f0
...
...
@@ -62,7 +62,7 @@ dependencies:
> V4开始,iOS中的url_scheme,universal_link, LSApplicationQueriesSchemes可以不必开发者手动配动。只需在`pubspec.yaml`
> 中填写即可。
-
app_id.
必填
. 它将用于生成iOS的url_scheme以及在Android端冷启动时,重新初始化WxApi。
-
app_id.
可选但推荐填写
. 它将用于生成iOS的url_scheme以及在Android端冷启动时,重新初始化WxApi。
-
debug_logging. 可选. 把它设置成
`true`
可以开启日志。
-
flutter_activity. 可选. 这个通常是用于Android的冷启动。如果不设置任何值,
`Fluwx`
将尝试启动launcher activity.
-
universal_link. iOS 必填. 它将用自动配置universal_link。
...
...
android/build.gradle
浏览文件 @
1c0802f0
...
...
@@ -33,14 +33,13 @@ android {
compileSdk
31
sourceSets
{
main
.
java
.
srcDirs
+=
[
'src/main/kotlin'
,
"${buildDir}/generated/src/kotlin"
]
main
.
java
.
srcDirs
+=
[
'src/main/kotlin'
,
"${buildDir}/generated/src/kotlin"
]
test
.
java
.
srcDirs
+=
'src/test/kotlin'
}
defaultConfig
{
minSdkVersion
16
consumerProguardFiles
'consumer-proguard-rules.txt'
manifestPlaceholders
=
loadManifestPlaceholder
(
projectYaml
)
}
dependencies
{
...
...
@@ -75,17 +74,25 @@ Map loadPubspec() {
return
projectConfig
}
static
def
loadManifestPlaceholder
(
Map
projectConfig
)
{
String
interruptWxRequest
=
"true"
String
flutterActivity
=
""
String
debugLogging
=
"disabled"
Map
fluwx
=
(
Map
)
projectConfig
.
get
(
"fluwx"
)
tasks
.
register
(
"generateFluwxHelperFile"
)
{
Map
config
=
loadPubspec
()
Map
fluwx
=
(
Map
)
config
.
get
(
"fluwx"
)
if
(
fluwx
)
{
String
appId
=
(
String
)
fluwx
.
get
(
"app_id"
)
if
(
appId
==
null
)
{
appId
=
""
}
File
generateFolder
=
new
File
(
"${buildDir}/generated/src/kotlin/com/jarvan/fluwx"
)
String
enableLogging
=
"false"
String
interruptWeChatRequestByFluwx
=
"true"
String
flutterActivity
=
""
Map
android
=
(
Map
)
fluwx
.
get
(
"android"
)
if
(
android
)
{
def
iwr
=
android
.
get
(
"interrupt_wx_request"
)
if
(
iwr
)
{
interruptW
xRequest
=
(
String
)
iwr
if
(
iwr
&&
iwr
==
"true"
||
iwr
==
"false"
)
{
interruptW
eChatRequestByFluwx
=
(
String
)
iwr
}
def
activity
=
android
.
get
(
"flutter_activity"
)
...
...
@@ -95,37 +102,27 @@ static def loadManifestPlaceholder(Map projectConfig) {
}
def
logging
=
fluwx
.
get
(
"debug_logging"
)
if
(
logging
&&
logging
==
"true"
)
{
debugLogging
=
"true"
if
(
logging
&&
logging
==
"true"
||
logging
==
"false"
)
{
enableLogging
=
(
String
)
logging
}
}
return
[
"InterruptWeChatRequestByFluwx"
:
interruptWxRequest
,
"FluwxFlutterActivity"
:
flutterActivity
,
"WeChatDebugLogging"
:
debugLogging
]
}
tasks
.
register
(
"generateFluwxHelperFile"
)
{
Map
config
=
loadPubspec
()
Map
fluwx
=
(
Map
)
config
.
get
(
"fluwx"
)
if
(
fluwx
)
{
String
appId
=
(
String
)
fluwx
.
get
(
"app_id"
)
if
(
appId
==
null
)
{
appId
=
""
}
File
generateFolder
=
new
File
(
"${buildDir}/generated/src/kotlin/com/jarvan/fluwx"
)
String
template
=
"package com.jarvan.fluwx\n"
+
"\n"
+
"// auto generated\n"
+
"object FluwxHelper {\n"
+
" val appId:String =\"&&PLACEHOLDER&&\";\n"
+
"internal object FluwxConfigurations {\n"
+
" val flutterActivity: String = \"&&flutterActivity&&\"\n"
+
" val enableLogging: Boolean = &&enableLogging&&\n"
+
" val interruptWeChatRequestByFluwx: Boolean = &&interruptWeChatRequestByFluwx&&\n"
+
"}"
if
(!
generateFolder
.
exists
())
{
generateFolder
.
mkdirs
()
}
file
(
"${generateFolder.absolutePath}/FluwxHelper.kt"
).
text
=
template
.
replace
(
"&&PLACEHOLDER&&"
,
appId
)
String
source
=
template
.
replace
(
"&&interruptWeChatRequestByFluwx&&"
,
interruptWeChatRequestByFluwx
)
.
replace
(
"&&flutterActivity&&"
,
flutterActivity
)
.
replace
(
"&&enableLogging&&"
,
enableLogging
)
file
(
"${generateFolder.absolutePath}/FluwxConfigurations.kt"
).
text
=
source
}
...
...
android/gen.gradle.kts
0 → 100644
浏览文件 @
1c0802f0
abstract class GenFluwxHelperTask : DefaultTask() {
@get:Incremental
@get:PathSensitive(PathSensitivity.NAME_ONLY)
@get:InputDirectory
abstract val inputDir: DirectoryProperty
@get:OutputDirectory
abstract val outputDir: DirectoryProperty
@get:Input
abstract val inputProperty: Property<String>
@TaskAction
fun execute(inputChanges: InputChanges) {
println(
if (inputChanges.isIncremental) "Executing incrementally"
else "Executing non-incrementally"
)
inputChanges.getFileChanges(inputDir).forEach { change ->
if (change.fileType == FileType.DIRECTORY) return@forEach
println("${change.changeType}: ${change.normalizedPath}")
val targetFile = outputDir.file(change.normalizedPath).get().asFile
// if (change.changeType == ChangeType.REMOVED) {
// targetFile.delete()
// } else {
// targetFile.writeText(change.file.readText().reversed())
// }
}
}
}
\ No newline at end of file
android/src/main/AndroidManifest.xml
浏览文件 @
1c0802f0
...
...
@@ -12,17 +12,6 @@
<application>
<meta-data
android:name=
"InterruptWeChatRequestByFluwx"
android:value=
"${InterruptWeChatRequestByFluwx}"
/>
<meta-data
android:name=
"WeChatDebugLogging"
android:value=
"${WeChatDebugLogging}"
/>
<meta-data
android:name=
"FluwxFlutterActivity"
android:value=
"${FluwxFlutterActivity}"
/>
<activity
android:name=
".wxapi.FluwxWXEntryActivity"
android:exported=
"false"
...
...
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
浏览文件 @
1c0802f0
差异被折叠。
点击展开。
android/src/main/kotlin/com/jarvan/fluwx/handlers/FluwxRequestHandler.kt
浏览文件 @
1c0802f0
...
...
@@ -16,119 +16,10 @@
package
com.jarvan.fluwx.handlers
import
android.app.Activity
import
android.content.ActivityNotFoundException
import
android.content.Context
import
android.content.Intent
import
android.content.pm.PackageManager
import
android.net.Uri
import
android.os.Bundle
import
android.util.Log
import
androidx.core.content.ContextCompat.startActivity
import
com.jarvan.fluwx.FluwxPlugin
import
com.jarvan.fluwx.utils.KEY_FLUWX_REQUEST_INFO_BUNDLE
import
com.jarvan.fluwx.utils.KEY_FLUWX_REQUEST_INFO_EXT_MSG
import
com.jarvan.fluwx.utils.startFlutterActivity
import
com.tencent.mm.opensdk.modelbase.BaseReq
import
com.tencent.mm.opensdk.modelmsg.LaunchFromWX
import
com.tencent.mm.opensdk.modelmsg.ShowMessageFromWX
import
java.security.cert.Extension
object
FluwxRequestHandler
{
var
customOnReqDelegate
:
((
baseReq
:
BaseReq
,
activity
:
Activity
)
->
Unit
)?
=
null
fun
handleRequestInfoFromIntent
(
intent
:
Intent
)
{
intent
.
getBundleExtra
(
KEY_FLUWX_REQUEST_INFO_BUNDLE
)
?.
run
{
val
type
=
getInt
(
"_wxapi_command_type"
,
-
9999
)
if
(
type
==
4
)
{
handleShowMessageFromWXBundle
(
this
)
}
else
if
(
type
==
6
)
{
handleWXLaunchFromWXBundle
(
this
)
}
}
}
private
fun
handleShowMessageFromWXBundle
(
bundle
:
Bundle
)
=
handleWXShowMessageFromWX
(
ShowMessageFromWX
.
Req
(
bundle
))
private
fun
handleWXLaunchFromWXBundle
(
bundle
:
Bundle
)
=
handleWXLaunchFromWX
(
LaunchFromWX
.
Req
(
bundle
))
private
fun
handleRequest
(
req
:
BaseReq
)
{
when
(
req
)
{
is
ShowMessageFromWX
.
Req
->
handleWXShowMessageFromWX
(
req
)
is
LaunchFromWX
.
Req
->
handleWXLaunchFromWX
(
req
)
}
}
private
fun
handleWXShowMessageFromWX
(
req
:
ShowMessageFromWX
.
Req
)
{
val
result
=
mapOf
(
"extMsg"
to
req
.
message
.
messageExt
,
"messageAction"
to
req
.
message
.
messageAction
,
"description"
to
req
.
message
.
description
,
"lang"
to
req
.
lang
,
"description"
to
req
.
country
,
)
FluwxPlugin
.
extMsg
=
req
.
message
.
messageExt
FluwxPlugin
.
callingChannel
?.
invokeMethod
(
"onWXShowMessageFromWX"
,
result
)
}
private
fun
handleWXLaunchFromWX
(
req
:
LaunchFromWX
.
Req
)
{
val
result
=
mapOf
(
"extMsg"
to
req
.
messageExt
,
"messageAction"
to
req
.
messageAction
,
"lang"
to
req
.
lang
,
"country"
to
req
.
country
,
)
FluwxPlugin
.
callingChannel
?.
invokeMethod
(
"onWXLaunchFromWX"
,
result
)
}
private
fun
defaultOnReqDelegate
(
baseReq
:
BaseReq
,
activity
:
Activity
)
{
// FIXME: 可能是官方的Bug,从微信拉起APP的Intent类型不对,无法跳转回Flutter Activity
// 稳定复现场景:微信版本为7.0.5,小程序SDK为2.7.7
// com.tencent.mm.opensdk.constants.ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX = 4
if
(!
WXAPiHandler
.
coolBoot
)
{
handleRequest
(
baseReq
)
activity
.
startFlutterActivity
()
}
else
{
when
(
baseReq
)
{
is
ShowMessageFromWX
.
Req
->
{
activity
.
startFlutterActivity
(
wxRequestBundle
=
Bundle
().
apply
{
baseReq
.
toBundle
(
this
)
},
bundle
=
Bundle
().
apply
{
putString
(
KEY_FLUWX_REQUEST_INFO_EXT_MSG
,
baseReq
.
message
.
messageExt
)
})
WXAPiHandler
.
coolBoot
=
false
}
}
}
}
fun
onReq
(
baseReq
:
BaseReq
,
activity
:
Activity
)
{
try
{
val
packageManager
=
activity
.
packageManager
val
appInfo
=
packageManager
.
getApplicationInfo
(
activity
.
packageName
,
PackageManager
.
GET_META_DATA
)
val
defaultHandle
=
appInfo
.
metaData
.
getBoolean
(
"InterruptWeChatRequestByFluwx"
,
true
)
if
(
defaultHandle
)
{
defaultOnReqDelegate
(
baseReq
,
activity
)
}
else
{
customOnReqDelegate
?.
invoke
(
baseReq
,
activity
)
}
}
catch
(
e
:
Exception
)
{
Log
.
i
(
"Fluwx"
,
"can't load meta-data InterruptWeChatRequestByFluwx"
)
}
}
}
\ No newline at end of file
android/src/main/kotlin/com/jarvan/fluwx/handlers/FluwxResponseHandler.kt
deleted
100644 → 0
浏览文件 @
583d58bd
/*
* 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.jarvan.fluwx.FluwxPlugin
import
com.tencent.mm.opensdk.modelbase.BaseResp
import
com.tencent.mm.opensdk.modelbiz.*
import
com.tencent.mm.opensdk.modelmsg.SendAuth
import
com.tencent.mm.opensdk.modelmsg.SendMessageToWX
import
com.tencent.mm.opensdk.modelpay.PayResp
import
io.flutter.plugin.common.MethodChannel
object
FluwxResponseHandler
{
private
const
val
errStr
=
"errStr"
private
const
val
errCode
=
"errCode"
private
const
val
openId
=
"openId"
private
const
val
type
=
"type"
fun
handleResponse
(
response
:
BaseResp
)
{
when
(
response
)
{
is
SendAuth
.
Resp
->
handleAuthResponse
(
response
)
is
SendMessageToWX
.
Resp
->
handleSendMessageResp
(
response
)
is
PayResp
->
handlePayResp
(
response
)
is
WXLaunchMiniProgram
.
Resp
->
handleLaunchMiniProgramResponse
(
response
)
is
SubscribeMessage
.
Resp
->
handleSubscribeMessage
(
response
)
is
WXOpenBusinessWebview
.
Resp
->
handlerWXOpenBusinessWebviewResponse
(
response
)
is
WXOpenCustomerServiceChat
.
Resp
->
handlerWXOpenCustomerServiceChatResponse
(
response
)
is
WXOpenBusinessView
.
Resp
->
handleWXOpenBusinessView
(
response
)
is
ChooseCardFromWXCardPackage
.
Resp
->
handleWXOpenInvoiceResponse
(
response
)
}
}
private
fun
handleWXOpenInvoiceResponse
(
response
:
ChooseCardFromWXCardPackage
.
Resp
)
{
val
result
=
mapOf
(
"cardItemList"
to
response
.
cardItemList
,
"transaction"
to
response
.
transaction
,
"openid"
to
response
.
openId
,
errStr
to
response
.
errStr
,
type
to
response
.
type
,
errCode
to
response
.
errCode
)
FluwxPlugin
.
callingChannel
?.
invokeMethod
(
"onOpenWechatInvoiceResponse"
,
result
)
}
private
fun
handleWXOpenBusinessView
(
response
:
WXOpenBusinessView
.
Resp
)
{
val
result
=
mapOf
(
"openid"
to
response
.
openId
,
"extMsg"
to
response
.
extMsg
,
"businessType"
to
response
.
businessType
,
errStr
to
response
.
errStr
,
type
to
response
.
type
,
errCode
to
response
.
errCode
)
FluwxPlugin
.
callingChannel
?.
invokeMethod
(
"onOpenBusinessViewResponse"
,
result
)
}
private
fun
handleSubscribeMessage
(
response
:
SubscribeMessage
.
Resp
)
{
val
result
=
mapOf
(
"openid"
to
response
.
openId
,
"templateId"
to
response
.
templateID
,
"action"
to
response
.
action
,
"reserved"
to
response
.
reserved
,
"scene"
to
response
.
scene
,
type
to
response
.
type
)
FluwxPlugin
.
callingChannel
?.
invokeMethod
(
"onSubscribeMsgResp"
,
result
)
}
private
fun
handleLaunchMiniProgramResponse
(
response
:
WXLaunchMiniProgram
.
Resp
)
{
val
result
=
mutableMapOf
(
errStr
to
response
.
errStr
,
type
to
response
.
type
,
errCode
to
response
.
errCode
,
openId
to
response
.
openId
)
response
.
extMsg
?.
let
{
result
[
"extMsg"
]
=
response
.
extMsg
}
FluwxPlugin
.
callingChannel
?.
invokeMethod
(
"onLaunchMiniProgramResponse"
,
result
)
}
private
fun
handlePayResp
(
response
:
PayResp
)
{
val
result
=
mapOf
(
"prepayId"
to
response
.
prepayId
,
"returnKey"
to
response
.
returnKey
,
"extData"
to
response
.
extData
,
errStr
to
response
.
errStr
,
type
to
response
.
type
,
errCode
to
response
.
errCode
)
FluwxPlugin
.
callingChannel
?.
invokeMethod
(
"onPayResponse"
,
result
)
}
private
fun
handleSendMessageResp
(
response
:
SendMessageToWX
.
Resp
)
{
val
result
=
mapOf
(
errStr
to
response
.
errStr
,
type
to
response
.
type
,
errCode
to
response
.
errCode
,
openId
to
response
.
openId
)
FluwxPlugin
.
callingChannel
?.
invokeMethod
(
"onShareResponse"
,
result
)
}
private
fun
handleAuthResponse
(
response
:
SendAuth
.
Resp
)
{
val
result
=
mapOf
(
errCode
to
response
.
errCode
,
"code"
to
response
.
code
,
"state"
to
response
.
state
,
"lang"
to
response
.
lang
,
"country"
to
response
.
country
,
errStr
to
response
.
errStr
,
openId
to
response
.
openId
,
"url"
to
response
.
url
,
type
to
response
.
type
)
FluwxPlugin
.
callingChannel
?.
invokeMethod
(
"onAuthResponse"
,
result
)
}
private
fun
handlerWXOpenBusinessWebviewResponse
(
response
:
WXOpenBusinessWebview
.
Resp
)
{
val
result
=
mapOf
(
errCode
to
response
.
errCode
,
"businessType"
to
response
.
businessType
,
"resultInfo"
to
response
.
resultInfo
,
errStr
to
response
.
errStr
,
openId
to
response
.
openId
,
type
to
response
.
type
)
FluwxPlugin
.
callingChannel
?.
invokeMethod
(
"onWXOpenBusinessWebviewResponse"
,
result
)
}
private
fun
handlerWXOpenCustomerServiceChatResponse
(
response
:
WXOpenCustomerServiceChat
.
Resp
)
{
val
result
=
mapOf
(
errCode
to
response
.
errCode
,
errStr
to
response
.
errStr
,
openId
to
response
.
openId
,
type
to
response
.
type
)
FluwxPlugin
.
callingChannel
?.
invokeMethod
(
"onWXOpenCustomerServiceChatResponse"
,
result
)
}
}
\ No newline at end of file
android/src/main/kotlin/com/jarvan/fluwx/handlers/WXAPiHandler.kt
浏览文件 @
1c0802f0
...
...
@@ -30,7 +30,7 @@ import com.tencent.mm.opensdk.utils.ILog
import
io.flutter.plugin.common.MethodCall
import
io.flutter.plugin.common.MethodChannel
object
WXAPiHandler
:
ILog
{
object
WXAPiHandler
{
var
wxApi
:
IWXAPI
?
=
null
...
...
@@ -57,16 +57,6 @@ object WXAPiHandler : ILog {
fun
registerApp
(
call
:
MethodCall
,
result
:
MethodChannel
.
Result
,
context
:
Context
?)
{
context
?.
let
{
with
(
it
)
{
val
appInfo
=
packageManager
.
getApplicationInfo
(
packageName
,
PackageManager
.
GET_META_DATA
)
val
enableLogging
=
appInfo
.
metaData
.
getString
(
"WeChatDebugLogging"
,
""
)
if
(
enableLogging
==
"true"
&&
BuildConfig
.
DEBUG
)
{
startLog
()
}
}
}
if
(
call
.
argument
<
Boolean
?>(
"android"
)
==
false
)
{
return
}
...
...
@@ -118,49 +108,11 @@ object WXAPiHandler : ILog {
}
private
fun
registerWxAPIInternal
(
appId
:
String
,
context
:
Context
)
{
with
(
context
)
{
val
appInfo
=
packageManager
.
getApplicationInfo
(
packageName
,
PackageManager
.
GET_META_DATA
)
val
enableLogging
=
appInfo
.
metaData
.
getString
(
"WeChatDebugLogging"
,
""
)
if
(
enableLogging
==
"true"
&&
BuildConfig
.
DEBUG
)
{
startLog
()
}
}
val
api
=
WXAPIFactory
.
createWXAPI
(
context
.
applicationContext
,
appId
)
registered
=
api
.
registerApp
(
appId
)
wxApi
=
api
}
fun
startLog
()
{
wxApi
?.
setLogImpl
(
this
)
}
override
fun
d
(
p0
:
String
?,
p1
:
String
?)
{
logToFlutter
(
p0
,
p1
)
}
override
fun
i
(
p0
:
String
?,
p1
:
String
?)
{
logToFlutter
(
p0
,
p1
)
}
override
fun
e
(
p0
:
String
?,
p1
:
String
?)
{
logToFlutter
(
p0
,
p1
)
}
override
fun
v
(
p0
:
String
?,
p1
:
String
?)
{
logToFlutter
(
p0
,
p1
)
}
override
fun
w
(
p0
:
String
?,
p1
:
String
?)
{
logToFlutter
(
p0
,
p1
)
}
private
fun
logToFlutter
(
tag
:
String
?,
message
:
String
?){
FluwxPlugin
.
callingChannel
?.
invokeMethod
(
"wechatLog"
,
mapOf
(
"detail"
to
"$tag : $message"
))
}
}
android/src/main/kotlin/com/jarvan/fluwx/utils/FluwxExtensions.kt
浏览文件 @
1c0802f0
...
...
@@ -7,45 +7,36 @@ import android.content.Intent
import
android.content.pm.PackageManager
import
android.os.Bundle
import
android.util.Log
import
com.jarvan.fluwx.FluwxConfigurations
internal
const
val
KEY_FLUWX_REQUEST_INFO_EXT_MSG
=
"KEY_FLUWX_REQUEST_INFO_EXT_MSG"
internal
const
val
KEY_FLUWX_REQUEST_INFO_BUNDLE
=
"KEY_FLUWX_REQUEST_INFO_BUNDLE"
internal
const
val
KEY_FLUWX_EXTRA
=
"KEY_FLUWX_EXTRA"
internal
const
val
FLAG_PAYLOAD_FROM_WECHAT
=
"FLAG_PAYLOAD_FROM_WECHAT"
internal
fun
Activity
.
startFlutterActivity
(
wxRequestBundle
:
Bundle
?
=
null
,
bundle
:
Bundle
?
=
null
,
extra
:
Intent
,
)
{
flutterActivityIntent
()
?.
also
{
intent
->
intent
.
addFluwxExtras
()
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
)
bundle
?.
let
{
intent
.
putExtras
(
it
)
}
wxRequestBundle
?.
let
{
intent
.
putExtra
(
KEY_FLUWX_REQUEST_INFO_BUNDLE
,
it
)
}
intent
.
putExtra
(
KEY_FLUWX_EXTRA
,
extra
)
intent
.
putExtra
(
FLAG_PAYLOAD_FROM_WECHAT
,
true
)
try
{
startActivity
(
intent
)
}
catch
(
e
:
ActivityNotFoundException
)
{
Log
.
w
(
"fluwx"
,
"Can not start activity for Intent: $intent"
)
}
finally
{
finish
()
}
}
}
internal
fun
Context
.
flutterActivityIntent
():
Intent
?
{
val
appInfo
=
packageManager
.
getApplicationInfo
(
packageName
,
PackageManager
.
GET_META_DATA
)
val
flutterActivity
=
appInfo
.
metaData
.
getString
(
"FluwxFlutterActivity"
,
""
)
return
if
(
flutterActivity
.
isBlank
())
{
return
if
(
FluwxConfigurations
.
flutterActivity
.
isBlank
())
{
packageManager
.
getLaunchIntentForPackage
(
packageName
)
}
else
{
Intent
().
also
{
it
.
setClassName
(
this
,
"${packageName}.$
flutterActivity
"
)
it
.
setClassName
(
this
,
"${packageName}.$
{FluwxConfigurations.flutterActivity}
"
)
}
}
}
...
...
@@ -53,3 +44,11 @@ internal fun Context.flutterActivityIntent(): Intent? {
internal
fun
Intent
.
addFluwxExtras
()
{
putExtra
(
"fluwx_payload_from_fluwx"
,
true
)
}
internal
fun
Intent
.
readWeChatCallbackIntent
():
Intent
?
{
return
if
(
getBooleanExtra
(
FLAG_PAYLOAD_FROM_WECHAT
,
false
))
{
getParcelableExtra
(
KEY_FLUWX_EXTRA
)
}
else
{
null
}
}
android/src/main/kotlin/com/jarvan/fluwx/wxapi/FluwxWXEntryActivity.kt
浏览文件 @
1c0802f0
...
...
@@ -17,67 +17,24 @@ package com.jarvan.fluwx.wxapi
import
android.app.Activity
import
android.content.Intent
import
android.content.pm.PackageManager
import
android.os.Bundle
import
com.jarvan.fluwx.FluwxHelper
import
com.jarvan.fluwx.handlers.FluwxResponseHandler
import
com.jarvan.fluwx.handlers.FluwxRequestHandler
import
com.jarvan.fluwx.handlers.WXAPiHandler
import
com.jarvan.fluwx.utils.flutterActivityIntent
import
com.jarvan.fluwx.utils.startFlutterActivity
import
com.tencent.mm.opensdk.modelbase.BaseReq
import
com.tencent.mm.opensdk.modelbase.BaseResp
import
com.tencent.mm.opensdk.openapi.IWXAPIEventHandler
import
io.flutter.Log
open
class
FluwxWXEntryActivity
:
Activity
()
,
IWXAPIEventHandler
{
open
class
FluwxWXEntryActivity
:
Activity
()
{
// IWXAPI 是第三方app和微信通信的openapi接口
public
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
try
{
if
(!
WXAPiHandler
.
wxApiRegistered
)
{
val
wechatAppId
=
FluwxHelper
.
appId
if
(
wechatAppId
.
isNotBlank
())
{
WXAPiHandler
.
setupWxApi
(
wechatAppId
,
this
)
WXAPiHandler
.
coolBoot
=
true
}
else
{
Log
.
w
(
"fluwx"
,
"can't load meta-data weChatAppId"
)
}
}
WXAPiHandler
.
wxApi
?.
handleIntent
(
intent
,
this
)
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
this
.
startFlutterActivity
()
}
startFlutterActivity
(
intent
)
finish
()
}
override
fun
onNewIntent
(
intent
:
Intent
)
{
super
.
onNewIntent
(
intent
)
setIntent
(
intent
)
try
{
WXAPiHandler
.
wxApi
?.
handleIntent
(
intent
,
this
)
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
this
.
startFlutterActivity
()
}
}
override
fun
onReq
(
baseReq
:
BaseReq
)
{
// FIXME: 可能是官方的Bug,从微信拉起APP的Intent类型不对,无法跳转回Flutter Activity
// 稳定复现场景:微信版本为7.0.5,小程序SDK为2.7.7
FluwxRequestHandler
.
onReq
(
baseReq
,
this
)
}
// 第三方应用发送到微信的请求处理后的响应结果,会回调到该方法
override
fun
onResp
(
resp
:
BaseResp
)
{
FluwxResponseHandler
.
handleResponse
(
resp
)
startFlutterActivity
(
intent
)
finish
()
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论