推送相关 和确认协议

This commit is contained in:
YangYuhao 2023-08-15 16:48:14 +08:00
parent 153a2f07cc
commit 9f3972a8de
13 changed files with 374 additions and 92 deletions

View File

@ -71,6 +71,8 @@
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:showWhenLocked="true"
android:turnScreenOn="true"
android:networkSecurityConfig="@xml/network_security_config" android:networkSecurityConfig="@xml/network_security_config"
android:windowSoftInputMode="adjustResize"> android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as <!-- Specifies an Android theme to apply to this Activity as soon as

View File

@ -275,7 +275,7 @@ class InfoListViewState extends State<InfoListView> with AutomaticKeepAliveClien
return Container( return Container(
padding: EdgeInsets.only( padding: EdgeInsets.only(
left: 12.sp, right: 12.sp), left: 12.sp, right: 12.sp),
height:urlList.length==0?47.sp: 108.sp, height:urlList.length==0?47.sp: 118.sp,
decoration: BoxDecoration( decoration: BoxDecoration(
image: DecorationImage( image: DecorationImage(
fit: BoxFit.fill, fit: BoxFit.fill,

View File

@ -0,0 +1,198 @@
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:tencent_chat_push_for_china/tencent_chat_push_for_china.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
import '../../common/values/pushconfig.dart';
import '../../util/SharedPreferencesHelper.dart';
import '../../util/device.dart';
import '../../util/util.dart';
class YesAgreementDialog extends StatefulWidget {
@override
_CustomDialogState createState() => _CustomDialogState();
}
double myProgress = 0;
class _CustomDialogState extends State<YesAgreementDialog> {
bool isDownload = false;
void incrementCounter() {}
void setDownloadUi() {
setState(() {
isDownload = true;
});
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
print(getAgreemement());
return false;
},
child: Dialog(
backgroundColor: Colors.transparent,
child: Container(
height: 277.sp,
padding: const EdgeInsets.all(1.0),
child: Stack(
children: [
Container(
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(10.0),
gradient: const LinearGradient(
colors: [Color(0xFFDD3DF4), Color(0xFF30FFD9)],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
),
Container(
margin: EdgeInsets.all(1.sp),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(10.0),
gradient: const LinearGradient(
colors: [Color(0xFF4C3E5F), Color(0xFF324140)],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
margin: EdgeInsets.only(left: 10.sp, right: 10.sp),
child: RichText(
text: TextSpan(
text: "感谢您信任并使用跨友APP在你使用跨友的服务之前请认真阅读",
style: TextStyle(
color: Colors.white,
fontSize: 14.sp,
),
children: [
TextSpan(
text: "《用户协议》",
style: TextStyle(
color: Color(0xFF21BEAB),
),
recognizer: TapGestureRecognizer()
..onTap = () {
navigateToUserAgreement();
},
),
TextSpan(
text: "",
style: TextStyle(
color: Colors.white,
),
),
TextSpan(
text: "《隐私政策》",
style: TextStyle(
color: Color(0xFF21BEAB),
),
recognizer: TapGestureRecognizer()
..onTap = () {
navigateToPrivacyPolicy();
},
),
TextSpan(
text:
"的全部内容,以了解用户权力义务和个人信息处理规则。跨友仅会将您的信息用于提供服务和改善体验,我们将权力保障您的信息安全,请同意后使用,若您不同意本隐私政策,很遗憾,我们将无法为您提供完整的产品和服务。",
style: TextStyle(
color: Colors.white,
fontSize: 14.sp,
),
),
],
),
),
),
SizedBox(height: 10.sp),
GestureDetector(
onTap: () async {
//
var sp = await SharedPreferencesHelper.getInstance();
sp.setBool(SharedPreferencesHelper.AGREEMENT, true);
pushLoginPage();
uploadBuzIDAndToken();
},
child: Container(
width: 240.sp,
padding: EdgeInsets.symmetric(
vertical: 10,
horizontal: 44,
),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xFFDD3DF4), Color(0xFF30FFD9)],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
borderRadius: BorderRadius.circular(30),
),
child: Center(
child: Text(
"同意并继续使用",
style: TextStyle(
color: Colors.white,
fontSize: 16.sp,
),
),
),
),
),
TextButton(
onPressed: () {
//
exit(1);
},
child: Text(
"不同意并退出应用",
style: TextStyle(
color: Color(0xFFB8C2CC),
fontSize: 16.sp,
),
),
),
],
),
],
),
),
),
);
}
void uploadBuzIDAndToken() async {
final CoreServicesImpl coreInstance = TIMUIKitCore.getInstance();
await ChannelPush.init((msg) {});
int? businessID = await TimUiKitPushPlugin.getBuzId(PushConfig.appInfo);
String token = await ChannelPush.getDeviceToken();
ChannelPush.uploadToken();
print("token=" + token);
if (token != "") {
V2TimCallback res = await coreInstance.setOfflinePushConfig(
token: token, businessID: businessID);
print("token=" + res.code.toString());
}
}
}

View File

@ -31,9 +31,7 @@ class LoginLogic extends GetxController {
// TODO: implement onInit // TODO: implement onInit
super.onInit(); super.onInit();
SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
String loginPhone = String loginPhone = await sharedPreferences.getString(SharedPreferencesHelper.LOGINPHONE) ?? "";
await sharedPreferences.getString(SharedPreferencesHelper.LOGINPHONE) ??
"";
print(loginPhone); print(loginPhone);
phoneEditingController.text = loginPhone; phoneEditingController.text = loginPhone;
if (GetUtils.isPhoneNumber(loginPhone) && loginPhone.length == 11) { if (GetUtils.isPhoneNumber(loginPhone) && loginPhone.length == 11) {

View File

@ -1,8 +1,13 @@
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart'; import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import '../../router/app_routers.dart'; import '../../router/app_routers.dart';
import '../../util/SharedPreferencesHelper.dart'; import '../../util/SharedPreferencesHelper.dart';
import '../dialog/YesAgreementDialog.dart';
import 'state.dart'; import 'state.dart';
import '../../network/api.dart'; import '../../network/api.dart';
@ -27,7 +32,19 @@ class SplashLogic extends GetxController {
super.onInit(); super.onInit();
// await Future.delayed(Duration(seconds: 30)); // await Future.delayed(Duration(seconds: 30));
if ((await getAuthorization()).isEmpty) { if ((await getAuthorization()).isEmpty) {
if(Platform.isIOS){
pushLoginPage(); pushLoginPage();
return;
}
bool isAgreemement = await getAgreemement();
if(!isAgreemement){
showReportDialog();
}else{
pushLoginPage();
}
} else { } else {
var data = var data =
await DioManager.instance.put(url: Api.refreshToken, params: {}); await DioManager.instance.put(url: Api.refreshToken, params: {});
@ -63,4 +80,15 @@ class SplashLogic extends GetxController {
// Get.toNamed(AppRoutes.Home); // Get.toNamed(AppRoutes.Home);
} }
} }
void showReportDialog() {
FlutterNativeSplash.remove();
showDialog(
context: Get.context!,
barrierDismissible: false,
builder: (BuildContext context) {
return YesAgreementDialog();
});
}
} }

View File

@ -103,6 +103,7 @@ class UserinfoLogic extends GetxController {
userInfoBean = bean.data.user; userInfoBean = bean.data.user;
isVip = userInfoBean?.vip ?? 0; isVip = userInfoBean?.vip ?? 0;
imId = bean.data.accountId; imId = bean.data.accountId;
print("imId="+imId);
if (isMe) { if (isMe) {
isOnline = true; isOnline = true;
} else { } else {

View File

@ -4,6 +4,7 @@ import 'package:circle_app/main.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
import '../../components/my_app_bar.dart'; import '../../components/my_app_bar.dart';
import '../../router/app_routers.dart'; import '../../router/app_routers.dart';
@ -656,7 +657,15 @@ class MyTabbedScreenState extends State<UserinfoPage>
], ],
); );
} }
sendmsg(){
OfflinePushInfo(
title : '测试', // IM后台自动替换成 sender的昵称 => sender ID
desc : '测试', //
disablePush : false,
ext : 'null', // Conversation信息的JSONChatTUIKit的实例代码
androidOPPOChannelID : 'new_message', // OPPO的channel ID
);
}
Widget _buildAvatar1(UserinfoLogic controller) { Widget _buildAvatar1(UserinfoLogic controller) {
if (controller.userInfoBean == null) { if (controller.userInfoBean == null) {
return SizedBox( return SizedBox(

View File

@ -35,7 +35,9 @@ class PushConfig{
static const String OPPOPushAPPSECRET = "7d17a5b2b2fc43eda61005807002f654"; static const String OPPOPushAPPSECRET = "7d17a5b2b2fc43eda61005807002f654";
static const String OPPOPushAPPID = "31286141"; static const String OPPOPushAPPID = "31286141";
static const String OPPOChannelID = "new_message"; static const String OPPOChannelID = "new_message";
//appsecret:7d17a5b2b2fc43eda61005807002f654
//appserversecret:07a4d3b9f3f249d2954866706af000d9
//07a4d3b9f3f249d2954866706af000d9
// Business ID for Apple APNS 39381 39382 // Business ID for Apple APNS 39381 39382
static const ApplePushBuzID = 39381; static const ApplePushBuzID = 39381;
@ -73,8 +75,8 @@ class ChannelPush{
// create new notification channel // create new notification channel
cPush.createNotificationChannel( cPush.createNotificationChannel(
channelId: "new_message", channelId: PushConfig.OPPOChannelID,
channelName: "chat_message", channelName: "消息推送",
channelDescription: channelDescription:
"The notification for chat message from Tencent Cloud IM" "The notification for chat message from Tencent Cloud IM"
); );
@ -89,9 +91,6 @@ class ChannelPush{
return cPush.getDevicePushToken(); return cPush.getDevicePushToken();
} }
static Future<bool> uploadToken() async { static Future<bool> uploadToken() async {
return await cPush.uploadToken(PushConfig.appInfo); return await cPush.uploadToken(PushConfig.appInfo);
} }

View File

@ -33,11 +33,6 @@ final TUIChatSeparateViewModel chatSeparateViewModel =
TUIChatSeparateViewModel(); TUIChatSeparateViewModel();
void main() { void main() {
// FlutterError.onError = (FlutterErrorDetails details) {
// FlutterError.dumpErrorToConsole(details);
// // if (kReleaseMode)
// // //线
// };
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized(); WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding); FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
runApp(const MyApp()); runApp(const MyApp());
@ -64,9 +59,12 @@ logoutIM() async {
print(result.desc + '退出IM'); print(result.desc + '退出IM');
} }
//Token线 //Token线
void uploadBuzIDAndToken() async { void uploadBuzIDAndToken() async {
bool isAgreemement = await getAgreemement();
if(!isAgreemement){
return;
}
await ChannelPush.init((msg) {}); await ChannelPush.init((msg) {});
int? businessID = await TimUiKitPushPlugin.getBuzId(PushConfig.appInfo); int? businessID = await TimUiKitPushPlugin.getBuzId(PushConfig.appInfo);
@ -77,16 +75,12 @@ void uploadBuzIDAndToken() async {
print("token=" + token); print("token=" + token);
if (token != "") { if (token != "") {
V2TimCallback res = await coreInstance.setOfflinePushConfig( V2TimCallback res = await coreInstance.setOfflinePushConfig(
token: token, token: token, businessID: businessID);
businessID: businessID
);
print("token=" + res.code.toString()); print("token=" + res.code.toString());
} }
} }
initPush() { initPush() {
// final TimUiKitPushPlugin cPush = TimUiKitPushPlugin( // final TimUiKitPushPlugin cPush = TimUiKitPushPlugin(
// isUseGoogleFCM: true, // // isUseGoogleFCM: true, //
@ -95,7 +89,6 @@ initPush() {
// pushClickAction: pushClickAction, // STEP6讲解 // pushClickAction: pushClickAction, // STEP6讲解
// appInfo: PushConfig.appInfo, // STEP1做的appInfo // appInfo: PushConfig.appInfo, // STEP1做的appInfo
// ); // );
} }
// //
@ -231,7 +224,6 @@ sendCustomMsg(String userId, String data, String desc) async {
// //
//EventBusManager.fire(SendCoustomMessage(createCustomMessageRes)); //EventBusManager.fire(SendCoustomMessage(createCustomMessageRes));
// sendMessage时receiver则发个人用户单聊消息 // sendMessage时receiver则发个人用户单聊消息
// groupID则发群组消息 // groupID则发群组消息
// receiver与groupID则发群内的个人用户receiver能看见 // receiver与groupID则发群内的个人用户receiver能看见
@ -257,18 +249,21 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> with WidgetsBindingObserver { class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
AppLifecycleState? _lastLifecycleState; AppLifecycleState? _lastLifecycleState;
// This widget is the root of your application. // This widget is the root of your application.
final List<String> _guideList = ['bg', 'home_back']; final List<String> _guideList = ['bg', 'home_back'];
@override @override
void dispose() { void dispose() {
// WidgetsBinding.instance.removeObserver(this); WidgetsBinding.instance.removeObserver(this);
super.dispose(); super.dispose();
} }
@override @override
void initState() { void initState() {
initIM(); initIM();
// WidgetsBinding.instance.addObserver(this); WidgetsBinding.instance.addObserver(this);
if (Platform.isAndroid) { if (Platform.isAndroid) {
initWxApi(); initWxApi();
} }
@ -278,6 +273,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
super.initState(); super.initState();
addPayNotifi(); addPayNotifi();
} }
@override @override
void didChangeAppLifecycleState(AppLifecycleState state) async { void didChangeAppLifecycleState(AppLifecycleState state) async {
print("--" + state.toString()); print("--" + state.toString());
@ -292,33 +288,46 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
// //
unreadCount = getTotalUnreadMessageCountRes.data; // unreadCount = getTotalUnreadMessageCountRes.data; //
} }
print("state=" + state.toString());
if (Platform.isIOS) {
return;
}
switch (state) { switch (state) {
case AppLifecycleState.inactive: case AppLifecycleState.inactive:
TencentImSDKPlugin.v2TIMManager setOfflinePushStatus(
.getOfflinePushManager() status: AppStatus.background, totalCount: unreadCount);
.doBackground(unreadCount: unreadCount ?? 0);
if (unreadCount != null) { if (unreadCount != null) {
ChannelPush.setBadgeNum(unreadCount); ChannelPush.setBadgeNum(unreadCount);
} }
break; break;
case AppLifecycleState.resumed: case AppLifecycleState.resumed:
TencentImSDKPlugin.v2TIMManager setOfflinePushStatus(status: AppStatus.foreground);
.getOfflinePushManager()
.doForeground();
break; break;
case AppLifecycleState.paused: case AppLifecycleState.paused:
TencentImSDKPlugin.v2TIMManager setOfflinePushStatus(
.getOfflinePushManager() status: AppStatus.background, totalCount: unreadCount);
.doBackground(unreadCount: unreadCount ?? 0);
if (unreadCount != null) { if (unreadCount != null) {
ChannelPush.setBadgeNum(unreadCount); ChannelPush.setBadgeNum(unreadCount);
} }
break; break;
} }
}
@override
Future<V2TimCallback> setOfflinePushStatus(
{required AppStatus status, int? totalCount}) {
if (status == AppStatus.foreground) {
// status为前台时doForeground()
return TencentImSDKPlugin.v2TIMManager
.getOfflinePushManager()
.doForeground();
} else {
// status为后台时doBackground()
return TencentImSDKPlugin.v2TIMManager
.getOfflinePushManager()
.doBackground(unreadCount: totalCount ?? 0);
}
} }
getLoginStyle() async { getLoginStyle() async {
@ -355,7 +364,6 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
return; return;
} }
} }
} }
initIM() { initIM() {
@ -410,7 +418,8 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
loadBgImage() async { loadBgImage() async {
await precacheImage(precacheImages(_guideList.first), context); await precacheImage(precacheImages(_guideList.first), context);
await precacheImage(precacheImages(_guideList.last), context); await precacheImage(precacheImages(_guideList.last), context);
await precacheImage(AssetImage(getBaseImage('bg')), context,size: Size(Get.width, Get.height)); await precacheImage(AssetImage(getBaseImage('bg')), context,
size: Size(Get.width, Get.height));
} }
precacheImages(String image) { precacheImages(String image) {
@ -419,7 +428,6 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
//稿,dp //稿,dp
// configureDio(); // configureDio();
return ScreenUtilInit( return ScreenUtilInit(

View File

@ -5,6 +5,7 @@ import 'package:circle_app/util/util.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import '../util/SharedPreferencesHelper.dart';
import '../util/device.dart'; import '../util/device.dart';
import 'api.dart'; import 'api.dart';
import 'package:connectivity/connectivity.dart'; import 'package:connectivity/connectivity.dart';
@ -166,16 +167,32 @@ class DioManager {
try { try {
Response response; Response response;
Options options = Options(
var options = Options();
bool isAgreemement = await getAgreemement();
if(isAgreemement){
options = Options(
method: methodValues[method], headers: { method: methodValues[method], headers: {
"Authorization": await getAuthorization(), "Authorization": await getAuthorization(),
'VersionName': await getVersionName(), 'VersionName': await getVersionName(),
'VersionCode': await getVersionCode(), 'VersionCode': await getVersionCode(),
'OsVersion': await getDeviceId(),
'Platform': Platform.isIOS ? '1' : '0', 'Platform': Platform.isIOS ? '1' : '0',
'OsVersion': await getDeviceId(),
'Imei': await getImei(), 'Imei': await getImei(),
'Brand': await getBrand(), 'Brand': await getBrand(),
}); });
}else{
options = Options(
method: methodValues[method], headers: {
"Authorization": await getAuthorization(),
'VersionName': await getVersionName(),
'VersionCode': await getVersionCode(),
'Platform': Platform.isIOS ? '1' : '0',
});
}
print(">>>>>$params"); print(">>>>>$params");
/// ,. /// ,.

View File

@ -1,3 +1,5 @@
import 'dart:io';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
class SharedPreferencesHelper { class SharedPreferencesHelper {
@ -13,6 +15,8 @@ class SharedPreferencesHelper {
static const LOGINPHONE = 'loginPhone'; static const LOGINPHONE = 'loginPhone';
static const AGREEMENT = 'agreement';
static SharedPreferencesHelper? _instance; static SharedPreferencesHelper? _instance;
static SharedPreferences? _preferences; static SharedPreferences? _preferences;
@ -44,6 +48,10 @@ class SharedPreferencesHelper {
final prefs = preferences; final prefs = preferences;
prefs?.setInt(key, value) ?? 0; prefs?.setInt(key, value) ?? 0;
} }
setBool(String key, bool value) async {
final prefs = preferences;
prefs?.setBool(key, value) ?? 0;
}
int getInt(String key) { int getInt(String key) {
final prefs = preferences; final prefs = preferences;
@ -59,6 +67,8 @@ class SharedPreferencesHelper {
return preferences?.getInt(SharedPreferencesHelper.USERID).toString() ?? ''; return preferences?.getInt(SharedPreferencesHelper.USERID).toString() ?? '';
} }
bool? getBool(String key) { bool? getBool(String key) {
final prefs = preferences; final prefs = preferences;
return prefs?.getBool(key); return prefs?.getBool(key);

View File

@ -114,3 +114,13 @@ Future<String> getAuthorization() async {
token = sharedPreferences.getString(SharedPreferencesHelper.AUTHORIZATION)??""; token = sharedPreferences.getString(SharedPreferencesHelper.AUTHORIZATION)??"";
return token; return token;
} }
Future<bool> getAgreemement() async {
if(Platform.isIOS){
return true;
}
bool isAgreemement =false;
SharedPreferences sharedPreferences =await SharedPreferences.getInstance();
isAgreemement = sharedPreferences.getBool(SharedPreferencesHelper.AGREEMENT)??false;
return isAgreemement;
}

View File

@ -153,10 +153,12 @@ String convertToTenThousand(int number) {
pushLoginPage() async { pushLoginPage() async {
await logoutIM(); await logoutIM();
SharedPreferencesHelper.getInstance().then((sharedPreferences) { SharedPreferencesHelper.getInstance().then((sharedPreferences) {
String loginPhone = sharedPreferences.getString(SharedPreferencesHelper.LOGINPHONE); bool agreement = sharedPreferences.getBool(SharedPreferencesHelper.AGREEMENT)??false;
String loginPhone = sharedPreferences.getString(SharedPreferencesHelper.LOGINPHONE)??"";
print(loginPhone); print(loginPhone);
sharedPreferences.clear(); sharedPreferences.clear();
sharedPreferences.setString(SharedPreferencesHelper.LOGINPHONE, loginPhone); sharedPreferences.setString(SharedPreferencesHelper.LOGINPHONE, loginPhone);
sharedPreferences.setBool(SharedPreferencesHelper.AGREEMENT, agreement);
}); });
Get.offAllNamed(AppRoutes.Login); Get.offAllNamed(AppRoutes.Login);