Browse Source

添加老师端极光推送

Pq 2 years ago
parent
commit
817ba7cb41

+ 92 - 0
teacher/agconnect-services.json

@@ -0,0 +1,92 @@
+{
+	"agcgw":{
+		"backurl":"connect-drcn.hispace.hicloud.com",
+		"url":"connect-drcn.dbankcloud.cn",
+		"websocketbackurl":"connect-ws-drcn.hispace.dbankcloud.com",
+		"websocketurl":"connect-ws-drcn.hispace.dbankcloud.cn"
+	},
+	"agcgw_all":{
+		"CN":"connect-drcn.dbankcloud.cn",
+		"CN_back":"connect-drcn.hispace.hicloud.com",
+		"DE":"connect-dre.dbankcloud.cn",
+		"DE_back":"connect-dre.hispace.hicloud.com",
+		"RU":"connect-drru.hispace.dbankcloud.ru",
+		"RU_back":"connect-drru.hispace.dbankcloud.cn",
+		"SG":"connect-dra.dbankcloud.cn",
+		"SG_back":"connect-dra.hispace.hicloud.com"
+	},
+	"websocketgw_all":{
+		"CN":"connect-ws-drcn.hispace.dbankcloud.cn",
+		"CN_back":"connect-ws-drcn.hispace.dbankcloud.com",
+		"DE":"connect-ws-dre.hispace.dbankcloud.cn",
+		"DE_back":"connect-ws-dre.hispace.dbankcloud.com",
+		"RU":"connect-ws-drru.hispace.dbankcloud.ru",
+		"RU_back":"connect-ws-drru.hispace.dbankcloud.cn",
+		"SG":"connect-ws-dra.hispace.dbankcloud.cn",
+		"SG_back":"connect-ws-dra.hispace.dbankcloud.com"
+	},
+	"client":{
+		"cp_id":"890086000300075951",
+		"product_id":"99536292102459120",
+		"client_id":"930923350119697856",
+		"client_secret":"357D4BC4E1EDDAC67291848C5F442034C679BFEC080C8668B0E57F09F14C226C",
+		"project_id":"99536292102459120",
+		"app_id":"106640105",
+		"api_key":"DAEDAF87SRo4sNbJG4FSvPeJ3AdQX8zIt3HFGxOy8/y1hMPaQ5dgIgGv1otMOSbfFHrB8k4S9Pu/v44ytx2gfPojd17p+nUvPlqMyQ==",
+		"package_name":"com.cooleshow.teacher"
+	},
+	"oauth_client":{
+		"client_id":"106640105",
+		"client_type":1
+	},
+	"app_info":{
+		"app_id":"106640105",
+		"package_name":"com.cooleshow.teacher"
+	},
+	"service":{
+		"analytics":{
+			"collector_url":"datacollector-drcn.dt.hicloud.com,datacollector-drcn.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",
+			"collector_url_de":"datacollector-dre.dt.hicloud.com,datacollector-dre.dt.dbankcloud.cn",
+			"collector_url_cn":"datacollector-drcn.dt.hicloud.com,datacollector-drcn.dt.dbankcloud.cn",
+			"resource_id":"p1",
+			"channel_id":""
+		},
+		"search":{
+			"url":"https://search-drcn.cloud.huawei.com"
+		},
+		"cloudstorage":{
+			"storage_url_sg_back":"https://agc-storage-dra.cloud.huawei.asia",
+			"storage_url_ru_back":"https://agc-storage-drru.cloud.huawei.ru",
+			"storage_url_ru":"https://agc-storage-drru.cloud.huawei.ru",
+			"storage_url_de_back":"https://agc-storage-dre.cloud.huawei.eu",
+			"storage_url_de":"https://ops-dre.agcstorage.link",
+			"storage_url":"https://agc-storage-drcn.platform.dbankcloud.cn",
+			"storage_url_sg":"https://ops-dra.agcstorage.link",
+			"storage_url_cn_back":"https://agc-storage-drcn.cloud.huawei.com.cn",
+			"storage_url_cn":"https://agc-storage-drcn.platform.dbankcloud.cn"
+		},
+		"ml":{
+			"mlservice_url":"ml-api-drcn.ai.dbankcloud.com,ml-api-drcn.ai.dbankcloud.cn"
+		}
+	},
+	"region":"CN",
+	"configuration_version":"3.0",
+	"appInfos":[
+		{
+			"package_name":"com.cooleshow.teacher",
+			"client":{
+				"app_id":"106640105"
+			},
+			"app_info":{
+				"package_name":"com.cooleshow.teacher",
+				"app_id":"106640105"
+			},
+			"oauth_client":{
+				"client_type":1,
+				"client_id":"106640105"
+			}
+		}
+	]
+}

