微信支付封装

pull/1/head
张萌 3 years ago
parent 14c196f071
commit 0e3b3d098d

@ -1,4 +1,4 @@
{
"flutterSdkVersion": "2.8.1",
"flutterSdkVersion": "2.10.2",
"flavors": {}
}

@ -82,7 +82,12 @@ class MainInitialize {
static initWechat() {
if (kIsWeb || Platform.isMacOS) return;
registerWxApi(appId: AppConfig.wechatAppId);
var isAndroid = Platform.isAndroid;
registerWxApi(
appId: 'wx9bc3ffb23a749254',
doOnIOS: !isAndroid,
doOnAndroid: isAndroid,
universalLink: '');
}
static initWebSocket() {

@ -13,7 +13,7 @@ FacilityAppointmentModel _$FacilityAppointmentModelFromJson(
code: json['code'] as String,
status: json['status'] as int,
address: json['address'] as String,
reserveStartDate: json['reserveStartDate'] as String,
reserveEndDate: json['reserveEndDate'] as String,
reserveStartDate: json['reserveStartDate'] as String,
nullifyReason: json['nullifyReason'] as String?,
);

@ -13,7 +13,7 @@ FacilityTypeModel _$FacilityTypeModelFromJson(Map<String, dynamic> json) =>
name: json['name'] as String,
type: json['type'] as int,
num_: json['num'] as int,
imgUrls: (json['imgList'] as List<dynamic>?)
imgUrls: (json['imgUrls'] as List<dynamic>?)
?.map((e) => ImgModel.fromJson(e as Map<String, dynamic>))
.toList(),
);

@ -0,0 +1,37 @@
import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
part 'wx_pay_model.g.dart';
@JsonSerializable()
class WxPayModel extends Equatable {
final String prepayId;
final String partnerId;
final String timeStamp;
final String nonceStr;
final String package;
final String sign;
factory WxPayModel.fromJson(Map<String, dynamic> json) =>
_$WxPayModelFromJson(json);
const WxPayModel({
required this.prepayId,
required this.partnerId,
required this.timeStamp,
required this.nonceStr,
required this.package,
required this.sign,
});
@override
List<Object?> get props => [
prepayId,
partnerId,
timeStamp,
nonceStr,
package,
sign,
];
}

@ -0,0 +1,16 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'wx_pay_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
WxPayModel _$WxPayModelFromJson(Map<String, dynamic> json) => WxPayModel(
prepayId: json['prepayId'] as String,
partnerId: json['partnerId'] as String,
timeStamp: json['timeStamp'] as String,
nonceStr: json['nonceStr'] as String,
package: json['package'] as String,
sign: json['sign'] as String,
);

@ -1,9 +1,14 @@
import 'dart:async';
import 'dart:convert';
import 'dart:ui';
import 'package:aku_new_community/models/pay/pay_model.dart';
import 'package:aku_new_community/models/pay/wx_pay_model.dart';
import 'package:aku_new_community/utils/network/base_model.dart';
import 'package:aku_new_community/utils/network/net_util.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/foundation.dart';
import 'package:fluwx/fluwx.dart';
import 'package:power_logger/power_logger.dart';
import 'package:tobias/tobias.dart';
@ -22,6 +27,12 @@ enum PAYTYPE {
}
class PayUtil {
static final PayUtil _instance = PayUtil._();
factory PayUtil() => _instance;
PayUtil._();
///
void resultSatus(String status) {
switch (status) {
case '8000':
@ -49,7 +60,7 @@ class PayUtil {
}
String _resultStatus = '';
///
///
Future<bool> callAliPay(String order, String apiPath) async {
var install = await isAliPayInstalled();
@ -75,7 +86,7 @@ class PayUtil {
return false;
}
}
//
Future<bool> _confirmPayResult(String path, String code) async {
try {
late BaseModel base;
@ -102,4 +113,43 @@ class PayUtil {
return false;
}
}
///
StreamSubscription? _wxPayStream;
///
void wxPayAddListener(
{required VoidCallback paySuccess,
Function(BaseWeChatResponse)? payError}) {
_wxPayStream = weChatResponseEventHandler.listen((event) {
if (kDebugMode) {
print('errorCode:${event.errCode} errorStr:${event.errStr}');
}
if (event.errCode == 0) {
paySuccess();
} else {
LoggerData.addData(
'errorCode:${event.errCode} errorStr:${event.errStr ?? '支付失败'}');
BotToast.showText(text: event.errStr ?? '支付失败');
payError == null ? null : payError(event);
}
});
}
///
void removeWxPayListener() {
_wxPayStream?.cancel();
}
Future callWxPay({
required WxPayModel payModel,
}) async {
await payWithWeChat(
appId: 'wx9bc3ffb23a749254',
partnerId: payModel.partnerId,
prepayId: payModel.prepayId,
packageValue: payModel.package,
nonceStr: payModel.nonceStr,
timeStamp: int.parse(payModel.timeStamp),
sign: payModel.sign);
}
}

@ -23,7 +23,7 @@ Member _$MemberFromJson(Map<String, dynamic> json) => Member(
id: json['id'] as int,
name: json['name'] as String,
identity: json['identity'] as int,
avatarImgList: (json['imgList'] as List<dynamic>)
avatarImgList: (json['avatarImgList'] as List<dynamic>)
.map((e) => ImgModel.fromJson(e as Map<String, dynamic>))
.toList(),
);

@ -760,6 +760,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
meta:
dependency: transitive
description:
@ -1207,7 +1214,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
version: "0.4.8"
time:
dependency: transitive
description:

@ -55,7 +55,7 @@ dependencies:
#支付宝支付功能
tobias: ^2.4.0+2
#微信支付
fluwx: ^3.4.2
fluwx: ^3.8.3
#路由相关
get: ^4.1.4
#各种扩展

Loading…
Cancel
Save