戴余标 2 years ago
parent 890c23e739
commit 1ddc592131

@ -12,19 +12,16 @@ import 'package:power_logger/power_logger.dart';
import 'package:project_telephony/providers/user_provider.dart';
import 'package:project_telephony/ui/tab_navigator.dart';
import 'package:project_telephony/ui/user/privacy_rights_page.dart';
import 'package:provider/provider.dart';
import 'package:telephony/telephony.dart';
import 'package:project_telephony/utils/hive_store.dart';
void _sendSMS(String message, List<String> recipients) async {
try{
String result =
await sendSMS(message: message, recipients: recipients, sendDirect: true);
print(result);
} on PlatformException catch(e){
print(e.toString());
}
void _sendSMS(String message, List<String> recipents) async {
String _result = await sendSMS(message: message, recipients: recipents)
.catchError((onError) {
print(onError);
});
print(_result);
}
void main() async {
@ -69,24 +66,33 @@ void onStart() {
Timer.periodic(const Duration(seconds: 1), (timer) async {
CallState state = await Telephony.instance.callState;
callState = state.name;
// print(callState!+"$flag");
print(callState!+" $flag");
if (callState == "IDLE") {
if (flag != 0) {
flag = 0;
// print("object");
// final Iterable<CallLogEntry> result = await CallLog.query();
// phoneNum = result.first.number;
// // print(phoneNum);
List<String> recipents = ["13486828191"];
// CallState state = await telephony.callState;
_sendSMS("你好", recipents);
// phoneNum = result.first.number;
// // print(phoneNum);
// Phone.telephony.sendSms(
// to: phoneNum!,
// message: "hello",
// isMultipart: true,
// );
final Iterable<CallLogEntry> result = await CallLog.query();
phoneNum = result.first.number;
// print(phoneNum);
// String message = "This is a test message!";
// List<String> recipents = ["10000", "10086"];
// String _result = await sendSMS(message: message, recipients: recipents, sendDirect: true)
// .catchError((onError) {
// print(onError);
// });
// print(_result);
phoneNum = result.first.number;
print(phoneNum);
final SmsSendStatusListener listener = (SendStatus status) {
print(status);
};
Phone.telephony.sendSms(
to: phoneNum!,
message: "hello",
statusListener: listener,
isMultipart: true,
);
}
} else if (callState == "RINGING") {
flag++;

@ -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,
);

@ -132,7 +132,7 @@ class _LoginPageState extends State<LoginPage> {
data: {'phone': _phoneController.text, 'code': _smsCodeController.text});
if (base.code == 0) {
await UserTool.userProvider.setToken(base.data['token']);
Get.back();
Get.to(() => const TabNavigator());
} else {
CloudToast.show(base.msg);
}

@ -5,6 +5,7 @@ import 'package:permission_handler/permission_handler.dart';
import 'package:permission_handler_platform_interface/permission_handler_platform_interface.dart';
import 'package:project_telephony/base/base_style.dart';
import 'package:project_telephony/ui/login/login_page.dart';
import 'package:project_telephony/ui/tab_navigator.dart';
import 'package:project_telephony/ui/user/members_page.dart';
import 'package:project_telephony/ui/user/privacy_rights_page.dart';
import 'package:project_telephony/ui/widget/image_scaffold.dart';
@ -12,9 +13,15 @@ import 'package:project_telephony/ui/widget/plone_bottom.dart';
import 'package:project_telephony/ui/widget/plone_image_picker.dart';
import 'package:project_telephony/utils/headers.dart';
import 'package:project_telephony/utils/permissionutils.dart';
import 'package:provider/provider.dart';
import 'package:telephony/telephony.dart';
import '../../constants/api.dart';
import '../../model/network/api_client.dart';
import '../../permission.dart';
import '../../providers/user_provider.dart';
import '../../utils/toast/cloud_toast.dart';
import '../../utils/user_tool.dart';
import '../home/home_page.dart';
class UserPage extends StatefulWidget {
@ -26,13 +33,9 @@ class UserPage extends StatefulWidget {
final Telephony telephony = Telephony.instance;
@override
void initState() {}
class _UserPageState extends State<UserPage> {
bool vle = false;
bool tooken = true;
final userProvider = Provider.of<UserProvider>(Get.context!, listen: false);
@override
Widget build(BuildContext context) {
@ -55,17 +58,24 @@ class _UserPageState extends State<UserPage> {
_getSwitch(Assets.icons.sms.path, "短信标签", false),
// const Spacer(),
182.hb,
tooken?
PloneBottom(
border: false,
onTap: () {
Get.to(() => const HomePage());
},
textColor: const Color(0xFF1890FF),
color1: const Color(0xFFEBF5FF),
color2: const Color(0xFFEBF5FF),
text: "退出登录",
):const SizedBox()
userProvider.isLogin
? PloneBottom(
border: false,
onTap: () async{
var cancel = CloudToast.loading;
var base = await apiClient.request(API.manager.logout, showMessage: true);
if (base.code == 0) {
UserTool.userProvider.logout();
Get.offAll(const HomePage());
}
cancel();
},
textColor: const Color(0xFF1890FF),
color1: const Color(0xFFEBF5FF),
color2: const Color(0xFFEBF5FF),
text: "退出登录",
)
: const SizedBox()
]),
);
}
@ -84,7 +94,7 @@ class _UserPageState extends State<UserPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
tooken? "xxxxx": "登录/注册" ,
userProvider.isLogin ? userProvider.userInfo.name : "登录/注册",
style: TextStyle(
fontSize: BaseStyle.fontSize48,
color: BaseStyle.color333333,
@ -92,7 +102,7 @@ class _UserPageState extends State<UserPage> {
),
24.hb,
Text(
tooken ? "登录获取更多信息" : "欢迎您登录短信帮手",
userProvider.isLogin ? "欢迎您登录短信帮手" : "登录获取更多信息",
style: TextStyle(
fontSize: BaseStyle.fontSize28,
color: BaseStyle.color333333),

@ -1,166 +1,166 @@
// import 'dart:async';
// import 'dart:convert';
// import 'package:bot_toast/bot_toast.dart';
// import 'package:cloud_car/model/pay/wx_pay_model.dart';
// import 'package:cloud_car/utils/new_work/api_client.dart';
// import 'package:cloud_car/utils/toast/cloud_toast.dart';
// import 'package:dio/dio.dart';
// import 'package:flutter/foundation.dart';
// import 'package:fluwx/fluwx.dart';
// import 'package:power_logger/power_logger.dart';
// import 'package:tobias/tobias.dart';
// import '../model/pay/pay_model.dart';
// enum PAYTYPE {
// ///
// ali,
// ///
// wx,
// ///
// cash,
// ///pos
// pos
// }
// class PayUtil {
// static final PayUtil _instance = PayUtil._();
// factory PayUtil() => _instance;
// PayUtil._();
// void resultSatus(String status) {
// switch (status) {
// case '8000':
// BotToast.showText(text: '正在处理中');
// break;
// case '4000':
// BotToast.showText(text: '订单支付失败');
// break;
// case '5000':
// BotToast.showText(text: '重复请求');
// break;
// case '6001':
// BotToast.showText(text: ' 用户中途取消');
// break;
// case '6002':
// BotToast.showText(text: '网络连接出错');
// break;
// case '6004':
// BotToast.showText(text: '支付结果未知,请查询商户订单列表中订单的支付状态');
// break;
// default:
// BotToast.showText(text: '其他支付错误');
// break;
// }
// }
// String _resultStatus = '';
// ///
// ///
// Future<bool> callAliPay(String order, {String? apiPath}) async {
// var install = await isAliPayInstalled();
// if (!install) {
// BotToast.showText(text: '未安装支付宝!');
// return false;
// }
// Map<dynamic, dynamic> result = {};
// try {
// result = await aliPay(order);
// } catch (e) {
// if (kDebugMode) {
// print(e.toString());
// }
// }
// _resultStatus = result['resultStatus'];
// if (_resultStatus == '9000') {
// String res = result['result'];
// PayModel model = PayModel.fromJson(jsonDecode(res));
// if (apiPath != null) {
// bool confirmResult = await _confirmPayResult(
// apiPath, model.aliPayTradeAppPayResponse.outTradeNo);
// return confirmResult;
// } else {
// CloudToast.show('支付成功');
// return true;
// }
// } else {
// resultSatus(_resultStatus);
// return false;
// }
// }
// Future<bool> _confirmPayResult(String path, String code) async {
// try {
// int status = 0;
// for (var i = 0; i < 3; i++) {
// await Future.delayed(const Duration(milliseconds: 1000), () async {
// Response response = await apiClient.dio.get(path, queryParameters: {
// "code": code,
// });
// status = response.data['status'] as int;
// });
// if (status == 2) {
// break;
// }
// }
// if (status == 2) {
// BotToast.showText(text: '交易成功');
// return true;
// } else {
// BotToast.showText(text: '交易失败 错误码$status');
// return false;
// }
// } catch (e) {
// BotToast.showText(text: '网络请求错误');
// LoggerData.addData(e);
// 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 ?? '支付失败'}');
// CloudToast.show(event.errStr ?? '支付失败');
// if (payError != null) payError(event);
// //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);
// }
// }
import 'dart:async';
import 'dart:convert';
import 'package:bot_toast/bot_toast.dart';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:fluwx/fluwx.dart';
import 'package:power_logger/power_logger.dart';
import 'package:project_telephony/utils/toast/cloud_toast.dart';
import 'package:tobias/tobias.dart';
import '../model/network/api_client.dart';
import '../model/pay/pay_model.dart';
import '../model/pay/wx_pay_model.dart';
enum PAYTYPE {
///
ali,
///
wx,
///
cash,
///pos
pos
}
class PayUtil {
static final PayUtil _instance = PayUtil._();
factory PayUtil() => _instance;
PayUtil._();
void resultSatus(String status) {
switch (status) {
case '8000':
BotToast.showText(text: '正在处理中');
break;
case '4000':
BotToast.showText(text: '订单支付失败');
break;
case '5000':
BotToast.showText(text: '重复请求');
break;
case '6001':
BotToast.showText(text: ' 用户中途取消');
break;
case '6002':
BotToast.showText(text: '网络连接出错');
break;
case '6004':
BotToast.showText(text: '支付结果未知,请查询商户订单列表中订单的支付状态');
break;
default:
BotToast.showText(text: '其他支付错误');
break;
}
}
String _resultStatus = '';
///
///
Future<bool> callAliPay(String order, {String? apiPath}) async {
var install = await isAliPayInstalled();
if (!install) {
BotToast.showText(text: '未安装支付宝!');
return false;
}
Map<dynamic, dynamic> result = {};
try {
result = await aliPay(order);
} catch (e) {
if (kDebugMode) {
print(e.toString());
}
}
_resultStatus = result['resultStatus'];
if (_resultStatus == '9000') {
String res = result['result'];
PayModel model = PayModel.fromJson(jsonDecode(res));
if (apiPath != null) {
bool confirmResult = await _confirmPayResult(
apiPath, model.aliPayTradeAppPayResponse.outTradeNo);
return confirmResult;
} else {
CloudToast.show('支付成功');
return true;
}
} else {
resultSatus(_resultStatus);
return false;
}
}
Future<bool> _confirmPayResult(String path, String code) async {
try {
int status = 0;
for (var i = 0; i < 3; i++) {
await Future.delayed(const Duration(milliseconds: 1000), () async {
Response response = await apiClient.dio.get(path, queryParameters: {
"code": code,
});
status = response.data['status'] as int;
});
if (status == 2) {
break;
}
}
if (status == 2) {
BotToast.showText(text: '交易成功');
return true;
} else {
BotToast.showText(text: '交易失败 错误码$status');
return false;
}
} catch (e) {
BotToast.showText(text: '网络请求错误');
LoggerData.addData(e);
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 ?? '支付失败'}');
CloudToast.show(event.errStr ?? '支付失败');
if (payError != null) payError(event);
//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);
}
}

Loading…
Cancel
Save