提交 572e003c authored 作者: Tenfar Lin's avatar Tenfar Lin

add WeChatLaunchMiniProgram

上级 b200e68c
{
"version": "0.0.5",
"open_new_column" : "no",
"engine_configurations": [
{
"cscope" : {
"paths" : [
"${workspaceRoot}"
]
}
}
]
}
\ No newline at end of file
......@@ -8,6 +8,7 @@
#import "FluwxKeys.h"
#import "FluwxWXApiHandler.h"
#import "FluwxShareHandler.h"
#import "FluwxLaunchMiniProgramHandler.h"
@implementation FluwxPlugin
......@@ -49,6 +50,7 @@ FluwxPaymentHandler *_fluwxPaymentHandler;
_fluwxAuthHandler = [[FluwxAuthHandler alloc] initWithRegistrar:registrar];
_fluwxWXApiHandler = [[FluwxWXApiHandler alloc] init];
_fluwxPaymentHandler = [[FluwxPaymentHandler alloc] initWithRegistrar:registrar];
_fluwxLaunchMiniProgramHandler = [[FluwxLuanchMiniProgramHandler alloc] initWithRegistrar:registrar];
}
......@@ -88,7 +90,10 @@ FluwxPaymentHandler *_fluwxPaymentHandler;
} else {
result(FlutterMethodNotImplemented);
}
if([@"launchMiniProgram" isEqualToString :call.method]){
[_fluwxLaunchMiniProgramHandler handlerLaunchMiniProgram:call result:result];
return;
}
}
......
......@@ -13,6 +13,7 @@ extern NSString *const shareMusic;
extern NSString *const shareVideo;
extern NSString *const shareWebPage;
extern NSString *const shareMiniProgram;
extern NSString *const launchMiniProgram;
@interface FluwxMethods : NSObject
@end
\ No newline at end of file
......@@ -13,7 +13,7 @@ NSString *const shareMusic = @"shareMusic";
NSString *const shareVideo = @"shareVideo";
NSString *const shareWebPage = @"shareWebPage";
NSString *const shareMiniProgram = @"shareMiniProgram";
NSString *const LaunchMiniProgram = @"launchMiniProgram";
@implementation FluwxMethods {
......
#import "FluwxLaunchMiniProgramHandler.h"
#import "CallResults.h"
#import "FluwxKeys.h"
#import "StringToWeChatScene.h"
#import "FluwxMethods.h"
#import "ThumbnailHelper.h"
#import "NSStringWrapper.h"
@implementation FluwxLaunchMiniProgramHandler
- (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
self = [super init];
// if (self) {
//
// }
return self;
}
- (void)handleLaunchMiniProgram:(FlutterMethodCall *)call result:(FlutterResult)result {
NSString *userName = call.arguments[@"userName"];
NSString *path = call.arguments[@"path"];
WXMiniProgramType *miniProgramType = (WXcall.arguments[@"miniProgramType"]
[WXApiRequestHandler launchMiniProgramWithUserName:userName
path:path
type:miniProgramType;
}
@end
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
#import "FluwxPlugin.h"
#import "WXApi.h"
@class StringUtil;
@interface FluwxLaunchMiniProgramHandler : NSObject
-(instancetype) initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar;
- (void)handleLaunchMiniProgram:(FlutterMethodCall *)call result:(FlutterResult)result;
@end
\ No newline at end of file
......@@ -20,6 +20,7 @@ import 'package:flutter/services.dart';
import 'models/wechat_response.dart';
import 'models/wechat_send_auth_model.dart';
import 'models/wechat_share_models.dart';
import 'models/wechat_launchminiprogram_model.dart';
import 'package:flutter/foundation.dart';
StreamController<WeChatShareResponse> _responseShareController =
......@@ -40,6 +41,9 @@ StreamController<WeChatPaymentResponse> _responsePaymentController =
Stream<WeChatPaymentResponse> get responseFromPayment =>
_responsePaymentController.stream;
StreamController<WeChatLaunchMiniProgramResponse> _responseLaunchMiniProgramController =
new StreamController.broadcast();
final MethodChannel _channel = const MethodChannel('com.jarvanmo/fluwx')
..setMethodCallHandler(_handler);
......@@ -50,6 +54,9 @@ Future<dynamic> _handler(MethodCall methodCall) {
} else if ("onAuthResponse" == methodCall.method) {
_responseAuthController
.add(WeChatAuthResponse.fromMap(methodCall.arguments));
} else if ("onLaunchMiniProgramResponse" == methodCall.method) {
_responseLaunchMiniProgramController
.add(WeChatLaunchMiniProgramResponse.fromMap(methodCall.arguments));
} else if ("onPayResponse" == methodCall.method) {
_responsePaymentController
.add(WeChatPaymentResponse.fromMap(methodCall.arguments));
......@@ -84,7 +91,7 @@ Future register(
}
///we don't need the response any longer if params are true.
void dispose({shareResponse: true, authResponse: true, paymentResponse: true}) {
void dispose({shareResponse: true, authResponse: true, paymentResponse: true,launchMiniProgramResponse:true}) {
if (shareResponse) {
_responseShareController.close();
}
......@@ -92,6 +99,9 @@ void dispose({shareResponse: true, authResponse: true, paymentResponse: true}) {
if (authResponse) {
_responseAuthController.close();
}
if (launchMiniProgramResponse) {
_responseLaunchMiniProgramController.close();
}
if (paymentResponse) {
_responseAuthController.close();
......@@ -121,6 +131,11 @@ Future sendAuth(WeChatSendAuthModel model) async {
return await _channel.invokeMethod("sendAuth", model.toMap());
}
Future launchMiniProgram(WeChatLaunchMiniProgramModel model) async {
return await _channel.invokeMethod("launchMiniProgram", model.toMap());
}
Future isWeChatInstalled() async {
return await _channel.invokeMethod("isWeChatInstalled");
}
......
/*
* Copyright (C) 2018 The OpenFlutter Organization
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import 'package:flutter/foundation.dart';
import '../wechat_type.dart';
class WeChatLaunchMiniProgramModel {
final String username;
final String path;
final WXMiniProgramType miniprogramtype;
WeChatLaunchMiniProgramModel({@required this.username, this.path, this.miniprogramtype})
: assert(username != null && username.trim().isNotEmpty);
Map toMap() {
return {"userName": username, "path": path, "miniProgramType": miniprogramtype};
}
}
\ No newline at end of file
......@@ -76,6 +76,35 @@ class WeChatAuthResponse {
androidTransaction = map["transaction"];
}
class WeChatLaunchMiniProgramResponse {
final String errStr;
final int type;
final int errCode;
final String androidOpenId;
final String iOSDescription;
final String country;
final String lang;
final String code;
final String androidUrl;
final String state;
final String androidTransaction;
WeChatLaunchMiniProgramResponse.fromMap(Map map)
: errStr = map["errStr"],
type = map["type"],
errCode = map["errCode"],
androidOpenId = map["openId"],
iOSDescription = map["description"],
country = map["country"],
lang = map["lang"],
code = map["code"],
androidUrl = map["url"],
state = map["state"],
androidTransaction = map["transaction"];
}
class WeChatPaymentResponse {
final String errStr;
final int type;
......
/*
* Copyright (C) 2018 The OpenFlutter Organization
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
///[WXMiniProgramType.RELEASE]正式版
///[WXMiniProgramType.TEST]测试版
///[WXMiniProgramType.PREVIEW]预览版
enum WXMiniProgramType { RELEASE, TEST, PREVIEW }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论