浏览代码

[new]增加极光推送

zk 4 月之前
父节点
当前提交
9ebad4434a

+ 96 - 0
android/app/agconnect-services.json

@@ -0,0 +1,96 @@
+{
+  "agcgw": {
+    "url": "connect-drcn.dbankcloud.cn",
+    "backurl": "connect-drcn.hispace.hicloud.com",
+    "websocketurl": "connect-ws-drcn.hispace.dbankcloud.cn",
+    "websocketbackurl": "connect-ws-drcn.hispace.dbankcloud.com"
+  },
+  "agcgw_all": {
+    "SG": "connect-dra.dbankcloud.cn",
+    "SG_back": "connect-dra.hispace.hicloud.com",
+    "CN": "connect-drcn.dbankcloud.cn",
+    "CN_back": "connect-drcn.hispace.hicloud.com",
+    "RU": "connect-drru.hispace.dbankcloud.ru",
+    "RU_back": "connect-drru.hispace.dbankcloud.cn",
+    "DE": "connect-dre.dbankcloud.cn",
+    "DE_back": "connect-dre.hispace.hicloud.com"
+  },
+  "websocketgw_all": {
+    "SG": "connect-ws-dra.hispace.dbankcloud.cn",
+    "SG_back": "connect-ws-dra.hispace.dbankcloud.com",
+    "CN": "connect-ws-drcn.hispace.dbankcloud.cn",
+    "CN_back": "connect-ws-drcn.hispace.dbankcloud.com",
+    "RU": "connect-ws-drru.hispace.dbankcloud.ru",
+    "RU_back": "connect-ws-drru.hispace.dbankcloud.cn",
+    "DE": "connect-ws-dre.hispace.dbankcloud.cn",
+    "DE_back": "connect-ws-dre.hispace.dbankcloud.com"
+  },
+  "client": {
+    "cp_id": "30086000804905000",
+    "product_id": "461323198430156172",
+    "client_id": "1740613125964603648",
+    "client_secret": "5B901EF4B7829BC462068883F427B5B2137592CE1F93DBDCEB6677CDDC99A10C",
+    "project_id": "461323198430156172",
+    "app_id": "114478951",
+    "api_key": "DgEDAH/wd6ztRJoUuA8H2pf4aWtmdLu5m0eBgfZX1KrEV0vgLcabjDq7FYQWChMb0KLKXvL7YrOUc2P7JohkHPNuXMqcrqNbjd+bFg==",
+    "package_name": "com.xjsucha.manbu"
+  },
+  "oauth_client": {
+    "client_id": "114478951",
+    "client_type": 1
+  },
+  "app_info": {
+    "app_id": "114478951",
+    "package_name": "com.xjsucha.manbu"
+  },
+  "service": {
+    "analytics": {
+      "collector_url": "datacollector-drcn.dt.hicloud.com,datacollector-drcn.dt.dbankcloud.cn",
+      "collector_url_cn": "datacollector-drcn.dt.hicloud.com,datacollector-drcn.dt.dbankcloud.cn",
+      "collector_url_de": "datacollector-dre.dt.hicloud.com,datacollector-dre.dt.dbankcloud.cn",
+      "collector_url_ru": "datacollector-drru.dt.dbankcloud.ru,datacollector-drru.dt.hicloud.com",
+      "collector_url_sg": "datacollector-dra.dt.hicloud.com,datacollector-dra.dt.dbankcloud.cn",
+      "resource_id": "p1",
+      "channel_id": ""
+    },
+    "ml": {
+      "mlservice_url": "ml-api-drcn.ai.dbankcloud.com,ml-api-drcn.ai.dbankcloud.cn"
+    },
+    "cloudstorage": {
+      "storage_url": "https://agc-storage-drcn.platform.dbankcloud.cn",
+      "storage_url_ru": "https://agc-storage-drru.cloud.huawei.ru",
+      "storage_url_sg": "https://ops-dra.agcstorage.link",
+      "storage_url_de": "https://ops-dre.agcstorage.link",
+      "storage_url_cn": "https://agc-storage-drcn.platform.dbankcloud.cn",
+      "storage_url_ru_back": "https://agc-storage-drru.cloud.huawei.ru",
+      "storage_url_sg_back": "https://agc-storage-dra.cloud.huawei.asia",
+      "storage_url_de_back": "https://agc-storage-dre.cloud.huawei.eu",
+      "storage_url_cn_back": "https://agc-storage-drcn.cloud.huawei.com.cn"
+    },
+    "search": {
+      "url": "https://search-drcn.cloud.huawei.com"
+    },
+    "edukit": {
+      "edu_url": "edukit.cloud.huawei.com.cn",
+      "dh_url": "edukit.cloud.huawei.com.cn"
+    }
+  },
+  "region": "CN",
+  "configuration_version": "3.0",
+  "appInfos": [
+    {
+      "package_name": "com.xjsucha.manbu",
+      "client": {
+        "app_id": "114478951"
+      },
+      "app_info": {
+        "package_name": "com.xjsucha.manbu",
+        "app_id": "114478951"
+      },
+      "oauth_client": {
+        "client_type": 1,
+        "client_id": "114478951"
+      }
+    }
+  ]
+}

