import 'dart:io'; import 'package:fluwx/fluwx.dart'; import 'package:huixiang/data/base_data.dart'; import 'package:huixiang/data/order_info.dart'; import 'package:huixiang/data/place_order_first.dart'; import 'package:huixiang/data/wx_pay.dart'; import 'package:huixiang/retrofit/min_api.dart'; import 'package:huixiang/utils/min.dart'; class OrderUtils { static carryOnPay(payChannel, MinApiService? minService, OrderInfo? orderInfo, Function queryDetails) async { PlaceOrderFirst placeOrderFirst = PlaceOrderFirst(); placeOrderFirst.addressId = orderInfo?.addressExt?.addressId ?? ""; placeOrderFirst.isSubscribe = orderInfo?.isSubscribe; placeOrderFirst.isTakeOut = orderInfo?.isTakeOut; placeOrderFirst.notes = orderInfo?.notes; placeOrderFirst.id = orderInfo?.id; placeOrderFirst.orderProductVOList = orderInfo?.orderDetail?.orderProductList; placeOrderFirst.numberOfPeople = "0"; placeOrderFirst.orderSource = orderInfo?.orderSource; placeOrderFirst.orderType = "${orderInfo?.orderType}"; placeOrderFirst.orderTypeId = 0; placeOrderFirst.parentCode = orderInfo?.parentCode; // 火锅加菜 placeOrderFirst.parentId = orderInfo?.parentId; // 火锅加菜 placeOrderFirst.payChannel = payChannel; placeOrderFirst.promotionInfoDTO = PromotionInfoDTOBean(); placeOrderFirst.promotionInfoDTO?.promotionId = orderInfo?.promotionId; placeOrderFirst.promotionInfoDTO?.couponId = orderInfo?.couponId; placeOrderFirst.recMobile = ""; placeOrderFirst.shoppingCartSkuItemList = []; placeOrderFirst.skuItemDTOList = []; placeOrderFirst.source = 1; placeOrderFirst.storeId = orderInfo?.storeId; placeOrderFirst.subcribeTime = null; placeOrderFirst.tableId = orderInfo?.tableId; if (placeOrderFirst.payChannel == 1) { if(Platform.isAndroid){ if (!(await Min.isInitialize())) { // 小程序的微信支付和app的充值支付使用同一个WXPayEntryActivity回调, // 然而充值时小程序未初始化会导致回调内部代码调用getPackage空指针, // 故而在此初始化一下 await Min.initialize(); } } BaseData? baseData = await minService?.settlementWx(placeOrderFirst.toJson()) .catchError((error) {}); if (baseData?.isSuccess ?? false) { WxPay? wxPay = baseData!.data; if (wxPay?.isAnyEmpty() ?? true) { return; } Fluwx fluwx = Fluwx(); await fluwx.registerApi( appId: wxPay!.appId!, doOnAndroid: true, universalLink: "https://hx.lotus-wallet.com/app/", ); fluwx.pay( which: Payment( appId: wxPay.appId!, partnerId: wxPay.partnerId!, prepayId: wxPay.prepayId!, packageValue: wxPay.packageValue!, nonceStr: wxPay.nonceStr!, timestamp: int.tryParse(wxPay.timeStamp!) ?? 0, sign: wxPay.sign!, ) ); fluwx.addSubscriber((event) { print("payCallback: ${event.errCode}"); queryDetails(null); }); } } else { BaseData? baseData = await minService?.settlementApi(placeOrderFirst.toJson()) .catchError((error) {}); queryDetails(baseData); } } }