+ 31 - 1
teacher/build.gradle

@@ -4,6 +4,8 @@ plugins {
 }
 apply plugin: 'kotlin-android-extensions'
 apply plugin: 'kotlin-kapt'
+apply plugin: 'com.huawei.agconnect'
+
 kapt {
     arguments {
         arg("AROUTER_MODULE_NAME", project.getName())
@@ -25,7 +27,17 @@ android {
         }
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
         manifestPlaceholders = [
-                qqappid: "1110018403"
+                qqappid: "1110018403",
+                JPUSH_PKGNAME: applicationId,
+                JPUSH_APPKEY : "ea33d0a0a84d3b7b6dd70381", //JPush 上注册的包名对应的 Appkey.
+                JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.
+                XIAOMI_APPID : "MI-2882303761520170311",
+                XIAOMI_APPKEY : "MI-5592017040311",
+                OPPO_APPKEY : "OP-e2e0eff48d6145c0b9f87cd6a57636ad",
+                OPPO_APPID : "OP-30841115",
+                OPPO_APPSECRET : "OP-519726bf2dfc4a6c95a6e00d61e47f10",
+                VIVO_APPKEY : "3154931db9dbf361b67dbd4bce2c8d30",
+                VIVO_APPID : "105573870",
         ]
     }
 
@@ -108,4 +120,22 @@ dependencies {
     }
 
 //    api(name: 'openDefault-10.10.0', ext: 'aar')
+//    极光推送start
+    implementation 'cn.jiguang.sdk:jpush:4.7.2'  // 此处以JPush 4.7.0 版本为例。
+    implementation 'cn.jiguang.sdk:jcore:3.2.4'  // 此处以JCore 3.2.4 版本为例。
+    //若不集成厂商通道,可直接跳过以下依赖
+    // 接入华为厂商
+    implementation 'com.huawei.hms:push:6.3.0.304'
+    // 极光厂商插件版本与接入 JPush 版本保持一致,下同
+    implementation 'cn.jiguang.sdk.plugin:huawei:4.7.2'
+    // 接入 VIVO 厂商
+    implementation 'cn.jiguang.sdk.plugin:vivo:4.7.2'
+    // 接入小米厂商
+    implementation 'cn.jiguang.sdk.plugin:xiaomi:4.7.2'
+    // 接入 OPPO 厂商
+    implementation 'cn.jiguang.sdk.plugin:oppo:4.7.2'
+    // JPush Android SDK v4.6.0 开始,需要单独引入 oppo 厂商 aar ,请下载官网 SDK 包并把 jpush-android-xxx-release/third-push/oppo/libs 下的 com.heytap.msp-push-x.x.x.aar 文件单独拷贝一份到应用 module/libs 下
+    implementation(name: 'com.heytap.msp-push-3.0.0', ext: 'aar')
+    implementation 'commons-codec:commons-codec:1.6'
+//    极光推送end
 }

BIN
teacher/libs/com.heytap.msp-push-3.0.0.aar


+ 14 - 1
teacher/proguard-rules.pro

@@ -35,4 +35,17 @@
 -dontnote com.google.android.gms.gcm.**
 -dontnote io.rong.**
 