+ 37 - 0
android/app/build.gradle

@@ -3,6 +3,7 @@ plugins {
     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 {
@@ -42,6 +43,14 @@ android {
                 JPUSH_PKGNAME: rootProject.ext.applicationId,
                 JPUSH_APPKEY : "cd602bd396037438bb9ead5a", // NOTE: JPush 上注册的包名对应的 Appkey.
                 JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.
+                HONOR_APPID   : "104506963",//荣耀
+                XIAOMI_APPKEY : "5972042933453",// 小米平台注册的appkey,xiaomi-v5.5.3版本开始,不需要添加前缀 “MI-”
+                XIAOMI_APPID  : "2882303761520429453", // 小米平台注册的appid,xiaomi-v5.5.3版本开始,不需要添加前缀 “MI-”
+                VIVO_APPKEY   : "5c8095077aa3b1a4ac9843be810f87b9", // VIVO平台注册的appkey
+                VIVO_APPID    : "105921618", // VIVO平台注册的appid
+                OPPO_APPKEY   : "OP-c6415c75cb8e4b078bafcd8500bcb017", // OPPO平台注册的appkey
+                OPPO_APPID    : "OP-33499095", // OPPO平台注册的appid
+                OPPO_APPSECRET: "OP-f3eab24d5d5047e6a18d7151b52f5334"//OPPO平台注册的appsecret
         ]
     }
 
@@ -80,8 +89,36 @@ android {
             outputFileName = fileName
         }
     }
+
+    repositories {
+        flatDir {
+            dirs 'libs'
+        }
+    }
 }
 
 flutter {
     source = "../.."
 }
+
+
+dependencies {
+    //引入 libs 中的 aar,如果项目中有此依赖不需要重复引用
+    implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
+    // 接入荣耀厂商
+    implementation 'cn.jiguang.sdk.plugin:honor:5.8.0'
+    //小米
+    implementation 'cn.jiguang.sdk.plugin:xiaomi:5.8.0'
+    // 接入华为厂商
+    implementation 'com.huawei.hms:push:6.13.0.300'
+    implementation 'cn.jiguang.sdk.plugin:huawei:5.8.0'
+    // 接入 OPPO 厂商
+    implementation 'cn.jiguang.sdk.plugin:oppo:5.8.0'
+    //以下为 OPPO 3.1.0 aar需要依赖
+    implementation 'com.google.code.gson:gson:2.10.1'
+    implementation 'commons-codec:commons-codec:1.6'
+    implementation 'androidx.annotation:annotation:1.1.0'
+    //vivo
+    implementation 'cn.jiguang.sdk.plugin:vivo:5.8.0'
+
+}

二进制
android/app/libs/HiPushSDK-8.0.12.307.aar


二进制
android/app/libs/com.heytap.msp_3.5.3.aar


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

@@ -226,4 +226,43 @@ public <methods>;
 -keep class com.netease.nis.basesdk.**{
     public *;
     protected *;
-}
+}
+
+
+#######Push######
+# 小米
+-dontwarn com.xiaomi.push.**
+-keep class com.xiaomi.push.** { *; }
+
+# Honor
+-ignorewarnings
+-keepattributes *Annotation*
+-keepattributes Exceptions
+-keepattributes InnerClasses
+-keepattributes Signature
+-keepattributes SourceFile,LineNumberTable
+-keep class com.hihonor.push.**{*;}
+
+#华为
+-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.**{*;}
+
+#vivo
+-dontwarn com.vivo.push.**
+-keep class com.vivo.push.**{*; }
+-keep class com.vivo.vms.**{*; }
+
+#oppo
+-dontwarn com.coloros.mcsdk.**
+-keep class com.coloros.mcsdk.** { *; }
+-dontwarn com.heytap.**
+-keep class com.heytap.** { *; }
+-dontwarn com.mcs.**
+-keep class com.mcs.** { *; }

