提交 014554db authored 作者: JarvanMo's avatar JarvanMo

add new function: open

上级 0138d562
......@@ -2,14 +2,25 @@ package com.jarvan.fluwx
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.util.Log
import androidx.annotation.NonNull
import com.jarvan.fluwx.handlers.*
import com.jarvan.fluwx.handlers.FluwxAuthHandler
import com.jarvan.fluwx.handlers.FluwxRequestHandler
import com.jarvan.fluwx.handlers.FluwxShareHandler
import com.jarvan.fluwx.handlers.FluwxShareHandlerEmbedding
import com.jarvan.fluwx.handlers.PermissionHandler
import com.jarvan.fluwx.handlers.WXAPiHandler
import com.jarvan.fluwx.utils.KEY_FLUWX_REQUEST_INFO_EXT_MSG
import com.jarvan.fluwx.utils.WXApiUtils
import com.tencent.mm.opensdk.modelbiz.*
import com.tencent.mm.opensdk.modelbiz.ChooseCardFromWXCardPackage
import com.tencent.mm.opensdk.modelbiz.OpenRankList
import com.tencent.mm.opensdk.modelbiz.OpenWebview
import com.tencent.mm.opensdk.modelbiz.SubscribeMessage
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram
import com.tencent.mm.opensdk.modelbiz.WXOpenBusinessView
import com.tencent.mm.opensdk.modelbiz.WXOpenBusinessWebview
import com.tencent.mm.opensdk.modelbiz.WXOpenCustomerServiceChat
import com.tencent.mm.opensdk.modelpay.PayReq
import com.tencent.mm.opensdk.openapi.SendReqCallback
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
......@@ -82,7 +93,9 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
call.method == "openBusinessView" -> openBusinessView(call, result)
call.method == "openWeChatInvoice" -> openWeChatInvoice(call, result);
call.method == "openWeChatInvoice" -> openWeChatInvoice(call, result)
call.method == "openUrl" -> openUrl(call, result)
call.method == "openRankList" -> openRankList(result)
else -> result.notImplemented()
}
}
......@@ -265,8 +278,27 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
private fun openWXApp(result: Result) = result.success(WXAPiHandler.wxApi?.openWXApp())
private fun openUrl(call: MethodCall, result: Result) {
val req = OpenWebview.Req()
req.url = call.argument("url")
WXAPiHandler.wxApi?.sendReq(req, SendReqCallback {
result.success(it)
}) ?: kotlin.run {
result.success(false)
}
}
private fun openRankList(result: Result) {
val req = OpenRankList.Req()
WXAPiHandler.wxApi?.sendReq(req, SendReqCallback {
result.success(it)
}) ?: kotlin.run {
result.success(false)
}
}
override fun onNewIntent(intent: Intent): Boolean {
handelIntent(intent)
return false
}
}
......@@ -205,7 +205,7 @@ class ShareSelectorPage extends StatelessWidget {
padding: const EdgeInsets.all(8.0),
child: OutlinedButton(
onPressed: () {
fluwx.openWeChatApp();
fluwx.open(OpenWeChat());
},
child: const Text('Open WeChat App'),
),
......
......@@ -94,6 +94,10 @@ FlutterMethodChannel *channel = nil;
[self openWeChatCustomerServiceChat:call result:result];
} else if ([@"checkSupportOpenBusinessView" isEqualToString:call.method]) {
[self checkSupportOpenBusinessView:call result:result];
} else if ([@"openRankList" isEqualToString:call.method]) {
[self handleOpenRankListCall:call result:result];
} else if ([@"openUrl" isEqualToString:call.method]) {
[self handleOpenUrlCall:call result:result];
} else if([@"openWeChatInvoice" isEqualToString:call.method]) {
[self openWeChatInvoice:call result:result];
}
......@@ -326,6 +330,25 @@ FlutterMethodChannel *channel = nil;
[WXApi handleOpenUniversalLink:userActivity delegate:[FluwxResponseHandler defaultManager]];
}
- (void)handleOpenUrlCall:(FlutterMethodCall *)call
result:(FlutterResult)result {
OpenWebviewReq *req = [[OpenWebviewReq alloc] init];
req.url = call.arguments[@"url"];
[WXApi sendReq:req
completion:^(BOOL success){
result(@(success));
}];
}
- (void)handleOpenRankListCall:(FlutterMethodCall *)call
result:(FlutterResult)result {
OpenRankListReq *req = [[OpenRankListReq alloc] init];
[WXApi sendReq:req
completion:^(BOOL success){
result(@(success));
}];
}
- (BOOL)handleOpenURL:(NSNotification *)aNotification {
if (handleOpenURLByFluwx) {
NSString *aURLString = [aNotification userInfo][@"url"];
......@@ -336,6 +359,7 @@ FlutterMethodChannel *channel = nil;
}
}
- (void)managerDidRecvLaunchFromWXReq:(LaunchFromWXReq *)request {
[FluwxDelegate defaultManager].extMsg = request.message.messageExt;
// LaunchFromWXReq *launchFromWXReq = (LaunchFromWXReq *)request;
......
......@@ -27,4 +27,5 @@ export 'src/fluwx.dart';
export 'src/response/wechat_response.dart';
export 'src/share/share_models.dart';
export 'src/wechat_enums.dart';
export 'src/open_command.dart';
export 'src/wechat_file.dart' hide FileSchema;
......@@ -19,6 +19,7 @@
import 'dart:async';
import '../fluwx.dart';
import 'method_channel/fluwx_platform_interface.dart';
import 'response/wechat_response.dart';
import 'share/share_models.dart';
......@@ -38,8 +39,8 @@ class Fluwx {
Future<bool> get isWeChatInstalled =>
FluwxPlatform.instance.isWeChatInstalled;
Future<bool> openWeChatApp() async {
return FluwxPlatform.instance.openWeChatApp();
Future<bool> open(OpenCommand what){
return FluwxPlatform.instance.open(what);
}
Future<bool> registerWxApi({
......
......@@ -23,6 +23,7 @@ import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import '../open_command.dart';
import '../response/wechat_response.dart';
import '../share/share_models.dart';
import '../wechat_enums.dart';
......@@ -74,10 +75,21 @@ class MethodChannelFluwx extends FluwxPlatform {
return await methodChannel.invokeMethod('isWeChatInstalled');
}
/// Just open WeChat, noting to do.
@override
Future<bool> openWeChatApp() async {
Future<bool> open(OpenCommand what) async {
switch(what){
case OpenWeChat():
return await methodChannel.invokeMethod('openWXApp');
case OpenUrl():
return await methodChannel.invokeMethod(
'openUrl',
<String, dynamic>{
'url': what.url,
},
);
case OpenRankList():
return await methodChannel.invokeMethod("openRankList");
}
}
/// It's ok if you register multi times.
......
......@@ -50,8 +50,8 @@ abstract class FluwxPlatform extends PlatformInterface {
throw UnimplementedError('isWeChatInstalled has not been implemented.');
}
Future<bool> openWeChatApp() {
throw UnimplementedError('openWeChatApp() has not been implemented.');
Future<bool> open(OpenCommand what) {
throw UnimplementedError('open() has not been implemented.');
}
Future<bool> registerWxApi({
......
sealed class OpenCommand {
}
class OpenWeChat extends OpenCommand{
}
class OpenUrl extends OpenCommand {
final String url;
OpenUrl(this.url);
}
class OpenRankList extends OpenCommand {
}
\ No newline at end of file
......@@ -100,12 +100,6 @@ class MockFluwxPlatform
throw UnimplementedError();
}
@override
Future<bool> openWeChatApp() {
// TODO: implement openWeChatApp
throw UnimplementedError();
}
@override
Future<bool> pay(
{required String appId,
......@@ -172,6 +166,12 @@ class MockFluwxPlatform
// TODO: implement responseEventHandler
Stream<WeChatResponse> get responseEventHandler => throw UnimplementedError();
@override
Future<bool> open(OpenCommand what) {
// TODO: implement open
throw UnimplementedError();
}
}
void main() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论