--ignorewarnings
+-ignorewarnings
+
+-dontwarn com.xiaomi.push.**
+-keep class com.xiaomi.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.**{*;}

+ 47 - 0
teacher/src/main/AndroidManifest.xml

@@ -3,6 +3,15 @@
     xmlns:tools="http://schemas.android.com/tools"
     package="com.cooleshow.teacher">
 
+
+    <permission
+        android:name="${applicationId}.permission.JPUSH_MESSAGE"
+        android:protectionLevel="signature" />
+    <uses-permission android:name="${applicationId}.permission.JPUSH_MESSAGE" />
+    <permission
+        android:name="${applicationId}.permission.MIPUSH_RECEIVE"
+        android:protectionLevel="signature" />
+
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
@@ -314,6 +323,44 @@
         <meta-data
             android:name="qqappid"
             android:value="1110018403" />
+
+
+        <service
+            android:name=".push.PushService"
+            android:enabled="true"
+            android:exported="false"
+            android:process=":pushcore">
+            <intent-filter>
+                <action android:name="cn.jiguang.user.service.action" />
+            </intent-filter>
+        </service> <!-- User defined.  For test only  用户自定义的广播接收器 -->
+        <receiver
+            android:name=".push.MyJPushMessageReceiver"
+            android:enabled="true"
+            android:exported="false">
+            <intent-filter>
+                <action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
+
+                <category android:name="${applicationId}" />
+            </intent-filter>
+        </receiver> <!-- JPush结束 -->
+        <service
+            android:name=".push.MyHWPushService"
+            android:exported="false">
+            <intent-filter>
+                <action android:name="com.huawei.push.action.MESSAGING_EVENT" />
+            </intent-filter>
+        </service>
+        <!-- 融云开始 -->
+        <receiver
+            android:name=".push.SealNotificationReceiver"
+            android:exported="true">
+            <intent-filter>
+                <action android:name="io.rong.push.intent.MESSAGE_ARRIVED" />
+                <action android:name="io.rong.push.intent.MESSAGE_CLICKED" />
+                <action android:name="io.rong.push.intent.THIRD_PARTY_PUSH_STATE" />
+            </intent-filter>
+        </receiver>
     </application>
 
 </manifest>

+ 6 - 0
teacher/src/main/java/com/cooleshow/teacher/App.java

@@ -36,6 +36,7 @@ import com.vanniktech.emoji.ios.IosEmojiProvider;
 
 import androidx.annotation.RequiresApi;
 
+import cn.jpush.android.api.JPushInterface;
 import io.reactivex.rxjava3.annotations.NonNull;
 import io.reactivex.rxjava3.core.Observable;
 import io.reactivex.rxjava3.core.ObservableEmitter;
