-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathflutter_alipay.dart
60 lines (47 loc) · 1.49 KB
/
flutter_alipay.dart
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
import 'dart:async';
import 'dart:io';
import 'package:flutter/services.dart';
class AlipayResult{
///
final String memo;
/// 支付后结果
final String result;
/// 支付状态,参考支付宝的文档https://docs.open.alipay.com/204/105695/
/// 返回码,标识支付状态,含义如下:
/// 9000——订单支付成功 上面的result有值
/// 8000——正在处理中
/// 4000——订单支付失败
/// 5000——重复请求
/// 6001——用户中途取消
/// 6002——网络连接出错
final String resultStatus;
AlipayResult({
this.memo,
this.result,
this.resultStatus
});
@override
String toString() {
return "{meno: $memo, resultStatus:$resultStatus, result:$result}";
}
}
class FlutterAlipay {
static const MethodChannel _channel = const MethodChannel('flutter_alipay');
static Future<AlipayResult> pay(String payInfo) async {
final Map<String, dynamic> params = <String, dynamic>{
'payInfo': payInfo,
};
var res = await _channel.invokeMethod('pay', params);
return new AlipayResult(result: res['result'],resultStatus: res['resultStatus'],memo: res['memo']);
}
/// 判断是否安装了支付宝
static Future<bool> isInstalled() async{
var res = await _channel.invokeMethod('isInstalled');
return res['result'];
}
static Future setIosUrlSchema(String urlSchema) async{
if(Platform.isIOS){
await _channel.invokeMethod('setIosUrlSchema',{"schema":urlSchema});
}
}
}