@@ -13,7 +13,7 @@ import 'package:flutter/services.dart';
13
13
class Post {
14
14
final int code;
15
15
final String message;
16
- final String content;
16
+ final dynamic content;
17
17
18
18
Post ({this .code, this .message, this .content});
19
19
@@ -33,6 +33,7 @@ class AlipayDemo extends StatefulWidget {
33
33
}
34
34
35
35
class _AlipayDemoState extends State <AlipayDemo > {
36
+ final String base = "http://192.168.98.20:8080/" ;
36
37
static const MethodChannel platform =
37
38
const MethodChannel ('examples.flutter.dev/battery' );
38
39
static const EventChannel eventChannel =
@@ -48,28 +49,21 @@ class _AlipayDemoState extends State<AlipayDemo> {
48
49
49
50
Future <void > _wxPay () async {
50
51
// final String message = await platform.invokeMethod("wxpay");
51
- // _neverSatisfied(message);
52
- final client = new http.Client ();
53
- Post result;
52
+ final Post result = await _payment ("wxpay" );
54
53
try {
55
- final response = await client
56
- .get ("https://wxpay.wxutil.com/pub_v2/app/app_pay.php" )
57
- .timeout (const Duration (seconds: 5 ));
58
- result = Post .fromJson (json.decode (response.body));
54
+ if (result.code == 200 ) {
55
+ await platform.invokeMethod (
56
+ "wxpay" , < String , dynamic > {"payInfo" : result.content});
57
+ } else {
58
+ _neverSatisfied ("错误编码: ${result .code }, 错误信息: ${result .message }" );
59
+ }
59
60
} on PlatformException catch (e) {
60
- result = Post (code: int .parse (e.code), message: e.message, content: e.toString ());
61
- } on TimeoutException catch (e) {
62
- result = Post (code: 408 , message: e.message, content: e.toString ());
63
- } on FormatException catch (e) {
64
- result = Post (code: 405 , message: e.message, content: e.toString ());
65
- } on SocketException catch (e) {
66
- result = Post (code: 407 , message: e.message, content: e.toString ());
61
+ _neverSatisfied (e.message);
67
62
}
68
- print ("打印结果: $result .toString()" );
69
63
}
70
64
71
65
Future <void > _initiatedPayment () async {
72
- final Post result = await _payment ();
66
+ final Post result = await _payment ("alipay" );
73
67
try {
74
68
if (result.code == 200 ) {
75
69
_sendPaymentParameters (result.content);
@@ -109,13 +103,12 @@ class _AlipayDemoState extends State<AlipayDemo> {
109
103
);
110
104
}
111
105
112
- Future <Post > _payment () async {
106
+ Future <Post > _payment (String type ) async {
113
107
final client = new http.Client ();
114
108
Post result;
115
109
try {
116
- final response = await client
117
- .get ("http://192.168.98.20:8080/alipay" )
118
- .timeout (const Duration (seconds: 5 ));
110
+ final response =
111
+ await client.get (base + type).timeout (const Duration (seconds: 5 ));
119
112
result = Post .fromJson (json.decode (response.body));
120
113
} on PlatformException catch (e) {
121
114
result = Post (
0 commit comments