Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-fluwx
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx-fluwx
Commits
7dd5491f
提交
7dd5491f
authored
3月 08, 2020
作者:
JarvanMo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
compatible old flutter(<1.12)
上级
f254588d
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
66 行增加
和
20 行删除
+66
-20
FluwxPlugin.kt
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
+5
-2
FluwxShareHandlerEmbedding.kt
...n/com/jarvan/fluwx/handlers/FluwxShareHandlerEmbedding.kt
+50
-5
WeChatImages.kt
android/src/main/kotlin/com/jarvan/fluwx/io/WeChatImages.kt
+11
-13
没有找到文件。
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
浏览文件 @
7dd5491f
package
com.jarvan.fluwx
package
com.jarvan.fluwx
import
androidx.annotation.NonNull
import
androidx.annotation.NonNull
import
com.jarvan.fluwx.handlers.*
import
com.jarvan.fluwx.handlers.FluwxAuthHandler
import
com.jarvan.fluwx.handlers.FluwxAuthHandler
import
com.jarvan.fluwx.handlers.FluwxShareHandler
import
com.jarvan.fluwx.handlers.FluwxShareHandler
import
com.jarvan.fluwx.handlers.WXAPiHandler
import
com.jarvan.fluwx.handlers.FluwxShareHandlerCompat
import
com.jarvan.fluwx.handlers.FluwxShareHandlerEmbedding
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
import
com.tencent.mm.opensdk.modelbiz.WXOpenBusinessWebview
import
com.tencent.mm.opensdk.modelbiz.WXOpenBusinessWebview
...
@@ -27,6 +29,7 @@ public class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
...
@@ -27,6 +29,7 @@ public class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
val
authHandler
=
FluwxAuthHandler
(
channel
)
val
authHandler
=
FluwxAuthHandler
(
channel
)
channel
.
setMethodCallHandler
(
FluwxPlugin
().
apply
{
channel
.
setMethodCallHandler
(
FluwxPlugin
().
apply
{
this
.
authHandler
=
authHandler
this
.
authHandler
=
authHandler
this
.
shareHandler
=
FluwxShareHandlerCompat
(
registrar
)
})
})
}
}
}
}
...
@@ -39,7 +42,7 @@ public class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
...
@@ -39,7 +42,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
)
authHandler
=
FluwxAuthHandler
(
channel
)
authHandler
=
FluwxAuthHandler
(
channel
)
shareHandler
=
FluwxShareHandler
(
flutterPluginBinding
.
flutterAssets
,
flutterPluginBinding
.
applicationContext
)
shareHandler
=
FluwxShareHandler
Embedding
(
flutterPluginBinding
.
flutterAssets
,
flutterPluginBinding
.
applicationContext
)
}
}
override
fun
onMethodCall
(
@NonNull
call
:
MethodCall
,
@NonNull
result
:
Result
)
{
override
fun
onMethodCall
(
@NonNull
call
:
MethodCall
,
@NonNull
result
:
Result
)
{
...
...
android/src/main/kotlin/com/jarvan/fluwx/handlers/FluwxShareHandler.kt
→
android/src/main/kotlin/com/jarvan/fluwx/handlers/FluwxShareHandler
Embedding
.kt
浏览文件 @
7dd5491f
...
@@ -3,6 +3,9 @@ package com.jarvan.fluwx.handlers
...
@@ -3,6 +3,9 @@ package com.jarvan.fluwx.handlers
import
android.Manifest
import
android.Manifest
import
android.content.Context
import
android.content.Context
import
android.content.pm.PackageManager
import
android.content.pm.PackageManager
import
android.content.res.AssetFileDescriptor
import
android.net.Uri
import
android.text.TextUtils
import
androidx.core.content.ContextCompat
import
androidx.core.content.ContextCompat
import
androidx.fragment.app.Fragment
import
androidx.fragment.app.Fragment
import
com.jarvan.fluwx.io.ImagesIO
import
com.jarvan.fluwx.io.ImagesIO
...
@@ -14,6 +17,7 @@ import com.tencent.mm.opensdk.modelmsg.*
...
@@ -14,6 +17,7 @@ import com.tencent.mm.opensdk.modelmsg.*
import
io.flutter.embedding.engine.plugins.FlutterPlugin
import
io.flutter.embedding.engine.plugins.FlutterPlugin
import
io.flutter.plugin.common.MethodCall
import
io.flutter.plugin.common.MethodCall
import
io.flutter.plugin.common.MethodChannel
import
io.flutter.plugin.common.MethodChannel
import
io.flutter.plugin.common.PluginRegistry
import
kotlinx.coroutines.*
import
kotlinx.coroutines.*
import
java.util.*
import
java.util.*
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.CoroutineContext
...
@@ -23,7 +27,40 @@ import kotlin.coroutines.CoroutineContext
...
@@ -23,7 +27,40 @@ import kotlin.coroutines.CoroutineContext
* 冷风如刀,以大地为砧板,视众生为鱼肉。
* 冷风如刀,以大地为砧板,视众生为鱼肉。
* 万里飞雪,将穹苍作烘炉,熔万物为白银。
* 万里飞雪,将穹苍作烘炉,熔万物为白银。
**/
**/
internal
class
FluwxShareHandler
(
private
val
flutterAssets
:
FlutterPlugin
.
FlutterAssets
,
private
val
context
:
Context
)
:
CoroutineScope
{
internal
class
FluwxShareHandlerEmbedding
(
private
val
flutterAssets
:
FlutterPlugin
.
FlutterAssets
,
override
val
context
:
Context
)
:
FluwxShareHandler
{
override
val
assetFileDescriptor
:
(
String
)
->
AssetFileDescriptor
=
{
val
uri
=
Uri
.
parse
(
it
)
val
packageName
=
uri
.
getQueryParameter
(
"package"
)
val
subPath
=
if
(
packageName
.
isNullOrBlank
())
{
flutterAssets
.
getAssetFilePathBySubpath
(
uri
.
path
.
orEmpty
())
}
else
{
flutterAssets
.
getAssetFilePathBySubpath
(
uri
.
path
.
orEmpty
(),
packageName
)
}
context
.
assets
.
openFd
(
subPath
)
}
override
val
job
:
Job
=
Job
()
}
internal
class
FluwxShareHandlerCompat
(
private
val
registrar
:
PluginRegistry
.
Registrar
)
:
FluwxShareHandler
{
override
val
assetFileDescriptor
:
(
String
)
->
AssetFileDescriptor
=
{
val
uri
=
Uri
.
parse
(
it
)
val
packageName
=
uri
.
getQueryParameter
(
"package"
)
val
key
=
if
(
TextUtils
.
isEmpty
(
packageName
))
{
registrar
.
lookupKeyForAsset
(
uri
.
path
)
}
else
{
registrar
.
lookupKeyForAsset
(
uri
.
path
,
packageName
)
}
context
.
assets
.
openFd
(
key
)
}
override
val
context
:
Context
=
registrar
.
context
().
applicationContext
override
val
job
:
Job
=
Job
()
}
internal
interface
FluwxShareHandler
:
CoroutineScope
{
companion
object
{
companion
object
{
const
val
SHARE_IMAGE_THUMB_LENGTH
=
32
*
1024
const
val
SHARE_IMAGE_THUMB_LENGTH
=
32
*
1024
private
const
val
keyTitle
=
"title"
private
const
val
keyTitle
=
"title"
...
@@ -61,6 +98,7 @@ internal class FluwxShareHandler(private val flutterAssets: FlutterPlugin.Flutte
...
@@ -61,6 +98,7 @@ internal class FluwxShareHandler(private val flutterAssets: FlutterPlugin.Flutte
result
.
success
(
WXAPiHandler
.
wxApi
?.
sendReq
(
req
))
result
.
success
(
WXAPiHandler
.
wxApi
?.
sendReq
(
req
))
}
}
private
fun
shareMiniProgram
(
call
:
MethodCall
,
result
:
MethodChannel
.
Result
)
{
private
fun
shareMiniProgram
(
call
:
MethodCall
,
result
:
MethodChannel
.
Result
)
{
val
miniProgramObj
=
WXMiniProgramObject
()
val
miniProgramObj
=
WXMiniProgramObject
()
miniProgramObj
.
webpageUrl
=
call
.
argument
(
"webPageUrl"
)
// 兼容低版本的网页链接
miniProgramObj
.
webpageUrl
=
call
.
argument
(
"webPageUrl"
)
// 兼容低版本的网页链接
...
@@ -84,8 +122,8 @@ internal class FluwxShareHandler(private val flutterAssets: FlutterPlugin.Flutte
...
@@ -84,8 +122,8 @@ internal class FluwxShareHandler(private val flutterAssets: FlutterPlugin.Flutte
private
fun
shareImage
(
call
:
MethodCall
,
result
:
MethodChannel
.
Result
)
{
private
fun
shareImage
(
call
:
MethodCall
,
result
:
MethodChannel
.
Result
)
{
launch
{
launch
{
val
sourceImage
=
WeChatImage
.
createWeChatImage
(
call
.
argument
(
"source"
)
val
map
:
Map
<
String
,
Any
>
=
call
.
argument
(
"source"
)
?:
mapOf
(
)
?:
mapOf
(),
flutterAssets
,
context
)
val
sourceImage
=
WeChatImage
.
createWeChatImage
(
map
,
assetFileDescriptor
((
map
[
"source"
]
as
?
String
).
orEmpty
())
,
context
)
val
thumbData
=
readThumbnailByteArray
(
call
)
val
thumbData
=
readThumbnailByteArray
(
call
)
val
sourceByteArray
=
sourceImage
.
readByteArray
()
val
sourceByteArray
=
sourceImage
.
readByteArray
()
...
@@ -120,6 +158,7 @@ internal class FluwxShareHandler(private val flutterAssets: FlutterPlugin.Flutte
...
@@ -120,6 +158,7 @@ internal class FluwxShareHandler(private val flutterAssets: FlutterPlugin.Flutte
}
}
}
}
private
fun
shareMusic
(
call
:
MethodCall
,
result
:
MethodChannel
.
Result
)
{
private
fun
shareMusic
(
call
:
MethodCall
,
result
:
MethodChannel
.
Result
)
{
val
music
=
WXMusicObject
()
val
music
=
WXMusicObject
()
val
musicUrl
:
String
?
=
call
.
argument
(
"musicUrl"
)
val
musicUrl
:
String
?
=
call
.
argument
(
"musicUrl"
)
...
@@ -210,7 +249,7 @@ internal class FluwxShareHandler(private val flutterAssets: FlutterPlugin.Flutte
...
@@ -210,7 +249,7 @@ internal class FluwxShareHandler(private val flutterAssets: FlutterPlugin.Flutte
private
suspend
fun
readThumbnailByteArray
(
call
:
MethodCall
):
ByteArray
?
{
private
suspend
fun
readThumbnailByteArray
(
call
:
MethodCall
):
ByteArray
?
{
val
thumbnailMap
:
Map
<
String
,
Any
>?
=
call
.
argument
(
keyThumbnail
)
val
thumbnailMap
:
Map
<
String
,
Any
>?
=
call
.
argument
(
keyThumbnail
)
return
thumbnailMap
?.
run
{
return
thumbnailMap
?.
run
{
val
thumbnailImage
=
WeChatImage
.
createWeChatImage
(
thumbnailMap
,
flutterAssets
,
context
)
val
thumbnailImage
=
WeChatImage
.
createWeChatImage
(
thumbnailMap
,
assetFileDescriptor
((
thumbnailMap
[
"source"
]
as
?
String
).
orEmpty
())
,
context
)
val
thumbnailImageIO
=
ImagesIOIml
(
thumbnailImage
)
val
thumbnailImageIO
=
ImagesIOIml
(
thumbnailImage
)
compressThumbnail
(
thumbnailImageIO
)
compressThumbnail
(
thumbnailImageIO
)
}
}
...
@@ -234,12 +273,17 @@ internal class FluwxShareHandler(private val flutterAssets: FlutterPlugin.Flutte
...
@@ -234,12 +273,17 @@ internal class FluwxShareHandler(private val flutterAssets: FlutterPlugin.Flutte
}
}
}
}
val
context
:
Context
val
assetFileDescriptor
:
(
String
)
->
AssetFileDescriptor
override
val
coroutineContext
:
CoroutineContext
override
val
coroutineContext
:
CoroutineContext
get
()
=
Dispatchers
.
Main
+
job
get
()
=
Dispatchers
.
Main
+
job
private
val
job
=
Job
()
val
job
:
Job
fun
onDestroy
()
{
fun
onDestroy
()
{
job
.
cancel
()
job
.
cancel
()
}
}
}
}
\ No newline at end of file
android/src/main/kotlin/com/jarvan/fluwx/io/WeChatImages.kt
浏览文件 @
7dd5491f
...
@@ -2,9 +2,7 @@ package com.jarvan.fluwx.io
...
@@ -2,9 +2,7 @@ package com.jarvan.fluwx.io
import
android.content.Context
import
android.content.Context
import
android.content.res.AssetFileDescriptor
import
android.content.res.AssetFileDescriptor
import
android.net.Uri
import
android.util.Log
import
android.util.Log
import
io.flutter.embedding.engine.plugins.FlutterPlugin
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.withContext
import
kotlinx.coroutines.withContext
import
okhttp3.OkHttpClient
import
okhttp3.OkHttpClient
...
@@ -127,22 +125,22 @@ interface WeChatImage {
...
@@ -127,22 +125,22 @@ interface WeChatImage {
// ASSET,
// ASSET,
// FILE,
// FILE,
// BINARY,
// BINARY,
fun
createWeChatImage
(
params
:
Map
<
String
,
Any
>,
flutterAssets
:
FlutterPlugin
.
FlutterAssets
,
context
:
Context
):
WeChatImage
{
fun
createWeChatImage
(
params
:
Map
<
String
,
Any
>,
assetFileDescriptor
:
AssetFileDescriptor
,
context
:
Context
):
WeChatImage
{
// Map toMap() => {"source": source, "schema": schema.index, "suffix": suffix};
// Map toMap() => {"source": source, "schema": schema.index, "suffix": suffix};
val
suffix
=
(
params
[
"suffix"
]
as
String
?)
?:
".jpeg"
val
suffix
=
(
params
[
"suffix"
]
as
String
?)
?:
".jpeg"
return
when
((
params
[
"schema"
]
as
?
Int
)
?:
0
)
{
return
when
((
params
[
"schema"
]
as
?
Int
)
?:
0
)
{
0
->
WeChatNetworkImage
(
source
=
(
params
[
"source"
]
as
?
String
).
orEmpty
(),
suffix
=
suffix
)
0
->
WeChatNetworkImage
(
source
=
(
params
[
"source"
]
as
?
String
).
orEmpty
(),
suffix
=
suffix
)
1
->
{
1
->
{
val
source
=
(
params
[
"source"
]
as
?
String
).
orEmpty
()
//
val source = (params["source"] as? String).orEmpty()
val
uri
=
Uri
.
parse
(
source
)
//
val uri = Uri.parse(source)
val
packageName
=
uri
.
getQueryParameter
(
"package"
)
//
val packageName = uri.getQueryParameter("package")
val
subPath
=
if
(
packageName
.
isNullOrBlank
())
{
//
val subPath = if (packageName.isNullOrBlank()) {
flutterAssets
.
getAssetFilePathBySubpath
(
uri
.
path
.
orEmpty
())
//
flutterAssets.getAssetFilePathBySubpath(uri.path.orEmpty())
}
else
{
//
} else {
flutterAssets
.
getAssetFilePathBySubpath
(
uri
.
path
.
orEmpty
(),
packageName
)
//
flutterAssets.getAssetFilePathBySubpath(uri.path.orEmpty(), packageName)
}
//
}
WeChatAssetImage
(
source
=
context
.
assets
.
openFd
(
subPath
)
,
suffix
=
suffix
)
WeChatAssetImage
(
source
=
assetFileDescriptor
,
suffix
=
suffix
)
}
}
2
->
WeChatFileImage
(
source
=
(
params
[
"source"
]
as
?
String
).
orEmpty
(),
suffix
=
suffix
)
2
->
WeChatFileImage
(
source
=
(
params
[
"source"
]
as
?
String
).
orEmpty
(),
suffix
=
suffix
)
3
->
WeChatMemoryImage
(
source
=
(
params
[
"source"
]
as
?
ByteArray
)
3
->
WeChatMemoryImage
(
source
=
(
params
[
"source"
]
as
?
ByteArray
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论