Sfoglia il codice sorgente

[feat]添加极光推送

云天逵 7 mesi fa
parent
commit
c1787d7fda

File diff suppressed because it is too large
+ 1 - 0
android/app/agconnect-services.json


+ 40 - 2
android/app/build.gradle.kts

@@ -1,13 +1,16 @@
 import java.time.LocalDateTime
 import java.time.format.DateTimeFormatter
 import java.time.ZoneId
+
 plugins {
     id("com.android.application")
     id("kotlin-android")
     // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
     id("dev.flutter.flutter-gradle-plugin")
+    id("com.huawei.agconnect")
 }
 
+
 android {
     namespace = "com.atmob.keyboard"
     compileSdk = rootProject.extra["compileSdkVersion"] as Int
@@ -32,9 +35,24 @@ android {
         versionName = flutter.versionName
 
         ndk {
-
             abiFilters.add("arm64-v8a")
         }
+
+        manifestPlaceholders.putAll(
+            mapOf(
+                "JPUSH_PKGNAME" to applicationId!!,
+                "JPUSH_APPKEY" to "e4c8b538fa1046eccce756de",
+                "JPUSH_CHANNEL" to "developer-default",
+                "XIAOMI_APPKEY" to "5652041165266",
+                "XIAOMI_APPID" to "2882303761520411266",
+                "VIVO_APPKEY" to "37b75015089824508ddc711e385a3df3",
+                "VIVO_APPID" to "105899223",
+                "OPPO_APPKEY" to "OP-2cc9d48944b440ac9480292cf80bbac5",
+                "OPPO_APPID" to "OP-33224191",
+                "OPPO_APPSECRET" to "OP-989965607b044943b8b1b610385cf404",
+                "HONOR_APPID" to "104498449",
+            )
+        )
     }
     signingConfigs {
         create("keyboard") {
@@ -82,8 +100,28 @@ android {
             }
     }
 
+    dependencies {
+
+        implementation("cn.jiguang.sdk.plugin:xiaomi:5.7.0")
+
+        implementation("cn.jiguang.sdk.plugin:vivo:5.7.0")
+
+        implementation("cn.jiguang.sdk.plugin:oppo:5.7.0")
+
+        implementation("cn.jiguang.sdk.plugin:honor:5.7.0")
+
+        implementation("com.google.code.gson:gson:2.6.2")
+        implementation("commons-codec:commons-codec:1.6")
+        implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))
+        implementation("androidx.annotation:annotation:1.1.0")
+
+        implementation ("com.huawei.hms:push:6.12.0.300")
+        implementation ("cn.jiguang.sdk.plugin:huawei:5.7.0")
+    }
+
+
 }
 
 flutter {
-    source = "../.."
+source = "../.."
 }

BIN
android/app/libs/HiPushSDK-8.0.12.307.aar


BIN
android/app/libs/com.heytap.msp_3.5.3.aar


+ 70 - 1
android/app/proguard-rules.pro

@@ -144,4 +144,73 @@ public <methods>;
 -keepattributes Signature
 -keep class com.google.gson.reflect.TypeToken { *; }
 -keep class * extends com.google.gson.reflect.TypeToken
--keepattributes AnnotationDefault,RuntimeVisibleAnnotations
+-keepattributes AnnotationDefault,RuntimeVisibleAnnotations
+
+
+# ==================================== 小米推送 ====================================
+-dontwarn com.xiaomi.push.**
+-keep class com.xiaomi.push.** { *; }
+
+# ==================================== 小米推送 end ====================================
+
+# ==================================== oppo推送 ====================================
+-dontwarn com.coloros.mcsdk.**
+-keep class com.coloros.mcsdk.** { *; }
+
+-dontwarn com.heytap.**
+-keep class com.heytap.** { *; }
+
+-dontwarn com.mcs.**
+-keep class com.mcs.** { *; }
+
+# ==================================== oppo推送 end ====================================
+
+# ==================================== vivo推送 ====================================
+-dontwarn com.vivo.push.**
+-keep class com.vivo.push.**{*; }
+-keep class com.vivo.vms.**{*; }
+
+
+# ==================================== vivo推送 end ====================================
+
+
+# ==================================== 荣耀推送 ====================================
+
+-ignorewarnings
+-keepattributes *Annotation*
+-keepattributes Exceptions
+-keepattributes InnerClasses
+-keepattributes Signature
+-keepattributes SourceFile,LineNumberTable
+-keep class com.hihonor.push.**{*;}
+
+# ==================================== 荣耀推送 end ====================================
+
+
+#====================================华为推送 start=====================================
+-ignorewarnings
+-keepattributes *Annotation*
+-keepattributes Exceptions
+-keepattributes InnerClasses
+-keepattributes Signature
+-keepattributes SourceFile,LineNumberTable
+-keep class com.hianalytics.android.**{*;}
+-keep class com.huawei.updatesdk.**{*;}
+-keep class com.huawei.hms.**{*;}
+
+#====================================华为推送 end=====================================
+
+# ==================================极光推送 start=====================================
+
+## 极光推送
+-dontoptimize
+-dontpreverify
+
+-dontwarn cn.jpush.**
+-keep class cn.jpush.** { *; }
+
+
+-dontwarn cn.jiguang.**
+-keep class cn.jiguang.** { *; }
+
+# ================================极光推送 end==========================

