提交 6e07c71b authored 作者: MFW's avatar MFW

支持App打开微信支付分

等ios大佬补上ios部分
上级 07e02e08
......@@ -3,9 +3,7 @@ package com.jarvan.fluwx
import android.content.Intent
import androidx.annotation.NonNull
import com.jarvan.fluwx.handlers.*
import com.tencent.mm.opensdk.modelbiz.SubscribeMessage
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram
import com.tencent.mm.opensdk.modelbiz.WXOpenBusinessWebview
import com.tencent.mm.opensdk.modelbiz.*
import com.tencent.mm.opensdk.modelpay.PayReq
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
......@@ -15,10 +13,9 @@ import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.PluginRegistry
import com.tencent.mm.opensdk.modelbiz.WXOpenCustomerServiceChat
/** FluwxPlugin */
class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,PluginRegistry.NewIntentListener {
class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware, PluginRegistry.NewIntentListener {
companion object {
var callingChannel:MethodChannel? = null
// 主动获取的启动参数
......@@ -67,6 +64,8 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,PluginRegist
call.method == "isWeChatInstalled" -> WXAPiHandler.checkWeChatInstallation(result)
call.method == "getExtMsg" -> getExtMsg(result)
call.method == "openWeChatCustomerServiceChat" -> openWeChatCustomerServiceChat(call, result)
call.method == "checkSupportOpenBusinessView" -> WXAPiHandler.checkSupportOpenBusinessView(result)
call.method == "openBusinessView" -> openBusinessView(call, result)
else -> result.notImplemented()
}
}
......@@ -142,6 +141,14 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,PluginRegist
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) {
val appId: String = call.argument<String>("appid") ?: ""
val mchId = call.argument<String>("mch_id") ?: ""
......
......@@ -64,7 +64,7 @@ object FluwxRequestHandler {
// 稳定复现场景:微信版本为7.0.5,小程序SDK为2.7.7
if (baseReq.type == 4) {
// com.tencent.mm.opensdk.constants.ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX = 4
if (!WXAPiHandler.isCoolBoot) {
if (!WXAPiHandler.coolBoot) {
handleRequest(baseReq)
startSpecifiedActivity(defaultFlutterActivityAction(activity), activity = activity)
} else {
......@@ -74,7 +74,7 @@ object FluwxRequestHandler {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("wechatextmsg://${activity.packageName}/?extmsg=${baseReq.message.messageExt}"))
activity.startActivity(intent)
activity.finish()
WXAPiHandler.setCoolBool(false)
WXAPiHandler.coolBoot = false
}catch (e:Exception) {
Log.i("fluwx","call scheme error:${e.toString()}")
}
......
......@@ -17,10 +17,7 @@ package com.jarvan.fluwx.handlers
import com.jarvan.fluwx.FluwxPlugin
import com.tencent.mm.opensdk.modelbase.BaseResp
import com.tencent.mm.opensdk.modelbiz.SubscribeMessage
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.modelbiz.*
import com.tencent.mm.opensdk.modelmsg.SendAuth
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX
import com.tencent.mm.opensdk.modelpay.PayResp
......@@ -42,9 +39,22 @@ object FluwxResponseHandler {
is SubscribeMessage.Resp -> handleSubscribeMessage(response)
is WXOpenBusinessWebview.Resp -> handlerWXOpenBusinessWebviewResponse(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) {
val result = mapOf(
"openid" to response.openId,
......
......@@ -23,6 +23,7 @@ import com.tencent.mm.opensdk.openapi.IWXAPI
import com.tencent.mm.opensdk.openapi.WXAPIFactory
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import com.tencent.mm.opensdk.constants.Build
object WXAPiHandler {
......@@ -35,12 +36,7 @@ object WXAPiHandler {
val wxApiRegistered get() = registered
//是否为冷启动
private var coolBoot: Boolean = false
val isCoolBoot get() = coolBoot
fun setCoolBool(isCoolBoot : Boolean) {
coolBoot = isCoolBoot
}
var coolBoot: Boolean = false
fun setupWxApi(appId: String, context: Context, force: Boolean = true): Boolean {
if (force || !registered) {
......@@ -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) {
val api = WXAPIFactory.createWXAPI(context.applicationContext, appId)
registered = api.registerApp(appId)
......
......@@ -262,4 +262,14 @@ Future<bool> authWeChatByPhoneLogin(
Future<bool> openWeChatCustomerServiceChat({required String url, required String corpId}) async {
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");
}
\ No newline at end of file
......@@ -44,6 +44,8 @@ Map<String, _WeChatResponseInvoker> _nameAndResponseMapper = {
WeChatShowMessageFromWXRequest.fromMap(argument),
"onWXOpenCustomerServiceChatResponse": (Map argument) =>
WeChatOpenCustomerServiceChatResponse.fromMap(argument),
"onOpenBusinessViewResponse": (Map argument) =>
WeChatOpenBusinessViewResponse.fromMap(argument),
};
class BaseWeChatResponse {
......@@ -135,6 +137,20 @@ class WeChatOpenCustomerServiceChatResponse extends BaseWeChatResponse {
super._(map[_errCode], map[_errStr]);
}
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 {
final String? openid;
final String? templateId;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论