@@ -53,6 +54,7 @@ import io.rong.push.pushconfig.PushConfig;
  */
 public class App extends BaseApplication {
     public static boolean isRefresh = false;
+    private String mRegistrationId;
 
     @Override
     public void onCreate() {
@@ -85,6 +87,10 @@ public class App extends BaseApplication {
             webviewSetPath(this);
         }
         CrashReport.initCrashReport(getApplicationContext(), "c4d163184a", false);
+
+        //极光推送
+        JPushInterface.setDebugMode(true);
+        registrationId = JPushInterface.getRegistrationID(this);
         initRong();
         initUmeng();
     }

+ 13 - 0
teacher/src/main/java/com/cooleshow/teacher/push/HuaWeiHMSReceiver.java

@@ -0,0 +1,13 @@
+package com.cooleshow.teacher.push;
+
+/**
+ * Description:
+ * Copyright  : Copyright (c) 2019
+ * Company    : 大雅乐盟
+ * Author     : r
+ * Date       : 2019/10/29 16:51
+ * extends HMSReceiver
+ */
+public class HuaWeiHMSReceiver  {
+
+}

+ 36 - 0
teacher/src/main/java/com/cooleshow/teacher/push/MyHWPushService.java

@@ -0,0 +1,36 @@
+package com.cooleshow.teacher.push;
+
+import com.huawei.hms.push.HmsMessageService;
+import com.huawei.hms.push.RemoteMessage;
+
+import cn.jpush.android.service.PluginHuaweiPlatformsService;
+
+public class MyHWPushService extends HmsMessageService {
+
+      final PluginHuaweiPlatformsService jpushService = new PluginHuaweiPlatformsService();
+
+      @Override
+      public void onNewToken(String s) {
+          jpushService.onNewToken(s);
+      }
+
+      @Override
+      public void onMessageReceived(RemoteMessage remoteMessage) {
+          jpushService.onMessageReceived(remoteMessage);
+      }
+
+      @Override
+      public void onMessageSent(String s) {
+          jpushService.onMessageSent(s);
+      }
+
+      @Override
+      public void onSendError(String s, Exception e) {
+          jpushService.onSendError(s,e);
+      }
+
+      @Override
+      public void onDeletedMessages() {
+          jpushService.onDeletedMessages();
+      }
+  }

+ 79 - 0
teacher/src/main/java/com/cooleshow/teacher/push/MyJPushMessageReceiver.java

@@ -0,0 +1,79 @@
+package com.cooleshow.teacher.push;
+
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+
+import com.cooleshow.base.utils.LogUtils;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import cn.jpush.android.api.JPushMessage;
+import cn.jpush.android.api.NotificationMessage;
+import cn.jpush.android.service.JPushMessageReceiver;
+
+/**
+ * 自定义JPush message 接收器,包括操作tag/alias的结果返回(仅仅包含tag/alias新接口部分)
+ */
+public class MyJPushMessageReceiver extends JPushMessageReceiver {
+
+    private String memo;
+
+    /**
+     * 用户点击打开了通知
+     * @param context
+     * @param notificationMessage
+     */
+    @Override
+    public void onNotifyMessageOpened(Context context, NotificationMessage notificationMessage) {
+        startActivity(context, notificationMessage);
+    }
+
+    @Override
+    public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
+        super.onTagOperatorResult(context, jPushMessage);
+    }
+
+    @Override
+    public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage) {
+        super.onCheckTagOperatorResult(context, jPushMessage);
+    }
+
+    @Override
+    public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
+        super.onAliasOperatorResult(context, jPushMessage);
+    }
+
+    @Override
+    public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
+        super.onMobileNumberOperatorResult(context, jPushMessage);
+    }
+
+    public void startActivity(Context context, NotificationMessage notificationMessage) {
+        LogUtils.e(notificationMessage.notificationExtras);
+        JSONObject jsonObject;
+        try {
+            jsonObject = new JSONObject(notificationMessage.notificationExtras);
+//            memo = jsonObject.getString("memo");
+//            Log.i("JPushMessageReceiver","memo:"+memo);
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+
+
+//        MainActivity mainActivity = MainActivity.instance;
+//        if (ActivityManager.getInstance().isOpenActivity(MainActivity.class)&&mainActivity != null) {
+//            mainActivity.startActivity(memo);
+//            LOG.e("OpenActivity");
+//        } else {
+//            Intent i = new Intent(context, MainActivity.class);
+//            i.putExtra("memo", memo);
+//            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+//            context.startActivity(i);
+//            LOG.e("startActivity");
+//        }
+    }
+
+}

+ 7 - 0
teacher/src/main/java/com/cooleshow/teacher/push/PushService.java

@@ -0,0 +1,7 @@
+package com.cooleshow.teacher.push;
+
+import cn.jpush.android.service.JCommonService;
+
+public class PushService extends JCommonService {
+
+}

+ 42 - 0
teacher/src/main/java/com/cooleshow/teacher/push/SealNotificationReceiver.java

