浏览代码

add WeChatPay PaygoPage

[baozhangchao] 2 年前
父节点
当前提交
d5628b584a

+ 1
- 0
android/build.gradle 查看文件

9
     dependencies {
9
     dependencies {
10
         classpath 'com.android.tools.build:gradle:4.1.0'
10
         classpath 'com.android.tools.build:gradle:4.1.0'
11
         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11
         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12
+//        api 'com.tencent.mm.opensdk:wechat-sdk-android:+'
12
     }
13
     }
13
 }
14
 }
14
 
15
 

+ 11
- 0
lib/main.dart 查看文件

2
 import 'package:farmer_client/utils/location.dart';
2
 import 'package:farmer_client/utils/location.dart';
3
 import 'package:flutter/material.dart';
3
 import 'package:flutter/material.dart';
4
 import 'package:flutter_easyloading/flutter_easyloading.dart';
4
 import 'package:flutter_easyloading/flutter_easyloading.dart';
5
+import 'package:fluwx/fluwx.dart';
5
 import 'package:get/get.dart';
6
 import 'package:get/get.dart';
6
 import 'package:get_storage/get_storage.dart';
7
 import 'package:get_storage/get_storage.dart';
7
 import 'package:flutter_screenutil/flutter_screenutil.dart';
8
 import 'package:flutter_screenutil/flutter_screenutil.dart';
13
 
14
 