+ 1 - 1
android/app/src/main/AndroidManifest.xml

@@ -7,7 +7,7 @@
         android:name=".AtmobApplication"
         android:allowBackup="false"
         android:icon="@mipmap/ic_launcher"
-        android:label="追爱小键盘">
+        android:label="@string/app_name">
 
         <activity
             android:name=".MainActivity"

+ 3 - 0
android/app/src/main/res/values/strings.xml

@@ -0,0 +1,3 @@
+<resources>
+    <string name="app_name">追爱小键盘</string>
+</resources>

+ 16 - 1
android/build.gradle.kts

@@ -1,3 +1,17 @@
+buildscript {
+
+    repositories {
+        google()
+        mavenCentral()
+        maven { url = uri("https://developer.huawei.com/repo/") }
+    }
+    dependencies {
+        classpath("com.android.tools.build:gradle:8.7.0")
+        classpath("com.huawei.agconnect:agcp:1.9.1.301")
+        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.22")
+    }
+}
+
 allprojects {
     extra.apply {
         set("compileSdkVersion", 35)
@@ -11,7 +25,8 @@ allprojects {
         maven {
             url = uri("https://jitpack.io")
         }
-        google()
+        maven { url = uri("https://developer.huawei.com/repo/")}
+            google()
         mavenCentral()
     }
 }

+ 1 - 0
android/settings.gradle.kts

@@ -13,6 +13,7 @@ pluginManagement {
         google()
         mavenCentral()
         gradlePluginPortal()
+        maven { url = uri("https://developer.huawei.com/repo/") }
     }
 }
 

+ 19 - 0
lib/data/consts/build_config.dart

@@ -37,6 +37,25 @@ final class UmengConfig {
   }
 }
 