+ 16 - 0
android/build.gradle

@@ -1,3 +1,17 @@
+buildscript {
+    repositories {
+        google()
+        mavenCentral()
+        // 华为厂商通道依赖
+        maven { url 'https://developer.huawei.com/repo/' }
+    }
+    dependencies {
+        classpath 'com.android.tools.build:gradle:8.4.0'
+        // hms,若不集成华为厂商通道,可直接跳过
+        classpath 'com.huawei.agconnect:agcp:1.9.1.301'
+    }
+}
+
 allprojects {
     ext {
         compileSdkVersion = 35
@@ -13,6 +27,8 @@ allprojects {
         maven { url 'https://maven.aliyun.com/repository/public' }
         maven { url 'https://maven.aliyun.com/repository/central' }
         maven { url 'https://repo.huaweicloud.com/repository/maven/' }
+        //hms,若不集成华为厂商通道,可直接跳过
+        maven { url 'https://developer.huawei.com/repo/' }
         mavenCentral()
 
         maven {

+ 50 - 1
lib/sdk/jpush/jpush_helper.dart

@@ -1,13 +1,26 @@
+import 'package:flutter/services.dart';
 import 'package:jpush_flutter/jpush_flutter.dart';
 import 'package:jpush_flutter/jpush_interface.dart';
+import 'package:location/data/consts/build_config.dart';
+import 'package:location/utils/atmob_log.dart';
 
 class JpushHelper {
+  static const String tag = 'JpushHelper';
+
   JpushHelper._();
 
   static JPushFlutterInterface? jpush;
 
-  static void init() {
+  static void init() async {
     jpush = JPush.newJPush();
+    _setJPushEventHandler();
+    jpush!.setAuth(enable: true);
+    jpush!.setup(
+      appKey: "cd602bd396037438bb9ead5a",
+      debug: BuildConfig.isDebug,
+    );
+    final id = await JpushHelper.getRegistrationId();
+    AtmobLog.d(tag, 'RegistrationId:$id');
   }
 
   static Future<String> getRegistrationId() {
@@ -16,4 +29,40 @@ class JpushHelper {
     }
     return jpush!.getRegistrationID();
   }
+
+  static void _setJPushEventHandler() {
+    try {
+      if (jpush == null) {
+        throw Exception('JPush not initialized');
+      }
+      jpush!.addEventHandler(
+          onReceiveNotification: (Map<String, dynamic> message) async {
+        print("flutter onReceiveNotification: $message");
+      }, onOpenNotification: (Map<String, dynamic> message) async {
+        print("flutter onOpenNotification: $message");
+      }, onReceiveMessage: (Map<String, dynamic> message) async {
+        print("flutter onReceiveMessage: $message");
+      }, onReceiveNotificationAuthorization:
+              (Map<String, dynamic> message) async {
+        print("flutter onReceiveNotificationAuthorization: $message");
+      }, onNotifyMessageUnShow: (Map<String, dynamic> message) async {
+        print("flutter onNotifyMessageUnShow: $message");
+      }, onInAppMessageShow: (Map<String, dynamic> message) async {
+        print("flutter onInAppMessageShow: $message");
+      }, onCommandResult: (Map<String, dynamic> message) async {
+        print("flutter onCommandResult: $message");
+      }, onInAppMessageClick: (Map<String, dynamic> message) async {
+        print("flutter onInAppMessageClick: $message");
+      }, onConnected: (Map<String, dynamic> message) async {
+        print("flutter onConnected: $message");
+      }, onReceiveDeviceToken: (Map<String, dynamic> message) async {
+        print("flutter onReceiveDeviceToken: $message");
+      });
+    } on PlatformException {
+      AtmobLog.e(tag,
+          'JPush event handler error: JPush not initialized or platform error');
+    } catch (e) {
+      AtmobLog.e(tag, 'JPush event handler error: $e');
+    }
+  }
 }