王亚玲 2 years ago
commit 58f08ecc1a

@ -5,6 +5,7 @@ import 'package:project_telephony/utils/user_tool.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../constants/api.dart'; import '../constants/api.dart';
import '../model/exclude_phone_model.dart';
import '../model/login_info_model.dart'; import '../model/login_info_model.dart';
import '../model/network/api_client.dart'; import '../model/network/api_client.dart';
import '../model/user_info_model.dart'; import '../model/user_info_model.dart';
@ -52,8 +53,9 @@ class UserProvider extends ChangeNotifier {
_isLogin = true; _isLogin = true;
//app //app
await updateUserInfo(); await updateUserInfo();
updateConSms(); updateConSms();
updateRefSms(); updateRefSms();
getExclude();
} }
Future logout() async { Future logout() async {
@ -79,11 +81,13 @@ class UserProvider extends ChangeNotifier {
var base = await apiClient.request(API.app.find, data: {'status': 1}); var base = await apiClient.request(API.app.find, data: {'status': 1});
if (base.code == 0) { if (base.code == 0) {
await prefs.remove('conSms'); await prefs.remove('conSms');
await prefs.setString('conSms', (UserTool.userProvider.userInfo.tag)==""?"${base await prefs.setString(
.data['content']}":"${UserTool.userProvider.userInfo.tag}${base 'conSms',
.data['content']}"); (UserTool.userProvider.userInfo.tag) == ""
? "${base.data['content']}"
: "${UserTool.userProvider.userInfo.tag}${base.data['content']}");
service.invoke("stopService"); service.invoke("stopService");
if(prefs.getBool('kg')!){ if (prefs.getBool('kg')!) {
Future.delayed(const Duration(seconds: 1), () async { Future.delayed(const Duration(seconds: 1), () async {
service.startService(); service.startService();
}); });
@ -91,7 +95,6 @@ class UserProvider extends ChangeNotifier {
} else { } else {
CloudToast.show(base.msg); CloudToast.show(base.msg);
} }
notifyListeners(); notifyListeners();
} }
@ -101,11 +104,32 @@ class UserProvider extends ChangeNotifier {
var base = await apiClient.request(API.app.find, data: {'status': 2}); var base = await apiClient.request(API.app.find, data: {'status': 2});
if (base.code == 0) { if (base.code == 0) {
await prefs.remove('refSms'); await prefs.remove('refSms');
await prefs.setString('refSms', (UserTool.userProvider.userInfo.tag)==""?"${base await prefs.setString(
.data['content']}":"${UserTool.userProvider.userInfo.tag}${base 'refSms',
.data['content']}" ); (UserTool.userProvider.userInfo.tag) == ""
? "${base.data['content']}"
: "${UserTool.userProvider.userInfo.tag}${base.data['content']}");
service.invoke("stopService");
if (prefs.getBool('kg')!) {
Future.delayed(const Duration(seconds: 1), () async {
service.startService();
});
}
} else {
CloudToast.show(base.msg);
}
notifyListeners();
}
Future getExclude() async {
final prefs = await SharedPreferences.getInstance();
final service = FlutterBackgroundService();
var base = await apiClient.request(API.exclude.find);
if (base.code == 0) {
await prefs.remove('exclude');
await prefs.setStringList('exclude', base.data);
service.invoke("stopService"); service.invoke("stopService");
if(prefs.getBool('kg')!){ if (prefs.getBool('kg')!) {
Future.delayed(const Duration(seconds: 1), () async { Future.delayed(const Duration(seconds: 1), () async {
service.startService(); service.startService();
}); });

@ -1,14 +1,8 @@
import 'dart:async'; import 'dart:async';
import 'dart:ui'; import 'dart:ui';
import 'package:call_log/call_log.dart'; import 'package:call_log/call_log.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter_background_service/flutter_background_service.dart'; import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:flutter_background_service_android/flutter_background_service_android.dart';
import 'package:flutter_background_service_android/flutter_background_service_android.dart';
import 'package:project_telephony/utils/headers.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:telephony/telephony.dart'; import 'package:telephony/telephony.dart';
@ -49,10 +43,7 @@ void onStart(ServiceInstance service) async {
int flag = 0; int flag = 0;
String? phoneNum = ""; String? phoneNum = "";
int? callRecords = 0; int? callRecords = 0;
String? state1="";
// CallType? state1;
String callState; String callState;
final Iterable<CallLogEntry> entry = await CallLog.query();
service.on('stopService').listen((event) { service.on('stopService').listen((event) {
service.stopSelf(); service.stopSelf();
}); });
@ -70,11 +61,7 @@ void onStart(ServiceInstance service) async {
print(callState+"$flag"); print(callState+"$flag");
String? ref = prefs.getString('refSms'); String? ref = prefs.getString('refSms');
String? con = prefs.getString('conSms'); String? con = prefs.getString('conSms');
// print(con);
if (callState == "IDLE") { if (callState == "IDLE") {
//
if (flag != 0) { if (flag != 0) {
final Iterable<CallLogEntry> entry = await CallLog.query(); final Iterable<CallLogEntry> entry = await CallLog.query();
phoneNum = entry.first.number; phoneNum = entry.first.number;
@ -82,11 +69,11 @@ void onStart(ServiceInstance service) async {
print(phoneNum); print(phoneNum);
if (flag > 0) { if (flag > 0) {
print("来电拒接/未接"); print("来电拒接/未接");
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref!); Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref!);
print("发送成功"); print("发送成功");
} else if(flag==-1){ } else if(flag==-1){
print("来电接听"); print("来电接听");
// Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con!); Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con!);
}else { }else {
print(entry.first.callType); print(entry.first.callType);
print(entry.first.duration); print(entry.first.duration);

Loading…
Cancel
Save