+final class JpushConfig {
+  JpushConfig._();
+
+  //极光推送配置
+  static const jpushAndroidAppKey = "e4c8b538fa1046eccce756de";
+  // 这个不确定是不是ios
+  static const jpushIosAppKey = " e4c8b538fa1046eccce756de";
+
+  static String get jpushAppKey {
+    if (Platform.isAndroid) {
+      return jpushAndroidAppKey;
+    } else if (Platform.isIOS) {
+      return jpushIosAppKey;
+    } else {
+      return '';
+    }
+  }
+}
+
 final class GravityConfig {
   GravityConfig._();
 

+ 24 - 15
lib/data/consts/constants.dart

@@ -1,3 +1,5 @@
+import 'dart:io';
+
 import 'package:flutter/rendering.dart';
 
 import '../../utils/mmkv_util.dart';
@@ -19,17 +21,12 @@ class Constants {
 
   static const String _prodBaseUrl = "https://project-api.atmob.com";
 
-
-
-
   static String baseUrl = getBaseUrl();
 
   static bool isProdEnv() {
     return Constants.env == Constants.envProd;
   }
 
-
-
   // TTARCLW,BDARCLWXM测试用特定渠道 Android
   static const String appDefaultChannel = "TTARCLW";
   static const int appDefaultAppId = 0;
@@ -46,8 +43,9 @@ class Constants {
 
   static const String keyIsLogin = 'keyIsLogin';
   static const String keyIsMember = 'keyIsMember';
+
   //系统键盘选中的键盘
-  static const String keyboardSelect ="keyboard_select";
+  static const String keyboardSelect = "keyboard_select";
 
   // 首次进入应用
   static const String isFirstIntro = 'isFirstIntro';
@@ -56,12 +54,11 @@ class Constants {
   static const String isFirstShowKeyboardGuide = 'isFirstShowKeyboardGuide';
 
   // 是否首先显示键盘教程
-  static const String isFirstShowKeyboardTutorial = 'isFirstShowKeyboardTutorial';
+  static const String isFirstShowKeyboardTutorial =
+      'isFirstShowKeyboardTutorial';
 
   // 是否首次进入活动页
   static const String isFirstIntoDiscount = 'isFirstIntoDiscount';
-
-
 }
 
 String getBaseUrl() {
@@ -85,8 +82,6 @@ void setFirstIntro(bool isFirst) {
   KVUtil.putBool(Constants.isFirstIntro, isFirst);
 }
 
-
-
 bool isFirstIntoDiscount() {
   return KVUtil.getBool(Constants.isFirstIntoDiscount, true);
 }
@@ -95,10 +90,24 @@ void setFirstIntoDiscount(bool isFirst) {
   KVUtil.putBool(Constants.isFirstIntoDiscount, isFirst);
 }
 
-
 bool isNotHWChannel() {
-  String? channel= KVUtil.getString(Constants.appChanelName, Constants.appDefaultChannel);
-      return  channel!= "SDZAXJPHW";
+  String? channel = KVUtil.getString(
+    Constants.appChanelName,
+    Constants.appDefaultChannel,
+  );
+  return channel != "SDZAXJPHW";
 }
 
-
+String getChannelName() {
+  if (Platform.isAndroid) {
+    String? channel = KVUtil.getString(
+      Constants.appChanelName,
+      Constants.appDefaultChannel,
+    );
+    return channel!;
+  }else if (Platform.isIOS) {
+    return "Appstore";
+  } else {
+    return Constants.appDefaultChannel;
+  }
+}

+ 11 - 0
lib/data/repository/account_repository.dart

@@ -13,6 +13,7 @@ import '../../base/app_base_request.dart';
 import '../../di/get_it.dart';
 import '../../plugins/keyboard_android_platform.dart';
 import '../../sdk/gravity/gravity_helper.dart';
+import '../../sdk/jpush/jpush_helper.dart';
 import '../../utils/async_util.dart';
 import '../../utils/atmob_log.dart';
 import '../../utils/daily_limiter_util.dart';
@@ -175,6 +176,12 @@ class AccountRepository {
               response.memberInfo!.isMember,
             );
           }
+          if (isLogin.value) {
+            JpushHelper.getInstance().init();
+            isVipUser
+                ? JpushHelper.getInstance().setTags(tag: ["vipUser",getChannelName()])
+                : JpushHelper.getInstance().setTags(tag: ["noVipUser",getChannelName()]);
+          }
           return response;
         });
   }
