Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-fluwx
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx-fluwx
Commits
ff367cf4
提交
ff367cf4
authored
8月 14, 2021
作者:
JarvanMo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support OpenCustomerServiceChat on android
上级
1b7ff6e9
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
79 行增加
和
36 行删除
+79
-36
FluwxPlugin.kt
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
+15
-0
FluwxRequestHandler.kt
...n/kotlin/com/jarvan/fluwx/handlers/FluwxRequestHandler.kt
+1
-1
FluwxResponseHandler.kt
.../kotlin/com/jarvan/fluwx/handlers/FluwxResponseHandler.kt
+13
-0
ImagesIO.kt
android/src/main/kotlin/com/jarvan/fluwx/io/ImagesIO.kt
+35
-25
FluwxWXEntryActivity.kt
...ain/kotlin/com/jarvan/fluwx/wxapi/FluwxWXEntryActivity.kt
+2
-2
build.gradle
example/android/app/build.gradle
+3
-3
MainActivity.kt
.../src/main/kotlin/com/jarvan/fluwx_example/MainActivity.kt
+1
-1
build.gradle
example/android/build.gradle
+2
-4
wechat_response.dart
lib/src/response/wechat_response.dart
+7
-0
没有找到文件。
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
浏览文件 @
ff367cf4
...
@@ -16,6 +16,10 @@ import io.flutter.plugin.common.MethodChannel
...
@@ -16,6 +16,10 @@ import io.flutter.plugin.common.MethodChannel
import
io.flutter.plugin.common.MethodChannel.MethodCallHandler
import
io.flutter.plugin.common.MethodChannel.MethodCallHandler
import
io.flutter.plugin.common.MethodChannel.Result
import
io.flutter.plugin.common.MethodChannel.Result
import
io.flutter.plugin.common.PluginRegistry
import
io.flutter.plugin.common.PluginRegistry
import
com.tencent.mm.opensdk.modelbiz.WXOpenCustomerServiceChat
/** FluwxPlugin */
/** FluwxPlugin */
class
FluwxPlugin
:
FlutterPlugin
,
MethodCallHandler
,
ActivityAware
,
PluginRegistry
.
NewIntentListener
{
class
FluwxPlugin
:
FlutterPlugin
,
MethodCallHandler
,
ActivityAware
,
PluginRegistry
.
NewIntentListener
{
...
@@ -79,6 +83,7 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,PluginRegist
...
@@ -79,6 +83,7 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,PluginRegist
call
.
method
.
startsWith
(
"share"
)
->
shareHandler
?.
share
(
call
,
result
)
call
.
method
.
startsWith
(
"share"
)
->
shareHandler
?.
share
(
call
,
result
)
call
.
method
==
"isWeChatInstalled"
->
WXAPiHandler
.
checkWeChatInstallation
(
result
)
call
.
method
==
"isWeChatInstalled"
->
WXAPiHandler
.
checkWeChatInstallation
(
result
)
call
.
method
==
"getExtMsg"
->
getExtMsg
(
result
)
call
.
method
==
"getExtMsg"
->
getExtMsg
(
result
)
call
.
method
==
"openWeChatCustomerServiceChat"
->
openWeChatCustomerServiceChat
(
call
,
result
)
else
->
result
.
notImplemented
()
else
->
result
.
notImplemented
()
}
}
}
}
...
@@ -145,6 +150,16 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,PluginRegist
...
@@ -145,6 +150,16 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,PluginRegist
result
.
success
(
WXAPiHandler
.
wxApi
?.
sendReq
(
request
))
result
.
success
(
WXAPiHandler
.
wxApi
?.
sendReq
(
request
))
}
}
private
fun
openWeChatCustomerServiceChat
(
call
:
MethodCall
,
result
:
Result
)
{
val
url
=
call
.
argument
<
String
>(
"url"
)
?:
""
val
corpId
=
call
.
argument
<
String
>(
"corpId"
)
?:
""
val
request
=
WXOpenCustomerServiceChat
.
Req
()
request
.
corpId
=
corpId
// 企业ID
request
.
url
=
url
result
.
success
(
WXAPiHandler
.
wxApi
?.
sendReq
(
request
))
}
private
fun
signAutoDeduct
(
call
:
MethodCall
,
result
:
Result
)
{
private
fun
signAutoDeduct
(
call
:
MethodCall
,
result
:
Result
)
{
val
appId
:
String
=
call
.
argument
<
String
>(
"appid"
)
?:
""
val
appId
:
String
=
call
.
argument
<
String
>(
"appid"
)
?:
""
val
mchId
=
call
.
argument
<
String
>(
"mch_id"
)
?:
""
val
mchId
=
call
.
argument
<
String
>(
"mch_id"
)
?:
""
...
...
android/src/main/kotlin/com/jarvan/fluwx/handlers/FluwxRequestHandler.kt
浏览文件 @
ff367cf4
...
@@ -88,7 +88,7 @@ object FluwxRequestHandler {
...
@@ -88,7 +88,7 @@ object FluwxRequestHandler {
fun
onReq
(
baseReq
:
BaseReq
,
activity
:
Activity
)
{
fun
onReq
(
baseReq
:
BaseReq
,
activity
:
Activity
)
{
try
{
try
{
val
packageManager
=
activity
.
packageManager
val
packageManager
=
activity
.
packageManager
va
r
appInfo
=
packageManager
.
getApplicationInfo
(
activity
.
packageName
,
PackageManager
.
GET_META_DATA
)
va
l
appInfo
=
packageManager
.
getApplicationInfo
(
activity
.
packageName
,
PackageManager
.
GET_META_DATA
)
val
defaultHandle
=
appInfo
.
metaData
.
getBoolean
(
"handleWeChatRequestByFluwx"
,
true
)
val
defaultHandle
=
appInfo
.
metaData
.
getBoolean
(
"handleWeChatRequestByFluwx"
,
true
)
if
(
defaultHandle
)
{
if
(
defaultHandle
)
{
defaultOnReqDelegate
(
baseReq
,
activity
)
defaultOnReqDelegate
(
baseReq
,
activity
)
...
...
android/src/main/kotlin/com/jarvan/fluwx/handlers/FluwxResponseHandler.kt
浏览文件 @
ff367cf4
...
@@ -20,6 +20,7 @@ import com.tencent.mm.opensdk.modelbase.BaseResp
...
@@ -20,6 +20,7 @@ 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
import
com.tencent.mm.opensdk.modelbiz.WXOpenBusinessWebview
import
com.tencent.mm.opensdk.modelbiz.WXOpenBusinessWebview
import
com.tencent.mm.opensdk.modelbiz.WXOpenCustomerServiceChat
import
com.tencent.mm.opensdk.modelmsg.SendAuth
import
com.tencent.mm.opensdk.modelmsg.SendAuth
import
com.tencent.mm.opensdk.modelmsg.SendMessageToWX
import
com.tencent.mm.opensdk.modelmsg.SendMessageToWX
import
com.tencent.mm.opensdk.modelpay.PayResp
import
com.tencent.mm.opensdk.modelpay.PayResp
...
@@ -40,6 +41,7 @@ object FluwxResponseHandler {
...
@@ -40,6 +41,7 @@ object FluwxResponseHandler {
is
WXLaunchMiniProgram
.
Resp
->
handleLaunchMiniProgramResponse
(
response
)
is
WXLaunchMiniProgram
.
Resp
->
handleLaunchMiniProgramResponse
(
response
)
is
SubscribeMessage
.
Resp
->
handleSubscribeMessage
(
response
)
is
SubscribeMessage
.
Resp
->
handleSubscribeMessage
(
response
)
is
WXOpenBusinessWebview
.
Resp
->
handlerWXOpenBusinessWebviewResponse
(
response
)
is
WXOpenBusinessWebview
.
Resp
->
handlerWXOpenBusinessWebviewResponse
(
response
)
is
WXOpenCustomerServiceChat
.
Resp
->
handlerWXOpenCustomerServiceChatResponse
(
response
)
}
}
}
}
...
@@ -119,4 +121,14 @@ object FluwxResponseHandler {
...
@@ -119,4 +121,14 @@ object FluwxResponseHandler {
FluwxPlugin
.
callingChannel
?.
invokeMethod
(
"onWXOpenBusinessWebviewResponse"
,
result
)
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/io/ImagesIO.kt
浏览文件 @
ff367cf4
...
@@ -4,10 +4,11 @@ import android.content.Context
...
@@ -4,10 +4,11 @@ import android.content.Context
import
android.graphics.Bitmap
import
android.graphics.Bitmap
import
android.graphics.Bitmap.CompressFormat
import
android.graphics.Bitmap.CompressFormat
import
android.graphics.BitmapFactory
import
android.graphics.BitmapFactory
import
id.zelory.compressor.Compressor
import
id.zelory.compressor.constraint.size
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.withContext
import
kotlinx.coroutines.withContext
import
okio.*
import
okio.*
import
top.zibin.luban.Luban
import
java.io.*
import
java.io.*
import
java.io.IOException
import
java.io.IOException
import
java.util.*
import
java.util.*
...
@@ -22,29 +23,31 @@ class ImagesIOIml(override val image: WeChatFile) : ImagesIO {
...
@@ -22,29 +23,31 @@ class ImagesIOIml(override val image: WeChatFile) : ImagesIO {
override
suspend
fun
readByteArray
():
ByteArray
=
image
.
readByteArray
()
override
suspend
fun
readByteArray
():
ByteArray
=
image
.
readByteArray
()
override
suspend
fun
compressedByteArray
(
context
:
Context
,
maxSize
:
Int
):
ByteArray
=
withContext
(
Dispatchers
.
IO
)
{
override
suspend
fun
compressedByteArray
(
context
:
Context
,
maxSize
:
Int
):
ByteArray
=
val
originalByteArray
=
readByteArray
()
withContext
(
Dispatchers
.
IO
)
{
if
(
originalByteArray
.
isEmpty
())
val
originalByteArray
=
readByteArray
()
return
@withContext
originalByteArray
if
(
originalByteArray
.
isEmpty
())
return
@withContext
originalByteArray
val
originFile
=
inputStreamToFile
(
ByteArrayInputStream
(
originalByteArray
))
val
compressedFile
=
Luban
val
originFile
=
inputStreamToFile
(
ByteArrayInputStream
(
originalByteArray
))
.
with
(
context
)
if
(
image
.
suffix
.
contains
(
"gif"
))
{
.
ignoreBy
(
maxSize
)
return
@withContext
originalByteArray
.
setTargetDir
(
context
.
cacheDir
.
absolutePath
)
}
.
get
(
originFile
.
absolutePath
)
val
compressedFile
=
Compressor
.
compress
(
context
,
originFile
)
{
size
(
maxFileSize
=
maxSize
*
1024L
)
if
(
compressedFile
.
length
()
<
maxSize
)
{
}
val
source
=
compressedFile
.
source
()
val
bufferedSource
=
source
.
buffer
()
if
(
compressedFile
.
length
()
<
maxSize
)
{
val
bytes
=
bufferedSource
.
readByteArray
()
val
source
=
compressedFile
.
source
()
source
.
close
()
val
bufferedSource
=
source
.
buffer
()
bufferedSource
.
close
()
val
bytes
=
bufferedSource
.
readByteArray
()
bytes
source
.
close
()
}
else
{
bufferedSource
.
close
()
createScaledBitmapWithRatio
(
compressedFile
,
maxSize
)
bytes
}
else
{
createScaledBitmapWithRatio
(
compressedFile
,
maxSize
)
}
}
}
}
private
fun
inputStreamToFile
(
inputStream
:
InputStream
):
File
{
private
fun
inputStreamToFile
(
inputStream
:
InputStream
):
File
{
val
file
=
File
.
createTempFile
(
UUID
.
randomUUID
().
toString
(),
image
.
suffix
)
val
file
=
File
.
createTempFile
(
UUID
.
randomUUID
().
toString
(),
image
.
suffix
)
...
@@ -67,7 +70,11 @@ class ImagesIOIml(override val image: WeChatFile) : ImagesIO {
...
@@ -67,7 +70,11 @@ class ImagesIOIml(override val image: WeChatFile) : ImagesIO {
return
bmpToByteArray
(
result
,
image
.
suffix
)
?:
byteArrayOf
()
return
bmpToByteArray
(
result
,
image
.
suffix
)
?:
byteArrayOf
()
}
}
private
fun
createScaledBitmapWithRatio
(
bitmap
:
Bitmap
,
maxLength
:
Int
,
recycle
:
Boolean
):
Bitmap
?
{
private
fun
createScaledBitmapWithRatio
(
bitmap
:
Bitmap
,
maxLength
:
Int
,
recycle
:
Boolean
):
Bitmap
?
{
var
result
=
bitmap
var
result
=
bitmap
while
(
true
)
{
while
(
true
)
{
val
ratio
=
maxLength
.
toDouble
()
/
result
.
byteCount
val
ratio
=
maxLength
.
toDouble
()
/
result
.
byteCount
...
@@ -88,7 +95,10 @@ class ImagesIOIml(override val image: WeChatFile) : ImagesIO {
...
@@ -88,7 +95,10 @@ class ImagesIOIml(override val image: WeChatFile) : ImagesIO {
return
result
return
result
}
}
private
fun
bmpToByteArray
(
bitmap
:
Bitmap
,
suffix
:
String
):
ByteArray
?
{
// int bytes = bitmap.getByteCount();
private
fun
bmpToByteArray
(
bitmap
:
Bitmap
,
suffix
:
String
):
ByteArray
?
{
// int bytes = bitmap.getByteCount();
val
byteArrayOutputStream
=
ByteArrayOutputStream
()
val
byteArrayOutputStream
=
ByteArrayOutputStream
()
var
format
=
CompressFormat
.
PNG
var
format
=
CompressFormat
.
PNG
...
...
android/src/main/kotlin/com/jarvan/fluwx/wxapi/FluwxWXEntryActivity.kt
浏览文件 @
ff367cf4
...
@@ -37,12 +37,12 @@ open class FluwxWXEntryActivity : Activity(), IWXAPIEventHandler {
...
@@ -37,12 +37,12 @@ open class FluwxWXEntryActivity : Activity(), IWXAPIEventHandler {
try
{
try
{
if
(!
WXAPiHandler
.
wxApiRegistered
)
{
if
(!
WXAPiHandler
.
wxApiRegistered
)
{
va
r
appInfo
=
packageManager
.
getApplicationInfo
(
packageName
,
PackageManager
.
GET_META_DATA
)
va
l
appInfo
=
packageManager
.
getApplicationInfo
(
packageName
,
PackageManager
.
GET_META_DATA
)
val
wechatAppId
=
appInfo
.
metaData
.
getString
(
"weChatAppId"
)
val
wechatAppId
=
appInfo
.
metaData
.
getString
(
"weChatAppId"
)
if
(
wechatAppId
!=
null
){
if
(
wechatAppId
!=
null
){
WXAPiHandler
.
setupWxApi
(
wechatAppId
,
this
)
WXAPiHandler
.
setupWxApi
(
wechatAppId
,
this
)
WXAPiHandler
.
setCoolBool
(
true
)
WXAPiHandler
.
setCoolBool
(
true
)
Log
.
d
(
"fluwx"
,
"weChatAppId:
"
+
wechatAppId
)
Log
.
d
(
"fluwx"
,
"weChatAppId:
$wechatAppId"
)
}
else
{
}
else
{
Log
.
e
(
"fluwx"
,
"can't load meta-data weChatAppId"
)
Log
.
e
(
"fluwx"
,
"can't load meta-data weChatAppId"
)
}
}
...
...
example/android/app/build.gradle
浏览文件 @
ff367cf4
...
@@ -73,7 +73,7 @@ flutter {
...
@@ -73,7 +73,7 @@ flutter {
dependencies
{
dependencies
{
implementation
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation
'junit:junit:4.12'
testImplementation
'junit:junit:4.1
3.
2'
androidTestImplementation
'androidx.test:runner:1.
2
.0'
androidTestImplementation
'androidx.test:runner:1.
4
.0'
androidTestImplementation
'androidx.test.espresso:espresso-core:3.
2
.0'
androidTestImplementation
'androidx.test.espresso:espresso-core:3.
4
.0'
}
}
example/android/app/src/main/kotlin/com/jarvan/fluwx_example/MainActivity.kt
浏览文件 @
ff367cf4
...
@@ -16,7 +16,7 @@ class MainActivity: FlutterActivity() {
...
@@ -16,7 +16,7 @@ class MainActivity: FlutterActivity() {
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
//If you didn't configure WxAPI, add the following code
//If you didn't configure WxAPI, add the following code
WXAPiHandler
.
setupWxApi
(
"wxd930ea5d5a258f4f"
,
this
)
//
WXAPiHandler.setupWxApi("wxd930ea5d5a258f4f",this)
//Get Ext-Info from Intent.
//Get Ext-Info from Intent.
FluwxRequestHandler
.
handleRequestInfoFromIntent
(
intent
)
FluwxRequestHandler
.
handleRequestInfoFromIntent
(
intent
)
}
}
...
...
example/android/build.gradle
浏览文件 @
ff367cf4
buildscript
{
buildscript
{
ext
.
kotlin_version
=
'1.
4.10
'
ext
.
kotlin_version
=
'1.
5.21
'
repositories
{
repositories
{
google
()
google
()
jcenter
()
mavenCentral
()
mavenCentral
()
}
}
dependencies
{
dependencies
{
classpath
'com.android.tools.build:gradle:4.1.
0
'
classpath
'com.android.tools.build:gradle:4.1.
3
'
classpath
"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath
"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
}
}
...
@@ -15,7 +14,6 @@ buildscript {
...
@@ -15,7 +14,6 @@ buildscript {
allprojects
{
allprojects
{
repositories
{
repositories
{
google
()
google
()
jcenter
()
mavenCentral
()
mavenCentral
()
}
}
}
}
...
...
lib/src/response/wechat_response.dart
浏览文件 @
ff367cf4
...
@@ -42,6 +42,8 @@ Map<String, _WeChatResponseInvoker> _nameAndResponseMapper = {
...
@@ -42,6 +42,8 @@ Map<String, _WeChatResponseInvoker> _nameAndResponseMapper = {
WeChatQRCodeScannedResponse
.
fromMap
(
argument
),
WeChatQRCodeScannedResponse
.
fromMap
(
argument
),
"onWXShowMessageFromWX"
:
(
Map
argument
)
=>
"onWXShowMessageFromWX"
:
(
Map
argument
)
=>
WeChatShowMessageFromWXRequest
.
fromMap
(
argument
),
WeChatShowMessageFromWXRequest
.
fromMap
(
argument
),
"onWXOpenCustomerServiceChatResponse"
:
(
Map
argument
)
=>
WeChatOpenCustomerServiceChatResponse
.
fromMap
(
argument
),
};
};
class
BaseWeChatResponse
{
class
BaseWeChatResponse
{
...
@@ -125,6 +127,11 @@ class WeChatPaymentResponse extends BaseWeChatResponse {
...
@@ -125,6 +127,11 @@ class WeChatPaymentResponse extends BaseWeChatResponse {
super
.
_
(
map
[
_errCode
],
map
[
_errStr
]);
super
.
_
(
map
[
_errCode
],
map
[
_errStr
]);
}
}
class
WeChatOpenCustomerServiceChatResponse
extends
BaseWeChatResponse
{
WeChatOpenCustomerServiceChatResponse
.
fromMap
(
Map
map
)
:
super
.
_
(
map
[
_errCode
],
map
[
_errStr
]);
}
class
WeChatSubscribeMsgResponse
extends
BaseWeChatResponse
{
class
WeChatSubscribeMsgResponse
extends
BaseWeChatResponse
{
final
String
?
openid
;
final
String
?
openid
;
final
String
?
templateId
;
final
String
?
templateId
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论