Selaa lähdekoodia

add WeChatPay PaygoPage

[baozhangchao] 2 vuotta sitten
vanhempi
commit
d5628b584a

+ 1
- 0
android/build.gradle Näytä tiedosto

@@ -9,6 +9,7 @@ buildscript {
9 9
     dependencies {
10 10
         classpath 'com.android.tools.build:gradle:4.1.0'
11 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 Näytä tiedosto

@@ -2,6 +2,7 @@ import 'package:farmer_client/theme.dart';
2 2
 import 'package:farmer_client/utils/location.dart';
3 3
 import 'package:flutter/material.dart';
4 4
 import 'package:flutter_easyloading/flutter_easyloading.dart';
5
+import 'package:fluwx/fluwx.dart';
5 6
 import 'package:get/get.dart';
6 7
 import 'package:get_storage/get_storage.dart';
7 8
 import 'package:flutter_screenutil/flutter_screenutil.dart';
@@ -13,6 +14,12 @@ import 'routes/index.dart';
13 14
 
14 15
 void main() async {
15 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 25
   // showPrivacy();
@@ -26,17 +33,21 @@ class MyApp extends StatelessWidget {
26 33
   // This widget is the root of your application.
27 34
   @override
28 35
   Widget build(BuildContext context) {
36
+
29 37
     return ScreenUtilInit(
30 38
       designSize: const Size(375, 812),
31 39
       minTextAdapt: true,
32 40
       splitScreenMode: true,
33 41
       builder: (context , child) {
34 42
         return GetMaterialApp(
43
+
35 44
           localizationsDelegates: const [
36 45
             GlobalMaterialLocalizations.delegate,
37 46
             GlobalWidgetsLocalizations.delegate,
38 47
             GlobalCupertinoLocalizations.delegate,
39 48
           ],
49
+
50
+
40 51
           supportedLocales: [
41 52
             Locale('zh', ''),
42 53
             Locale('en', ''),

+ 1
- 1
lib/pages/OrderConfirmation/index.dart Näytä tiedosto

@@ -67,7 +67,7 @@ class OrderConfirmation extends BasicPage {
67 67
       generateOrder(data).then((value) {
68 68
         orderInfo(OrderInfoModel.fromJson(value));
69 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 Näytä tiedosto

@@ -1,4 +1,5 @@
1 1
 import 'package:farmer_client/pages/orderInfo/widgets/star.dart';
2
+import 'package:farmer_client/services/pay.dart';
2 3
 import 'package:farmer_client/widgets/DefaultButton.dart';
3 4
 import 'package:ff_stars/ff_stars.dart';
4 5
 import 'package:flutter/material.dart';
@@ -7,6 +8,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
7 8
 import 'package:fluttertoast/fluttertoast.dart';
8 9
 import 'package:get/get.dart';
9 10
 import 'package:farmer_client/widgets/Modal.dart' as modal;
11
+import 'package:fluwx/fluwx.dart' as fluwx;
10 12
 
11 13
 import '../../models/entities/OrderInfoModel.dart';
12 14
 import '../../services/orderAPI.dart';
@@ -28,13 +30,13 @@ class OrderPageInfo extends BasicPage {
28 30
   final evalStars = Rx<num>(-1);
29 31
 
30 32
   // orderStates
31
-
32 33
   @override
33 34
   void beforeShow() {
34 35
     // TODO: implement beforeShow
35 36
     super.beforeShow();
36 37
     if (Get.arguments['id'] != null) {
37 38
       id(Get.arguments['id']);
39
+      print(Get.arguments);
38 40
 
39 41
       orderStateText(Get.arguments['title']);
40 42
       orderStateColor(Get.arguments['styleColor']);
@@ -251,6 +253,7 @@ class _BottomWidget extends StatelessWidget {
251 253
 
252 254
   _BottomWidget({Key? key, required this.id}) : super(key: key);
253 255
 
256
+
254 257
   void _orderDeletels() {
255 258
     modal.showDialog(
256 259
         title: '提示',
@@ -266,7 +269,76 @@ class _BottomWidget extends StatelessWidget {
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 343
   void showBottomSheet(context) {
272 344
     //用于在底部打开弹框的效果
@@ -293,6 +365,9 @@ class _BottomWidget extends StatelessWidget {
293 365
                 Padding(
294 366
                   padding: EdgeInsets.fromLTRB(15.w, 0, 15.w, 0),
295 367
                   child: ListTile(
368
+                    onTap: (){
369
+                      payMoney('aliPay');
370
+                    },
296 371
                     contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
297 372
                     // 这边使用了contentPadding
298 373
                     leading: Image(
@@ -316,7 +391,9 @@ class _BottomWidget extends StatelessWidget {
316 391
                 Padding(
317 392
                   padding: EdgeInsets.fromLTRB(15.w, 0, 15.w, 0),
318 393
                   child: ListTile(
319
-                    onTap: () {},
394
+                    onTap: () {
395
+                      payMoney('wxPay');
396
+                    },
320 397
                     contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
321 398
                     // 这边使用了contentPadding
322 399
                     leading: Image(

+ 3
- 0
lib/services/homeAPI.dart Näytä tiedosto

@@ -91,3 +91,6 @@ Future getMachineryInfo(String id, String location, bool attached) async {
91 91
 Future getMachineryType() async {
92 92
   return request('/machinery-type', options: Options(method: 'GET'));
93 93
 }
94
+
95
+
96
+

+ 16
- 0
lib/services/pay.dart Näytä tiedosto

@@ -0,0 +1,16 @@
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 Näytä tiedosto

@@ -29,8 +29,8 @@ final client = GetPlatform.isAndroid ? 'android' : 'ios';
29 29
 
30 30
 Dio createRequest() {
31 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 34
     connectTimeout: 5000,
35 35
     receiveTimeout: 3000,
36 36
   );

+ 1
- 1
lib/widgets/OrderInfoCard.dart Näytä tiedosto

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

+ 10
- 3
pubspec.lock Näytä tiedosto

@@ -185,9 +185,9 @@ packages:
185 185
     dependency: "direct main"
186 186
     description:
187 187
       name: flutter_easyloading
188
-      url: "https://pub.flutter-io.cn"
188
+      url: "https://pub.dartlang.org"
189 189
     source: hosted
190
-    version: "3.0.3"
190
+    version: "3.0.5"
191 191
   flutter_easyrefresh:
192 192
     dependency: "direct main"
193 193
     description:
@@ -225,7 +225,7 @@ packages:
225 225
     dependency: transitive
226 226
     description:
227 227
       name: flutter_spinkit
228
-      url: "https://pub.flutter-io.cn"
228
+      url: "https://pub.dartlang.org"
229 229
     source: hosted
230 230
     version: "5.1.0"
231 231
   flutter_test:
@@ -245,6 +245,13 @@ packages:
245 245
       url: "https://pub.dartlang.org"
246 246
     source: hosted
247 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 255
   get:
249 256
     dependency: "direct main"
250 257
     description:

+ 1
- 0
pubspec.yaml Näytä tiedosto

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