推送相关 和确认协议

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:usesCleartextTraffic="true"
android:screenOrientation="portrait"
android:showWhenLocked="true"
android:turnScreenOn="true"
android:networkSecurityConfig="@xml/network_security_config"
android:windowSoftInputMode="adjustResize">
<!-- 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(
padding: EdgeInsets.only(
left: 12.sp, right: 12.sp),
height:urlList.length==0?47.sp: 108.sp,
height:urlList.length==0?47.sp: 118.sp,
decoration: BoxDecoration(
image: DecorationImage(
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
super.onInit();
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
String loginPhone =
await sharedPreferences.getString(SharedPreferencesHelper.LOGINPHONE) ??
"";
String loginPhone = await sharedPreferences.getString(SharedPreferencesHelper.LOGINPHONE) ?? "";
print(loginPhone);
phoneEditingController.text = loginPhone;
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:get/get.dart';
import '../../router/app_routers.dart';
import '../../util/SharedPreferencesHelper.dart';
import '../dialog/YesAgreementDialog.dart';
import 'state.dart';
import '../../network/api.dart';
@ -27,7 +32,19 @@ class SplashLogic extends GetxController {
super.onInit();
// await Future.delayed(Duration(seconds: 30));
if ((await getAuthorization()).isEmpty) {
if(Platform.isIOS){
pushLoginPage();
return;
}
bool isAgreemement = await getAgreemement();
if(!isAgreemement){
showReportDialog();
}else{
pushLoginPage();
}
} else {
var data =
await DioManager.instance.put(url: Api.refreshToken, params: {});
@ -63,4 +80,15 @@ class SplashLogic extends GetxController {
// 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;
isVip = userInfoBean?.vip ?? 0;
imId = bean.data.accountId;
print("imId="+imId);
if (isMe) {
isOnline = true;
} else {

View File

@ -4,6 +4,7 @@ import 'package:circle_app/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
import '../../components/my_app_bar.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) {
if (controller.userInfoBean == null) {
return SizedBox(

View File

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

View File

@ -33,11 +33,6 @@ final TUIChatSeparateViewModel chatSeparateViewModel =
TUIChatSeparateViewModel();
void main() {
// FlutterError.onError = (FlutterErrorDetails details) {
// FlutterError.dumpErrorToConsole(details);
// // if (kReleaseMode)
// // //线
// };
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
runApp(const MyApp());
@ -64,29 +59,28 @@ logoutIM() async {
print(result.desc + '退出IM');
}
//Token线
void uploadBuzIDAndToken() async {
await ChannelPush.init((msg) { });
bool isAgreemement = await getAgreemement();
if(!isAgreemement){
return;
}
await ChannelPush.init((msg) {});
int? businessID = await TimUiKitPushPlugin.getBuzId(PushConfig.appInfo);
String token = await ChannelPush.getDeviceToken();
ChannelPush.uploadToken();
print("token="+token);
print("token=" + token);
if (token != "") {
V2TimCallback res = await coreInstance.setOfflinePushConfig(
token: token,
businessID: businessID
);
print("token="+res.code.toString());
token: token, businessID: businessID);
print("token=" + res.code.toString());
}
}
initPush() {
// final TimUiKitPushPlugin cPush = TimUiKitPushPlugin(
// isUseGoogleFCM: true, //
@ -95,7 +89,6 @@ initPush() {
// pushClickAction: pushClickAction, // STEP6讲解
// appInfo: PushConfig.appInfo, // STEP1做的appInfo
// );
}
//
@ -142,7 +135,7 @@ createCustomMsg(String userId, String imId) async {
if (data['data']['both_cities'] != null) {
List city = data['data']['both_cities'];
print('城市'+city.toString());
print('城市' + city.toString());
if (city.isNotEmpty) {
desc = '你们都在${city.first}留下过足迹';
cityStr = '你们都在${city.first}留下过足迹';
@ -231,7 +224,6 @@ sendCustomMsg(String userId, String data, String desc) async {
//
//EventBusManager.fire(SendCoustomMessage(createCustomMessageRes));
// sendMessage时receiver则发个人用户单聊消息
// groupID则发群组消息
// receiver与groupID则发群内的个人用户receiver能看见
@ -257,18 +249,21 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
AppLifecycleState? _lastLifecycleState;
// This widget is the root of your application.
final List<String> _guideList = ['bg', 'home_back'];
@override
@override
void dispose() {
// WidgetsBinding.instance.removeObserver(this);
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void initState() {
initIM();
// WidgetsBinding.instance.addObserver(this);
WidgetsBinding.instance.addObserver(this);
if (Platform.isAndroid) {
initWxApi();
}
@ -278,8 +273,9 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
super.initState();
addPayNotifi();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) async{
void didChangeAppLifecycleState(AppLifecycleState state) async {
print("--" + state.toString());
_lastLifecycleState = state;
int? unreadCount = 0;
@ -290,35 +286,48 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
.getTotalUnreadMessageCount();
if (getTotalUnreadMessageCountRes.code == 0) {
//
unreadCount = getTotalUnreadMessageCountRes.data;//
unreadCount = getTotalUnreadMessageCountRes.data; //
}
print("state=" + state.toString());
if (Platform.isIOS) {
return;
}
switch (state) {
case AppLifecycleState.inactive:
TencentImSDKPlugin.v2TIMManager
.getOfflinePushManager()
.doBackground(unreadCount: unreadCount ?? 0);
if(unreadCount != null){
setOfflinePushStatus(
status: AppStatus.background, totalCount: unreadCount);
if (unreadCount != null) {
ChannelPush.setBadgeNum(unreadCount);
}
break;
case AppLifecycleState.resumed:
TencentImSDKPlugin.v2TIMManager
.getOfflinePushManager()
.doForeground();
setOfflinePushStatus(status: AppStatus.foreground);
break;
case AppLifecycleState.paused:
TencentImSDKPlugin.v2TIMManager
.getOfflinePushManager()
.doBackground(unreadCount: unreadCount ?? 0);
if(unreadCount != null){
setOfflinePushStatus(
status: AppStatus.background, totalCount: unreadCount);
if (unreadCount != null) {
ChannelPush.setBadgeNum(unreadCount);
}
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 {
@ -355,7 +364,6 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
return;
}
}
}
initIM() {
@ -372,11 +380,11 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
break;
case TIMCallbackType.API_ERROR:
//Prints the API error to console, and shows the error message.
if(callbackValue.errorCode==20007){
if (callbackValue.errorCode == 20007) {
showOKToast("您已被对方拉黑,换个人聊聊天吧~");
return;
}
if(callbackValue.errorCode==6015){
if (callbackValue.errorCode == 6015) {
return;
}
print(
@ -410,7 +418,8 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
loadBgImage() async {
await precacheImage(precacheImages(_guideList.first), 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) {
@ -419,7 +428,6 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
@override
Widget build(BuildContext context) {
//稿,dp
// configureDio();
return ScreenUtilInit(

View File

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

View File

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

View File

@ -114,3 +114,13 @@ Future<String> getAuthorization() async {
token = sharedPreferences.getString(SharedPreferencesHelper.AUTHORIZATION)??"";
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 {
await logoutIM();
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);
sharedPreferences.clear();
sharedPreferences.setString(SharedPreferencesHelper.LOGINPHONE, loginPhone);
sharedPreferences.setBool(SharedPreferencesHelper.AGREEMENT, agreement);
});
Get.offAllNamed(AppRoutes.Login);