flutter_wxwork_method_channel.dart
3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import 'dart:convert';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'flutter_wxwork_platform_interface.dart';
/// An implementation of [FlutterWxworkPlatform] that uses method channels.
class MethodChannelFlutterWxwork extends FlutterWxworkPlatform {
/// The method channel used to interact with the native platform.
@visibleForTesting
final methodChannel = const MethodChannel('flutter_wxwork');
@override
Future<String> getPlatformVersion() async {
final version =
await methodChannel.invokeMethod<String>('getPlatformVersion');
return version;
}
@override
Future<bool> registerApp(scheme, corpId, agentId) async {
bool result =
await methodChannel.invokeMethod<bool>('register', <String, String>{
'scheme': scheme,
'corpId': corpId,
'agentId': agentId,
});
return result;
}
@override
Future<bool> isAppInstalled() async {
final isAppInstalled =
await methodChannel.invokeMethod<bool>('isAppInstalled');
return isAppInstalled;
}
@override
Future<bool> shareImageNetWork(String path) async {
final shareImageNetWork = await methodChannel
.invokeMethod<bool>('shareImageNetWork', <String, String>{
'path': path,
});
return shareImageNetWork;
}
@override
Future<bool> shareImagePath(String path) async {
final shareImagePath = await methodChannel
.invokeMethod<bool>('shareImagePath', <String, String>{
'path': path,
});
return shareImagePath;
}
@override
Future<dynamic> shareMiniProgram(
{String userName, //必须是应用关联的小程序,注意要有@app后缀
String path,
String hdImageData,
String title = "分享标题",
String description= ""}) async {
final shareMiniProgram = await methodChannel.invokeMethod<dynamic>(
'shareMiniProgram', <String, String>{
'userName': userName,
'path': path,
'hdImageData': hdImageData,
'title': title,
"description":description
});
return shareMiniProgram;
}
@override
Future<bool> shareText({String text = "分享内容"}) async {
final shareText =
await methodChannel.invokeMethod<bool>('shareText', <String, String>{
'text': text,
});
return shareText;
}
@override
Future<AuthModel> auth({String state = 'state'}) async {
var content = await methodChannel.invokeMethod('auth', {"state": state});
return AuthModel.fromJson(Map<String, dynamic>.from(content));
}
bool _stringToBool(String string) {
if (string == '1') {
return true;
} else {
return false;
}
}
}
class AuthModel {
/// 1.取消 0.成功 2.失败
String errCode;
String code;
String state;
bool get isSuccess => errCode == '1';
AuthModel();
factory AuthModel.fromJson(Map<String, dynamic> json) {
AuthModel model = AuthModel();
model.errCode = json['errCode'];
model.code = json['code'];
model.state = json['state'];
return model;
}
Map<String, dynamic> toJson() {
return {'errorCode': errCode, 'code': code, 'state': state};
}
@override
String toString() {
return jsonEncode(this);
}
}