@@ -0,0 +1,42 @@
+
+package com.cooleshow.teacher.push;
+
+import android.content.Context;
+import android.os.Build;
+
+
+import io.rong.push.PushType;
+import io.rong.push.notification.PushMessageReceiver;
+import io.rong.push.notification.PushNotificationMessage;
+
+public class SealNotificationReceiver extends PushMessageReceiver {
+
+    @Override
+    public boolean onNotificationMessageArrived(Context context, PushType pushType, PushNotificationMessage pushNotificationMessage) {
+        return false;// 返回 false, 会弹出融云 SDK 默认通知; 返回 true, 融云 SDK 不会弹通知, 通知需要由您自定义。
+    }
+
+    @Override
+    public boolean onNotificationMessageClicked(Context context, PushType pushType, PushNotificationMessage notificationMessage) {
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+            return false;
+        }
+        try {
+//            if (ActivityManager.getInstance().isOpenActivity(MainActivity.class)) {
+//                MainActivity mainActivity = MainActivity.instance;
+//                if (mainActivity != null) {
+//                    mainActivity.startActivity("rongIM");
+//                }
+//            } else {
+//                Intent i = new Intent(context, HtmlActivity.class);
+//                i.putExtra("memo", "rongIM");
+//                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+//                context.startActivity(i);
+//            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return false;// 返回 false, 会走融云 SDK 默认处理逻辑, 即点击该通知会打开会话列表或会话界面; 返回 true, 则由您自定义处理逻辑。
+    }
+}

+ 8 - 0
teacher/src/main/java/com/cooleshow/teacher/push/XiaomiRongYunReceiver.java

@@ -0,0 +1,8 @@
+package com.cooleshow.teacher.push;
+
+import io.rong.push.platform.mi.MiMessageReceiver;
+
+public class XiaomiRongYunReceiver extends MiMessageReceiver {
+
+
+}

+ 15 - 0
teacher/src/main/java/com/cooleshow/teacher/ui/main/MainActivity.java

@@ -13,6 +13,7 @@ import android.widget.TextView;
 
 import com.alibaba.android.arouter.facade.annotation.Route;
 import com.common.im.ui.MessageFragment;
+import com.cooleshow.base.common.BaseApplication;
 import com.cooleshow.base.constanst.LoginStatusConstants;
 import com.cooleshow.base.event.LoginStatusEvent;
 import com.cooleshow.base.router.RouterPath;
@@ -47,6 +48,7 @@ import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.fragment.app.Fragment;
 
+import cn.jpush.android.api.JPushInterface;
 import io.rong.imkit.manager.UnReadMessageManager;
 import io.rong.imlib.RongIMClient;
 
@@ -64,6 +66,7 @@ public class MainActivity extends BaseMVPActivity<ActivityMainBinding, MainPrese
     private TextView tvMsgCount;
     private static final int EXIT_APP_DELAY = 1000;
     private long lastTime = 0;
+    private boolean isNeedSetPushId = true;
 
     /**
      * 打开首页并选中指定tab
@@ -261,12 +264,24 @@ public class MainActivity extends BaseMVPActivity<ActivityMainBinding, MainPrese
         //存储userInfo信息
         UserHelper.saveUserInfo(userInfo);
         connectIM();
+        bindPushId();
+    }
+
+    private void bindPushId() {
+        if (isNeedSetPushId && UserHelper.isLogin() && !TextUtils.isEmpty(UserHelper.getUserId())) {
+            String userId = UserHelper.getUserId();
+            LogUtils.i("pq", "registrationId:" + BaseApplication.registrationId);
+            JPushInterface.setAlias(getApplicationContext(), 1, userId);
+            isNeedSetPushId = false;
+        }
     }
 
     @Subscribe(threadMode = ThreadMode.MAIN)
     public void loadEventBus(LoginStatusEvent event) {
         if (event != null && event.eventCode == LoginStatusConstants.LOGIN_OUT) {
             IMManager.getInstance().logout();
+            JPushInterface.deleteAlias(getApplicationContext(), 1);
+            isNeedSetPushId = true;
             LogUtils.i("pq", "LoginStatusEvent:logout");
         }
     }