14
 void main() async {
15
 void main() async {
15
   await GetStorage.init();
16
   await GetStorage.init();
17
+  registerWxApi(
18
+      appId: "wx0969b05b5393ae17",
19
+      doOnAndroid: true,
20
+      doOnIOS: true,
21
+      universalLink: "https://help.wechat.com/sdksample/njyz"
22
+  );
16
 
23
 
17
   // // 高德地图隐私生命
24
   // // 高德地图隐私生命
18
   // showPrivacy();
25
   // showPrivacy();
26
   // This widget is the root of your application.
33
   // This widget is the root of your application.
27
   @override
34
   @override
28
   Widget build(BuildContext context) {
35
   Widget build(BuildContext context) {
36
+
29
     return ScreenUtilInit(
37
     return ScreenUtilInit(
30
       designSize: const Size(375, 812),
38
       designSize: const Size(375, 812),
31
       minTextAdapt: true,
39
       minTextAdapt: true,
32
       splitScreenMode: true,
40
       splitScreenMode: true,
33
       builder: (context , child) {
41
       builder: (context , child) {
34
         return GetMaterialApp(
42
         return GetMaterialApp(
43
+
35
           localizationsDelegates: const [
44
           localizationsDelegates: const [
36
             GlobalMaterialLocalizations.delegate,
45
             GlobalMaterialLocalizations.delegate,
37
             GlobalWidgetsLocalizations.delegate,
46
             GlobalWidgetsLocalizations.delegate,
38
             GlobalCupertinoLocalizations.delegate,
47
             GlobalCupertinoLocalizations.delegate,
39
           ],
48
           ],
49
+
50
+
40
           supportedLocales: [
51
           supportedLocales: [
41
             Locale('zh', ''),
52
             Locale('zh', ''),
42
             Locale('en', ''),
53
             Locale('en', ''),

+ 1
- 1
lib/pages/OrderConfirmation/index.dart 查看文件

67
       generateOrder(data).then((value) {
67
       generateOrder(data).then((value) {
68
         orderInfo(OrderInfoModel.fromJson(value));
68
         orderInfo(OrderInfoModel.fromJson(value));
69
         Fluttertoast.showToast(msg: '预约成功');
69
         Fluttertoast.showToast(msg: '预约成功');
70
-        Get.offNamed('/orderPageInfo', arguments: {'id': orderInfo().orderId});
70
+        Get.offNamed('/orderPageInfo', arguments: {'id': orderInfo().orderId,'title':'待付款','styleColor':Color(0xFF51D4FF)});
71
       });
71
       });
72
       //验证通过提交数据
72
       //验证通过提交数据
73
     }
73
     }

+ 79
- 2
lib/pages/orderInfo/index.dart 查看文件

1
 import 'package:farmer_client/pages/orderInfo/widgets/star.dart';
1
 import 'package:farmer_client/pages/orderInfo/widgets/star.dart';
2
+import 'package:farmer_client/services/pay.dart';
2
 import 'package:farmer_client/widgets/DefaultButton.dart';
3
 import 'package:farmer_client/widgets/DefaultButton.dart';
3
 import 'package:ff_stars/ff_stars.dart';
4
 import 'package:ff_stars/ff_stars.dart';
4
 import 'package:flutter/material.dart';
5
 import 'package:flutter/material.dart';
7
 import 'package:fluttertoast/fluttertoast.dart';
8
 import 'package:fluttertoast/fluttertoast.dart';
8
 import 'package:get/get.dart';
9
 import 'package:get/get.dart';
9
 import 'package:farmer_client/widgets/Modal.dart' as modal;
10
 import 'package:farmer_client/widgets/Modal.dart' as modal;
11
+import 'package:fluwx/fluwx.dart' as fluwx;
10
 
12
 
11
 import '../../models/entities/OrderInfoModel.dart';
13
 import '../../models/entities/OrderInfoModel.dart';
12
 import '../../services/orderAPI.dart';
14
 import '../../services/orderAPI.dart';
28
   final evalStars = Rx<num>(-1);
30
   final evalStars = Rx<num>(-1);
29
 
31
 
30
   // orderStates
32
   // orderStates
31
-
32
   @override
33
   @override
33
   void beforeShow() {
34
   void beforeShow() {
34
     // TODO: implement beforeShow
35
     // TODO: implement beforeShow
35
     super.beforeShow();
36
     super.beforeShow();
36
     if (Get.arguments['id'] != null) {
37
     if (Get.arguments['id'] != null) {
37
       id(Get.arguments['id']);
38
       id(Get.arguments['id']);
39
+      print(Get.arguments);
38
 
40
 
39
       orderStateText(Get.arguments['title']);
41
       orderStateText(Get.arguments['title']);
40
       orderStateColor(Get.arguments['styleColor']);
42
       orderStateColor(Get.arguments['styleColor']);
251
 
253
 
252
   _BottomWidget({Key? key, required this.id}) : super(key: key);
254
   _BottomWidget({Key? key, required this.id}) : super(key: key);
253
 
255
 
256
+
254
   void _orderDeletels() {
257
   void _orderDeletels() {
255
     modal.showDialog(
258
     modal.showDialog(
256
         title: '提示',
259
         title: '提示',
266
               })
269
               })
267
             });
270
             });
268
   }
271
   }
272
+  Map result={
273
+    'appid':'wx0969b05b5393ae17',
274
+    'partnerid':'122asdas5551222',
275
+    'prepayid':'wsserrg996ae17',
276
+    'package':'hkrllfl,g://sdsadaa',
277
+    'noncestr':'1221222',
278
+    'timestamp':'e55s5a6a6s',
279
+    'sign':'92552d22f541g2f5sd',
280
+  };
281
+
282
+Future<void> payMoney (String payType) async {
283
+    if(payType=='wxPay'){
284
+      final isInstall=await fluwx.isWeChatInstalled;
285
+      if(!isInstall){
286
+        EasyLoading.showError('未安装微信');
287
+        print('isInstall--------$isInstall');
288
+        return;
289
+      }
290
+      createOrder(id, "wx").then((value) {
291
+        print('--------------微信支付-----------------');
292
+        print('result--------$value');
293
+        print('-------------------------------');
294
+        print("appid--------${value['appid']}");
295
+        print("partnerId--------${value['partnerId']}");
296
+        print("prepayId--------${value['prepayId']}");
297
+        print("packageValue--------${value['packageValue']}");
298
+        print("noncestr--------${value['noncestr']}");
299
+        print("timestamp--------${value['timestamp']}");
300
+        print("sign--------${value['sign']}");
301
+        fluwx.payWithWeChat(
302
+          appId: value['appid'].toString(),
303
+          partnerId: value['partnerId'].toString(),
304
+          prepayId: value['prepayId'].toString(),
305
+          packageValue: value['packageValue'].toString(),
306
+          nonceStr: value['noncestr'].toString(),
307
+          timeStamp: int.parse(value['timestamp'].toString()),
308
+          sign: value['sign'].toString(),
309
+        ).then((res) {
310
+          print("payWithWeChat--------${res}");
311
+        })
312
+        .catchError((onError){
313
+          print("payWithWeChat错误--------${onError}");
314
+        })
315
+        ;
316
+
317
+      });
318
+
319
+// 监听支付结果
320
+      fluwx.weChatResponseEventHandler.listen((event) async {
321
+        print(event.errCode);
322
+        // 支付成功
323
+        if (event.errCode == 0) {
324
+          EasyLoading.showSuccess('支付成功');
325
+
326
+        }else{
327
+          EasyLoading.showError('支付失败');
328
+
329
+        }
330
+        // 关闭弹窗
331
+      });
269
 
332
 
333
+
334
+      return;
335
+    }else if(payType=='aliPay'){
336
+      print('--------------支付宝支付-----------------');
337
+
338
+    }
339
+
340
+
341
+}
270
   //显示底部弹框的功能
342
   //显示底部弹框的功能
271
   void showBottomSheet(context) {
343
   void showBottomSheet(context) {
272
     //用于在底部打开弹框的效果
344
     //用于在底部打开弹框的效果
293
                 Padding(
365
                 Padding(
294
                   padding: EdgeInsets.fromLTRB(15.w, 0, 15.w, 0),
366
                   padding: EdgeInsets.fromLTRB(15.w, 0, 15.w, 0),
295
                   child: ListTile(
367
                   child: ListTile(
368
+                    onTap: (){
369
+                      payMoney('aliPay');
370
+                    },
296
                     contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
371
                     contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
297
                     // 这边使用了contentPadding
372
                     // 这边使用了contentPadding
298
                     leading: Image(
373
                     leading: Image(
316
                 Padding(
391
                 Padding(
317
                   padding: EdgeInsets.fromLTRB(15.w, 0, 15.w, 0),
392
                   padding: EdgeInsets.fromLTRB(15.w, 0, 15.w, 0),
318
                   child: ListTile(
393
                   child: ListTile(
319
-                    onTap: () {},
394
+                    onTap: () {
395
+                      payMoney('wxPay');
396
+                    },
320
                     contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
397
                     contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
321
                     // 这边使用了contentPadding
398
                     // 这边使用了contentPadding
322
                     leading: Image(
399
                     leading: Image(

+ 3
- 0
lib/services/homeAPI.dart 查看文件

91
 Future getMachineryType() async {
91
 Future getMachineryType() async {
92
   return request('/machinery-type', options: Options(method: 'GET'));
92
   return request('/machinery-type', options: Options(method: 'GET'));
93
 }
93
 }
94
+
95
+
96
+

+ 16
- 0
lib/services/pay.dart 查看文件

1
+import 'package:dio/dio.dart';
2
+import 'package:farmer_client/utils/Request.dart';
3
+import 'package:fluttertoast/fluttertoast.dart';
4
+
5
+/**
6
+ * 支付
7
+ * @param {*} data
8
+ * @returns
9
+ */
10
+Future createOrder(String id ,String payType) async {
11
+  return request('/order/${id}/prepay',data:{'payType':payType} , options: Options(method: 'POST'));
12
+}
13
+
14
+
15
+
16
+// /api/{client}/{clientId}/order/{id}/prepay

+ 2
- 2
lib/utils/Request.dart 查看文件

29
 
29
 
30
 Dio createRequest() {
30
 Dio createRequest() {
31
   var options = BaseOptions(
31
   var options = BaseOptions(
32
-    // baseUrl: 'https://machine.njyunzhi.com/api/' + client + '/farmer',
33
-    baseUrl: 'http://192.168.89.147:7080/api/' + client + '/farmer',
32
+    baseUrl: 'https://machine.njyunzhi.com/api/' + client + '/farmer',
33
+    // baseUrl: 'http://192.168.89.147:7080/api/' + client + '/farmer',
34
     connectTimeout: 5000,
34
     connectTimeout: 5000,
35
     receiveTimeout: 3000,
35
     receiveTimeout: 3000,
36
   );
36
   );

+ 1
- 1
lib/widgets/OrderInfoCard.dart 查看文件

171
                                 fontWeight: FontWeight.bold)),
171
                                 fontWeight: FontWeight.bold)),
172
                         TextSpan(
172
                         TextSpan(
173
                             text: orderStateText == null
173
                             text: orderStateText == null
174
-                                ? '支付'
174
+                                ? '支付'
175
                                 : orderStateText == '已付款'
175
                                 : orderStateText == '已付款'
176
                                     ? '已付款,待调度'
176
                                     ? '已付款,待调度'
177
                                     : orderStateText,
177
                                     : orderStateText,

+ 10
- 3
pubspec.lock 查看文件

185
     dependency: "direct main"
185
     dependency: "direct main"
186
     description:
186
     description:
187
       name: flutter_easyloading
187
       name: flutter_easyloading
188
-      url: "https://pub.flutter-io.cn"
188
+      url: "https://pub.dartlang.org"
189
     source: hosted
189
     source: hosted
190
-    version: "3.0.3"
190
+    version: "3.0.5"
191
   flutter_easyrefresh:
191
   flutter_easyrefresh:
192
     dependency: "direct main"
192
     dependency: "direct main"
193
     description:
193
     description:
225
     dependency: transitive
225
     dependency: transitive
226
     description:
226
     description:
227
       name: flutter_spinkit
227
       name: flutter_spinkit
228
-      url: "https://pub.flutter-io.cn"
228
+      url: "https://pub.dartlang.org"
229
     source: hosted
229
     source: hosted
230
     version: "5.1.0"
230
     version: "5.1.0"
231
   flutter_test:
231
   flutter_test:
245
       url: "https://pub.dartlang.org"
245
       url: "https://pub.dartlang.org"
246
     source: hosted
246
     source: hosted
247
     version: "8.0.9"
247
     version: "8.0.9"
248
+  fluwx:
249
+    dependency: "direct main"
250
+    description:
251
+      name: fluwx
252
+      url: "https://pub.dartlang.org"
253
+    source: hosted
254
+    version: "3.9.0+2"
248
   get:
255
   get:
249
     dependency: "direct main"
256
     dependency: "direct main"
250
     description:
257
     description:

+ 1
- 0
pubspec.yaml 查看文件

52
   ff_stars: ^1.0.0
52
   ff_stars: ^1.0.0
53
   flutter_easyloading: ^3.0.3
53
   flutter_easyloading: ^3.0.3
54
   flutter_easyrefresh: ^2.2.1 #下拉刷新上拉加载
54
   flutter_easyrefresh: ^2.2.1 #下拉刷新上拉加载
55
+  fluwx: ^3.9.0 #微信支付
55
 
56
 
56
 #  flutter_bmflocation: ^3.1.0+1
57
 #  flutter_bmflocation: ^3.1.0+1
57
 
58