Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-fluwx
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx-fluwx
Commits
c6bf15ff
Unverified
提交
c6bf15ff
authored
3月 04, 2022
作者:
JarvanMo
提交者:
GitHub
3月 04, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #458 from mafanwei/master
支持App打开微信支付分
上级
80395256
deb0251a
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
80 行增加
和
28 行删除
+80
-28
FluwxPlugin.kt
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
+12
-5
FluwxRequestHandler.kt
...n/kotlin/com/jarvan/fluwx/handlers/FluwxRequestHandler.kt
+2
-2
FluwxResponseHandler.kt
.../kotlin/com/jarvan/fluwx/handlers/FluwxResponseHandler.kt
+14
-4
WXAPiHandler.kt
...src/main/kotlin/com/jarvan/fluwx/handlers/WXAPiHandler.kt
+19
-6
FluwxWXEntryActivity.kt
...ain/kotlin/com/jarvan/fluwx/wxapi/FluwxWXEntryActivity.kt
+3
-3
fluwx_iml.dart
lib/src/fluwx_iml.dart
+14
-8
wechat_response.dart
lib/src/response/wechat_response.dart
+16
-0
没有找到文件。
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
浏览文件 @
c6bf15ff
...
@@ -3,9 +3,7 @@ package com.jarvan.fluwx
...
@@ -3,9 +3,7 @@ package com.jarvan.fluwx
import
android.content.Intent
import
android.content.Intent
import
androidx.annotation.NonNull
import
androidx.annotation.NonNull
import
com.jarvan.fluwx.handlers.*
import
com.jarvan.fluwx.handlers.*
import
com.tencent.mm.opensdk.modelbiz.SubscribeMessage
import
com.tencent.mm.opensdk.modelbiz.*
import
com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram
import
com.tencent.mm.opensdk.modelbiz.WXOpenBusinessWebview
import
com.tencent.mm.opensdk.modelpay.PayReq
import
com.tencent.mm.opensdk.modelpay.PayReq
import
io.flutter.embedding.engine.plugins.FlutterPlugin
import
io.flutter.embedding.engine.plugins.FlutterPlugin
import
io.flutter.embedding.engine.plugins.activity.ActivityAware
import
io.flutter.embedding.engine.plugins.activity.ActivityAware
...
@@ -15,10 +13,9 @@ import io.flutter.plugin.common.MethodChannel
...
@@ -15,10 +13,9 @@ 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
{
companion
object
{
companion
object
{
var
callingChannel
:
MethodChannel
?
=
null
var
callingChannel
:
MethodChannel
?
=
null
// 主动获取的启动参数
// 主动获取的启动参数
...
@@ -67,6 +64,8 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,PluginRegist
...
@@ -67,6 +64,8 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,PluginRegist
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
)
call
.
method
==
"openWeChatCustomerServiceChat"
->
openWeChatCustomerServiceChat
(
call
,
result
)
call
.
method
==
"checkSupportOpenBusinessView"
->
WXAPiHandler
.
checkSupportOpenBusinessView
(
result
)
call
.
method
==
"openBusinessView"
->
openBusinessView
(
call
,
result
)
else
->
result
.
notImplemented
()
else
->
result
.
notImplemented
()
}
}
}
}
...
@@ -142,6 +141,14 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,PluginRegist
...
@@ -142,6 +141,14 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,PluginRegist
result
.
success
(
WXAPiHandler
.
wxApi
?.
sendReq
(
request
))
result
.
success
(
WXAPiHandler
.
wxApi
?.
sendReq
(
request
))
}
}
private
fun
openBusinessView
(
call
:
MethodCall
,
result
:
Result
)
{
val
request
=
WXOpenBusinessView
.
Req
()
request
.
businessType
=
call
.
argument
<
String
>(
"businessType"
)
?:
""
request
.
query
=
call
.
argument
<
String
>(
"query"
)
?:
""
request
.
extInfo
=
"{\"miniProgramType\": 0}"
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
浏览文件 @
c6bf15ff
...
@@ -64,7 +64,7 @@ object FluwxRequestHandler {
...
@@ -64,7 +64,7 @@ object FluwxRequestHandler {
// 稳定复现场景:微信版本为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
if
(!
WXAPiHandler
.
isC
oolBoot
)
{
if
(!
WXAPiHandler
.
c
oolBoot
)
{
handleRequest
(
baseReq
)
handleRequest
(
baseReq
)
startSpecifiedActivity
(
defaultFlutterActivityAction
(
activity
),
activity
=
activity
)
startSpecifiedActivity
(
defaultFlutterActivityAction
(
activity
),
activity
=
activity
)
}
else
{
}
else
{
...
@@ -74,7 +74,7 @@ object FluwxRequestHandler {
...
@@ -74,7 +74,7 @@ object FluwxRequestHandler {
val
intent
=
Intent
(
Intent
.
ACTION_VIEW
,
Uri
.
parse
(
"wechatextmsg://${activity.packageName}/?extmsg=${baseReq.message.messageExt}"
))
val
intent
=
Intent
(
Intent
.
ACTION_VIEW
,
Uri
.
parse
(
"wechatextmsg://${activity.packageName}/?extmsg=${baseReq.message.messageExt}"
))
activity
.
startActivity
(
intent
)
activity
.
startActivity
(
intent
)
activity
.
finish
()
activity
.
finish
()
WXAPiHandler
.
setCoolBool
(
false
)
WXAPiHandler
.
coolBoot
=
false
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
Log
.
i
(
"fluwx"
,
"call scheme error:${e.toString()}"
)
Log
.
i
(
"fluwx"
,
"call scheme error:${e.toString()}"
)
}
}
...
...
android/src/main/kotlin/com/jarvan/fluwx/handlers/FluwxResponseHandler.kt
浏览文件 @
c6bf15ff
...
@@ -17,10 +17,7 @@ package com.jarvan.fluwx.handlers
...
@@ -17,10 +17,7 @@ package com.jarvan.fluwx.handlers
import
com.jarvan.fluwx.FluwxPlugin
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.*
import
com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram
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
...
@@ -42,9 +39,22 @@ object FluwxResponseHandler {
...
@@ -42,9 +39,22 @@ object FluwxResponseHandler {
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
)
is
WXOpenCustomerServiceChat
.
Resp
->
handlerWXOpenCustomerServiceChatResponse
(
response
)
is
WXOpenBusinessView
.
Resp
->
handleWXOpenBusinessView
(
response
)
}
}
}
}
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
)
{
private
fun
handleSubscribeMessage
(
response
:
SubscribeMessage
.
Resp
)
{
val
result
=
mapOf
(
val
result
=
mapOf
(
"openid"
to
response
.
openId
,
"openid"
to
response
.
openId
,
...
...
android/src/main/kotlin/com/jarvan/fluwx/handlers/WXAPiHandler.kt
浏览文件 @
c6bf15ff
...
@@ -23,6 +23,7 @@ import com.tencent.mm.opensdk.openapi.IWXAPI
...
@@ -23,6 +23,7 @@ import com.tencent.mm.opensdk.openapi.IWXAPI
import
com.tencent.mm.opensdk.openapi.WXAPIFactory
import
com.tencent.mm.opensdk.openapi.WXAPIFactory
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
com.tencent.mm.opensdk.constants.Build
object
WXAPiHandler
{
object
WXAPiHandler
{
...
@@ -35,12 +36,7 @@ object WXAPiHandler {
...
@@ -35,12 +36,7 @@ object WXAPiHandler {
val
wxApiRegistered
get
()
=
registered
val
wxApiRegistered
get
()
=
registered
//是否为冷启动
//是否为冷启动
private
var
coolBoot
:
Boolean
=
false
var
coolBoot
:
Boolean
=
false
val
isCoolBoot
get
()
=
coolBoot
fun
setCoolBool
(
isCoolBoot
:
Boolean
)
{
coolBoot
=
isCoolBoot
}
fun
setupWxApi
(
appId
:
String
,
context
:
Context
,
force
:
Boolean
=
true
):
Boolean
{
fun
setupWxApi
(
appId
:
String
,
context
:
Context
,
force
:
Boolean
=
true
):
Boolean
{
if
(
force
||
!
registered
)
{
if
(
force
||
!
registered
)
{
...
@@ -86,6 +82,23 @@ object WXAPiHandler {
...
@@ -86,6 +82,23 @@ object WXAPiHandler {
}
}
}
}
fun
checkSupportOpenBusinessView
(
result
:
MethodChannel
.
Result
)
{
when
{
wxApi
==
null
->
{
result
.
error
(
"Unassigned WxApi"
,
"please config wxapi first"
,
null
)
}
wxApi
?.
isWXAppInstalled
!=
true
->
{
result
.
error
(
"WeChat Not Installed"
,
"Please install the WeChat first"
,
null
)
}
wxApi
?.
wxAppSupportAPI
?:
0
<
Build
.
OPEN_BUSINESS_VIEW_SDK_INT
->
{
result
.
error
(
"WeChat Not Supported"
,
"Please upgrade the WeChat version"
,
null
)
}
else
->
{
result
.
success
(
null
)
}
}
}
private
fun
registerWxAPIInternal
(
appId
:
String
,
context
:
Context
)
{
private
fun
registerWxAPIInternal
(
appId
:
String
,
context
:
Context
)
{
val
api
=
WXAPIFactory
.
createWXAPI
(
context
.
applicationContext
,
appId
)
val
api
=
WXAPIFactory
.
createWXAPI
(
context
.
applicationContext
,
appId
)
registered
=
api
.
registerApp
(
appId
)
registered
=
api
.
registerApp
(
appId
)
...
...
android/src/main/kotlin/com/jarvan/fluwx/wxapi/FluwxWXEntryActivity.kt
浏览文件 @
c6bf15ff
...
@@ -39,11 +39,11 @@ open class FluwxWXEntryActivity : Activity(), IWXAPIEventHandler {
...
@@ -39,11 +39,11 @@ open class FluwxWXEntryActivity : Activity(), IWXAPIEventHandler {
if
(!
WXAPiHandler
.
wxApiRegistered
)
{
if
(!
WXAPiHandler
.
wxApiRegistered
)
{
val
appInfo
=
packageManager
.
getApplicationInfo
(
packageName
,
PackageManager
.
GET_META_DATA
)
val
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
.
coolBoot
=
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"
)
}
}
}
}
...
...
lib/src/fluwx_iml.dart
浏览文件 @
c6bf15ff
...
@@ -277,12 +277,18 @@ Future<bool> authWeChatByPhoneLogin({
...
@@ -277,12 +277,18 @@ Future<bool> authWeChatByPhoneLogin({
);
);
}
}
Future
<
bool
>
openWeChatCustomerServiceChat
({
required
String
url
,
Future
<
bool
>
openWeChatCustomerServiceChat
({
required
String
url
,
required
String
corpId
})
async
{
required
String
corpId
,
return
await
_channel
})
async
{
.
invokeMethod
(
"openWeChatCustomerServiceChat"
,
{
"corpId"
:
corpId
,
"url"
:
url
});
return
await
_channel
.
invokeMethod
(
}
'openWeChatCustomerServiceChat'
,
{
'corpId'
:
corpId
,
'url'
:
url
},
// see https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter6_2_1.shtml
);
Future
<
bool
>
openWeChatBusinessView
({
required
String
businessType
,
required
String
query
})
async
{
return
await
_channel
.
invokeMethod
(
"openBusinessView"
,
{
"businessType"
:
businessType
,
"query"
:
query
});
}
Future
<
bool
>
checkSupportOpenBusinessView
()
async
{
return
await
_channel
.
invokeMethod
(
"checkSupportOpenBusinessView"
);
}
}
lib/src/response/wechat_response.dart
浏览文件 @
c6bf15ff
...
@@ -44,6 +44,8 @@ Map<String, _WeChatResponseInvoker> _nameAndResponseMapper = {
...
@@ -44,6 +44,8 @@ Map<String, _WeChatResponseInvoker> _nameAndResponseMapper = {
WeChatShowMessageFromWXRequest
.
fromMap
(
argument
),
WeChatShowMessageFromWXRequest
.
fromMap
(
argument
),
'onWXOpenCustomerServiceChatResponse'
:
(
Map
argument
)
=>
'onWXOpenCustomerServiceChatResponse'
:
(
Map
argument
)
=>
WeChatOpenCustomerServiceChatResponse
.
fromMap
(
argument
),
WeChatOpenCustomerServiceChatResponse
.
fromMap
(
argument
),
"onOpenBusinessViewResponse"
:
(
Map
argument
)
=>
WeChatOpenBusinessViewResponse
.
fromMap
(
argument
),
};
};
class
BaseWeChatResponse
{
class
BaseWeChatResponse
{
...
@@ -132,6 +134,20 @@ class WeChatOpenCustomerServiceChatResponse extends BaseWeChatResponse {
...
@@ -132,6 +134,20 @@ class WeChatOpenCustomerServiceChatResponse extends BaseWeChatResponse {
final
String
?
extMsg
;
final
String
?
extMsg
;
}
}
class
WeChatOpenBusinessViewResponse
extends
BaseWeChatResponse
{
final
String
?
extMsg
;
final
String
?
openid
;
final
String
?
businessType
;
final
int
?
type
;
WeChatOpenBusinessViewResponse
.
fromMap
(
Map
map
)
:
extMsg
=
map
[
"extMsg"
],
openid
=
map
[
"openid"
],
businessType
=
map
[
"businessType"
],
type
=
map
[
"type"
],
super
.
_
(
map
[
_errCode
],
map
[
_errStr
]);
}
class
WeChatSubscribeMsgResponse
extends
BaseWeChatResponse
{
class
WeChatSubscribeMsgResponse
extends
BaseWeChatResponse
{
WeChatSubscribeMsgResponse
.
fromMap
(
Map
map
)
WeChatSubscribeMsgResponse
.
fromMap
(
Map
map
)
:
openid
=
map
[
'openid'
],
:
openid
=
map
[
'openid'
],
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论