parent
99c86eb158
commit
e0012622d8
@ -0,0 +1,73 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
part 'pay_model.g.dart';
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class PayModel extends Equatable {
|
||||||
|
@JsonKey(name: 'alipay_trade_app_pay_response')
|
||||||
|
final AliPayTradeAppPayResponse aliPayTradeAppPayResponse;
|
||||||
|
final String sign;
|
||||||
|
@JsonKey(name: 'sign_type')
|
||||||
|
final String signType;
|
||||||
|
|
||||||
|
const PayModel({
|
||||||
|
required this.aliPayTradeAppPayResponse,
|
||||||
|
required this.sign,
|
||||||
|
required this.signType,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory PayModel.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$PayModelFromJson(json);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [aliPayTradeAppPayResponse, sign, signType];
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class AliPayTradeAppPayResponse extends Equatable {
|
||||||
|
final String code;
|
||||||
|
final String msg;
|
||||||
|
@JsonKey(name: 'app_id')
|
||||||
|
final String appId;
|
||||||
|
@JsonKey(name: 'out_trade_no')
|
||||||
|
final String outTradeNo;
|
||||||
|
@JsonKey(name: 'trade_no')
|
||||||
|
final String tradeNo;
|
||||||
|
@JsonKey(name: 'total_amount')
|
||||||
|
final String totalAmount;
|
||||||
|
@JsonKey(name: 'seller_id')
|
||||||
|
final String sellerId;
|
||||||
|
final String charset;
|
||||||
|
final String timestamp;
|
||||||
|
|
||||||
|
const AliPayTradeAppPayResponse({
|
||||||
|
required this.code,
|
||||||
|
required this.msg,
|
||||||
|
required this.appId,
|
||||||
|
required this.outTradeNo,
|
||||||
|
required this.tradeNo,
|
||||||
|
required this.totalAmount,
|
||||||
|
required this.sellerId,
|
||||||
|
required this.charset,
|
||||||
|
required this.timestamp,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory AliPayTradeAppPayResponse.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$AliPayTradeAppPayResponseFromJson(json);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props {
|
||||||
|
return [
|
||||||
|
code,
|
||||||
|
msg,
|
||||||
|
appId,
|
||||||
|
outTradeNo,
|
||||||
|
tradeNo,
|
||||||
|
totalAmount,
|
||||||
|
sellerId,
|
||||||
|
charset,
|
||||||
|
timestamp,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'pay_model.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonSerializableGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
PayModel _$PayModelFromJson(Map<String, dynamic> json) => PayModel(
|
||||||
|
aliPayTradeAppPayResponse: AliPayTradeAppPayResponse.fromJson(
|
||||||
|
json['alipay_trade_app_pay_response'] as Map<String, dynamic>),
|
||||||
|
sign: json['sign'] as String,
|
||||||
|
signType: json['sign_type'] as String,
|
||||||
|
);
|
||||||
|
|
||||||
|
AliPayTradeAppPayResponse _$AliPayTradeAppPayResponseFromJson(
|
||||||
|
Map<String, dynamic> json) =>
|
||||||
|
AliPayTradeAppPayResponse(
|
||||||
|
code: json['code'] as String,
|
||||||
|
msg: json['msg'] as String,
|
||||||
|
appId: json['app_id'] as String,
|
||||||
|
outTradeNo: json['out_trade_no'] as String,
|
||||||
|
tradeNo: json['trade_no'] as String,
|
||||||
|
totalAmount: json['total_amount'] as String,
|
||||||
|
sellerId: json['seller_id'] as String,
|
||||||
|
charset: json['charset'] as String,
|
||||||
|
timestamp: json['timestamp'] as String,
|
||||||
|
);
|
@ -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,166 +1,166 @@
|
|||||||
// import 'dart:async';
|
import 'dart:async';
|
||||||
// import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
// import 'package:bot_toast/bot_toast.dart';
|
import 'package:bot_toast/bot_toast.dart';
|
||||||
// import 'package:cloud_car/model/pay/wx_pay_model.dart';
|
import 'package:dio/dio.dart';
|
||||||
// import 'package:cloud_car/utils/new_work/api_client.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
// import 'package:cloud_car/utils/toast/cloud_toast.dart';
|
import 'package:fluwx/fluwx.dart';
|
||||||
// import 'package:dio/dio.dart';
|
import 'package:power_logger/power_logger.dart';
|
||||||
// import 'package:flutter/foundation.dart';
|
import 'package:project_telephony/utils/toast/cloud_toast.dart';
|
||||||
// import 'package:fluwx/fluwx.dart';
|
import 'package:tobias/tobias.dart';
|
||||||
// import 'package:power_logger/power_logger.dart';
|
|
||||||
// import 'package:tobias/tobias.dart';
|
import '../model/network/api_client.dart';
|
||||||
|
import '../model/pay/pay_model.dart';
|
||||||
// import '../model/pay/pay_model.dart';
|
import '../model/pay/wx_pay_model.dart';
|
||||||
|
|
||||||
// enum PAYTYPE {
|
enum PAYTYPE {
|
||||||
// ///支付宝
|
///支付宝
|
||||||
// ali,
|
ali,
|
||||||
|
|
||||||
// ///微信
|
///微信
|
||||||
// wx,
|
wx,
|
||||||
|
|
||||||
// ///现金
|
///现金
|
||||||
// cash,
|
cash,
|
||||||
|
|
||||||
// ///pos
|
///pos
|
||||||
// pos
|
pos
|
||||||
// }
|
}
|
||||||
|
|
||||||
// class PayUtil {
|
class PayUtil {
|
||||||
// static final PayUtil _instance = PayUtil._();
|
static final PayUtil _instance = PayUtil._();
|
||||||
|
|
||||||
// factory PayUtil() => _instance;
|
factory PayUtil() => _instance;
|
||||||
|
|
||||||
// PayUtil._();
|
PayUtil._();
|
||||||
|
|
||||||
// void resultSatus(String status) {
|
void resultSatus(String status) {
|
||||||
// switch (status) {
|
switch (status) {
|
||||||
// case '8000':
|
case '8000':
|
||||||
// BotToast.showText(text: '正在处理中');
|
BotToast.showText(text: '正在处理中');
|
||||||
// break;
|
break;
|
||||||
// case '4000':
|
case '4000':
|
||||||
// BotToast.showText(text: '订单支付失败');
|
BotToast.showText(text: '订单支付失败');
|
||||||
// break;
|
break;
|
||||||
// case '5000':
|
case '5000':
|
||||||
// BotToast.showText(text: '重复请求');
|
BotToast.showText(text: '重复请求');
|
||||||
// break;
|
break;
|
||||||
// case '6001':
|
case '6001':
|
||||||
// BotToast.showText(text: ' 用户中途取消');
|
BotToast.showText(text: ' 用户中途取消');
|
||||||
// break;
|
break;
|
||||||
// case '6002':
|
case '6002':
|
||||||
// BotToast.showText(text: '网络连接出错');
|
BotToast.showText(text: '网络连接出错');
|
||||||
// break;
|
break;
|
||||||
// case '6004':
|
case '6004':
|
||||||
// BotToast.showText(text: '支付结果未知,请查询商户订单列表中订单的支付状态');
|
BotToast.showText(text: '支付结果未知,请查询商户订单列表中订单的支付状态');
|
||||||
// break;
|
break;
|
||||||
// default:
|
default:
|
||||||
// BotToast.showText(text: '其他支付错误');
|
BotToast.showText(text: '其他支付错误');
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// String _resultStatus = '';
|
String _resultStatus = '';
|
||||||
|
|
||||||
// ///支付宝支付
|
///支付宝支付
|
||||||
// ///传入订单信息和确认订单请求地址
|
///传入订单信息和确认订单请求地址
|
||||||
// Future<bool> callAliPay(String order, {String? apiPath}) async {
|
Future<bool> callAliPay(String order, {String? apiPath}) async {
|
||||||
// var install = await isAliPayInstalled();
|
var install = await isAliPayInstalled();
|
||||||
// if (!install) {
|
if (!install) {
|
||||||
// BotToast.showText(text: '未安装支付宝!');
|
BotToast.showText(text: '未安装支付宝!');
|
||||||
// return false;
|
return false;
|
||||||
// }
|
}
|
||||||
// Map<dynamic, dynamic> result = {};
|
Map<dynamic, dynamic> result = {};
|
||||||
// try {
|
try {
|
||||||
// result = await aliPay(order);
|
result = await aliPay(order);
|
||||||
// } catch (e) {
|
} catch (e) {
|
||||||
// if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
// print(e.toString());
|
print(e.toString());
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// _resultStatus = result['resultStatus'];
|
_resultStatus = result['resultStatus'];
|
||||||
// if (_resultStatus == '9000') {
|
if (_resultStatus == '9000') {
|
||||||
// String res = result['result'];
|
String res = result['result'];
|
||||||
// PayModel model = PayModel.fromJson(jsonDecode(res));
|
PayModel model = PayModel.fromJson(jsonDecode(res));
|
||||||
// if (apiPath != null) {
|
if (apiPath != null) {
|
||||||
// bool confirmResult = await _confirmPayResult(
|
bool confirmResult = await _confirmPayResult(
|
||||||
// apiPath, model.aliPayTradeAppPayResponse.outTradeNo);
|
apiPath, model.aliPayTradeAppPayResponse.outTradeNo);
|
||||||
// return confirmResult;
|
return confirmResult;
|
||||||
// } else {
|
} else {
|
||||||
// CloudToast.show('支付成功');
|
CloudToast.show('支付成功');
|
||||||
// return true;
|
return true;
|
||||||
// }
|
}
|
||||||
// } else {
|
} else {
|
||||||
// resultSatus(_resultStatus);
|
resultSatus(_resultStatus);
|
||||||
// return false;
|
return false;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Future<bool> _confirmPayResult(String path, String code) async {
|
Future<bool> _confirmPayResult(String path, String code) async {
|
||||||
// try {
|
try {
|
||||||
// int status = 0;
|
int status = 0;
|
||||||
// for (var i = 0; i < 3; i++) {
|
for (var i = 0; i < 3; i++) {
|
||||||
// await Future.delayed(const Duration(milliseconds: 1000), () async {
|
await Future.delayed(const Duration(milliseconds: 1000), () async {
|
||||||
// Response response = await apiClient.dio.get(path, queryParameters: {
|
Response response = await apiClient.dio.get(path, queryParameters: {
|
||||||
// "code": code,
|
"code": code,
|
||||||
// });
|
});
|
||||||
// status = response.data['status'] as int;
|
status = response.data['status'] as int;
|
||||||
// });
|
});
|
||||||
// if (status == 2) {
|
if (status == 2) {
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// if (status == 2) {
|
if (status == 2) {
|
||||||
// BotToast.showText(text: '交易成功');
|
BotToast.showText(text: '交易成功');
|
||||||
// return true;
|
return true;
|
||||||
// } else {
|
} else {
|
||||||
// BotToast.showText(text: '交易失败 错误码$status');
|
BotToast.showText(text: '交易失败 错误码$status');
|
||||||
// return false;
|
return false;
|
||||||
// }
|
}
|
||||||
// } catch (e) {
|
} catch (e) {
|
||||||
// BotToast.showText(text: '网络请求错误');
|
BotToast.showText(text: '网络请求错误');
|
||||||
// LoggerData.addData(e);
|
LoggerData.addData(e);
|
||||||
// return false;
|
return false;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// ///微信支付
|
///微信支付
|
||||||
|
|
||||||
// StreamSubscription? _wxPayStream;
|
StreamSubscription? _wxPayStream;
|
||||||
|
|
||||||
// void wxPayAddListener(
|
void wxPayAddListener(
|
||||||
// {required VoidCallback paySuccess,
|
{required VoidCallback paySuccess,
|
||||||
// Function(BaseWeChatResponse)? payError}) {
|
Function(BaseWeChatResponse)? payError}) {
|
||||||
// _wxPayStream = weChatResponseEventHandler.listen((event) {
|
_wxPayStream = weChatResponseEventHandler.listen((event) {
|
||||||
// if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
// print('errorCode:${event.errCode} errorStr:${event.errStr}');
|
print('errorCode:${event.errCode} errorStr:${event.errStr}');
|
||||||
// }
|
}
|
||||||
// if (event.errCode == 0) {
|
if (event.errCode == 0) {
|
||||||
// paySuccess();
|
paySuccess();
|
||||||
// } else {
|
} else {
|
||||||
// LoggerData.addData(
|
LoggerData.addData(
|
||||||
// 'errorCode:${event.errCode} errorStr:${event.errStr ?? '支付失败'}');
|
'errorCode:${event.errCode} errorStr:${event.errStr ?? '支付失败'}');
|
||||||
// CloudToast.show(event.errStr ?? '支付失败');
|
CloudToast.show(event.errStr ?? '支付失败');
|
||||||
// if (payError != null) payError(event);
|
if (payError != null) payError(event);
|
||||||
// //payError == null ? null : payError(event);
|
//payError == null ? null : payError(event);
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
|
|
||||||
// void removeWxPayListener() {
|
void removeWxPayListener() {
|
||||||
// _wxPayStream?.cancel();
|
_wxPayStream?.cancel();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Future callWxPay({
|
Future callWxPay({
|
||||||
// required WxPayModel payModel,
|
required WxPayModel payModel,
|
||||||
// }) async {
|
}) async {
|
||||||
// await payWithWeChat(
|
await payWithWeChat(
|
||||||
// appId: 'wx9bc3ffb23a749254',
|
appId: 'wx9bc3ffb23a749254',
|
||||||
// partnerId: payModel.partnerId,
|
partnerId: payModel.partnerId,
|
||||||
// prepayId: payModel.prepayId,
|
prepayId: payModel.prepayId,
|
||||||
// packageValue: payModel.package,
|
packageValue: payModel.package,
|
||||||
// nonceStr: payModel.nonceStr,
|
nonceStr: payModel.nonceStr,
|
||||||
// timeStamp: int.parse(payModel.timeStamp),
|
timeStamp: int.parse(payModel.timeStamp),
|
||||||
// sign: payModel.sign);
|
sign: payModel.sign);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
Loading…
Reference in new issue