@@ -223,6 +230,7 @@ class AccountRepository {
     keyboardRepository.refreshData();
     // 微信登录,通知键盘刷新数据
     _notifyKeyboardPluginRefreshData();
+
   }
 
   void logout() {
@@ -238,8 +246,11 @@ class AccountRepository {
     GravityHelper.onLogout();
     KVUtil.putString(Constants.keyboardSelect, null);
     DailyLimiterUtil.clearDailyLimitData("SurpriseDialog");
+    // 退出登录,清除极光推送的标签
+    JpushHelper.getInstance().cleanTags();
     // 退出登录,通知键盘刷新数据
     _notifyKeyboardPluginRefreshData();
+
   }
 
   /// 通知键盘刷新数据

+ 5 - 3
lib/di/get_it.config.dart

@@ -106,6 +106,7 @@ import '../module/zodiac_love_intimacy/tody/zodiac_love_today_controller.dart'
 import '../module/zodiac_love_intimacy/zodiac_love_intimacy_controller.dart'
     as _i1060;
 import '../plugins/keyboard_method_handler.dart' as _i415;
+import '../sdk/jpush/jpush_helper.dart' as _i482;
 import '../utils/intimacy_analyze_config_helper.dart' as _i738;
 import '../utils/payment_status_manager.dart' as _i779;
 import '../utils/upload/upload_file_manager.dart' as _i428;
@@ -164,14 +165,15 @@ extension GetItInjectableX on _i174.GetIt {
     gh.factory<_i101.KeyboardTutorialVideoController>(
       () => _i101.KeyboardTutorialVideoController(),
     );
+    gh.factory<_i232.DeleteProfileConfirmController>(
+      () => _i232.DeleteProfileConfirmController(),
+    );
     gh.factory<_i973.SplashController>(() => _i973.SplashController());
     gh.factory<_i333.DiscountController>(() => _i333.DiscountController());
     gh.factory<_i415.KeyboardMethodHandler>(
       () => _i415.KeyboardMethodHandler(),
     );
-    gh.factory<_i232.DeleteProfileConfirmController>(
-      () => _i232.DeleteProfileConfirmController(),
-    );
+    gh.singleton<_i482.JpushHelper>(() => _i482.JpushHelper());
     gh.lazySingleton<_i495.WechatLoginService>(
       () => _i495.WechatLoginService(),
     );

+ 10 - 0
lib/main.dart

@@ -14,6 +14,7 @@ import 'package:keyboard/resource/string_source.dart';
 import 'package:keyboard/router/app_pages.dart';
 import 'package:keyboard/sdk/bugly/bugly_helper.dart';
 import 'package:keyboard/sdk/gravity/gravity_helper.dart';
+import 'package:keyboard/sdk/jpush/jpush_helper.dart';
 import 'package:keyboard/utils/app_info_util.dart';
 import 'package:keyboard/utils/atmob_log.dart';
 import 'package:keyboard/utils/channel_util.dart';
@@ -86,6 +87,15 @@ class AppInitTask implements EnsurePolicyGrant {
     GravityHelper.init();
     //友盟
     UmengHelper.initCommon();
+
+    JpushHelper.getInstance().isNotificationEnabled().then((hasPermission){
+      AtmobLog.d("JpushHelper", ("flutter isNotificationEnabled: $hasPermission"));
+      if(hasPermission){
+        return;
+      }else{
+        JpushHelper.getInstance().requestRequiredPermission();
+      }
+    });
   }
 }
 

+ 1 - 1
lib/module/zodiac_love_intimacy/zodiac_love_intimacy_page.dart

@@ -147,7 +147,7 @@ class ZodiacLoveIntimacyPage extends BasePage<ZodiacLoveIntimacyController> {
             Positioned(
               left: 0,
               right: 0,
-              top: 6.h,
+              top: 8.h,
               child: Container(
                 height: 41.h,
                 // 顶部2边圆角

+ 136 - 0
lib/sdk/jpush/jpush_helper.dart

@@ -0,0 +1,136 @@
+import 'dart:io';
+import 'package:get/get.dart';
+import 'package:flutter/services.dart';
+import 'package:injectable/injectable.dart';
+import 'package:jpush_flutter/jpush_flutter.dart';
+import 'package:jpush_flutter/jpush_interface.dart';
+import 'package:keyboard/module/store/new_discount/new_discount_page.dart';
+import 'package:keyboard/utils/atmob_log.dart';
+
+import '../../data/consts/build_config.dart';
+import '../../data/consts/constants.dart';
+import '../../di/get_it.dart';
+import '../../module/main/main_controller.dart';
+import '../../router/app_pages.dart';
+
+@singleton
+class JpushHelper {
+  static const String tag = "qqq JpushHelper";
+  static String registrationId = "";
+
+  static final JPushFlutterInterface _jpush = JPush.newJPush();
+
+  JpushHelper();
+
+  // Platform messages are asynchronous, so we initialize in an async method.
+  Future<void> init() async {
+    String? platformVersion;
+    AtmobLog.d(tag, "flutter init JPushHelper");
+    print("qqq flutter init JPushHelper");
+    try {
+      _jpush.addEventHandler(
+        onReceiveNotification: (Map<String, dynamic> message) async {
+          AtmobLog.d(tag, "flutter onReceiveNotification: $message");
+          if (Get.isRegistered<MainController>() &&
+              Get.currentRoute != RoutePath.newDiscount) {
+            NewDiscountPage.start();
+          }
+          //清除应用图标角标数量
+          _jpush.setBadge(-1);
+        },
+        onOpenNotification: (Map<String, dynamic> message) async {
+          AtmobLog.d(tag, "flutter onOpenNotification: $message");
+        },
+        onReceiveMessage: (Map<String, dynamic> message) async {
+          AtmobLog.d(tag, "flutter onReceiveMessage: $message");
+        },
+        onReceiveNotificationAuthorization: (
+          Map<String, dynamic> message,
+        ) async {
+          AtmobLog.d(
+            tag,
+            "flutter onReceiveNotificationAuthorization: $message",
+          );
+        },
+        onNotifyMessageUnShow: (Map<String, dynamic> message) async {
+          AtmobLog.d(tag, "flutter onNotifyMessageUnShow: $message");
+        },
+        onInAppMessageShow: (Map<String, dynamic> message) async {
+          AtmobLog.d(tag, "flutter onInAppMessageShow: $message");
+        },
+        onCommandResult: (Map<String, dynamic> message) async {
+          AtmobLog.d(tag, "flutter onCommandResult: $message");
+        },
+        onInAppMessageClick: (Map<String, dynamic> message) async {
+          AtmobLog.d(tag, "flutter onInAppMessageClick: $message");
+        },
+        onConnected: (Map<String, dynamic> message) async {
+          AtmobLog.d(tag, "flutter onConnected: $message");
+        },
+      );
+    } on PlatformException {
+      platformVersion = 'Failed to get platform version.';
+    }
+    _jpush.enableAutoWakeup(enable: true);
+    _jpush.setAuth(enable: true);
+    _jpush.setup(
+      appKey: JpushConfig.jpushAppKey,
+      channel: getChannelName(),
+      production: false,
+      debug: BuildConfig.isDebug,
+    );
+    _jpush.applyPushAuthority(
+      new NotificationSettingsIOS(sound: true, alert: true, badge: true),
+    );
+
+    // Platform messages may fail, so we use a try/catch PlatformException.
+    _jpush.getRegistrationID().then((rid) {
+      AtmobLog.d(tag, "极光id get registration id : $rid");
+      print("qqq 极光id get registration id : $rid");
+
+      registrationId = rid;
+    });
+
+    if (Platform.isIOS) {
+      // iOS要是使用应用内消息,请在页面进入离开的时候配置pageEnterTo 和  pageLeave 函数,参数为页面名。
+      // _jpush.pageEnterTo("HomePage");
+    }
+    isNotificationEnabled().then((hasPermission) {
+      AtmobLog.d(
+        "JpushHelper",
+        ("flutter isNotificationEnabled: $hasPermission"),
+      );
+      if (hasPermission) {
+        return;
+      } else {
+        requestRequiredPermission();
+      }
+    });
+  }
+
+  Future<void> setTags({required List<String> tag}) async {
+    _jpush.setTags(tag).then((result) {
+      AtmobLog.d("JpushHelper", ("flutter setTags: $result"));
+    });
+  }
+
+  Future<void> cleanTags() async {
+    _jpush.cleanTags().then((result) {
+      AtmobLog.d("JpushHelper", ("flutter cleanTags: $result"));
+    });
+  }
+
+  Future<bool> isNotificationEnabled() async {
+    return _jpush.isNotificationEnabled();
+  }
+
+  void requestRequiredPermission() {
+    _jpush.requestRequiredPermission();
+  }
+
+  void openSettingsForNotification() {
+    _jpush.openSettingsForNotification();
+  }
+
+  static JpushHelper getInstance() => getIt.get<JpushHelper>();
+}

+ 8 - 0
pubspec.lock

@@ -868,6 +868,14 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "1.0.5"
+  jpush_flutter:
+    dependency: "direct main"
+    description:
+      name: jpush_flutter
+      sha256: "309ffd60169cb7ea78810026eac30a3a6b98a41f66cdef31cb63d6930486b48e"
+      url: "https://pub.dev"
+    source: hosted
+    version: "3.2.7"
   js:
     dependency: transitive
     description:

+ 1 - 1
pubspec.yaml

@@ -104,7 +104,7 @@ dependencies:
   # 基于video_player的封装库,能自定义UI
   chewie: ^1.11.3
 
-
+  jpush_flutter: ^3.2.7
 
   #QR
   qr_flutter: ^4.1.0