快速測試通知訊息

最新更新:2022-11-29

後台傳送通知訊息

傳送合集:電腦上下載 postMan 然後軟件左上方 import-link:https://www.getpostman.com/collections/618d2460851f697dc22c

推播讯息格式如下:

curl --location --request POST 'http://pricloud-master-api.glqas.mtpushoa.com/v3/push' \ --header 'Authorization: Basic MWM0Yjc0OWExN2Y2YWNhMzM5NjBhNTYwOjQ5ZjlkODI2MDExMmI0YmVlMDVhMzQzOA==' \ --header 'Content-Type: application/json' \ --data-raw '{"platform":"android","audience": {"registration_id": ["1104a89792bbb659ec5"] }, "notification": { "android": { "title": "通知 title", "alert": "通知內容", "builder_id": 0, "category": "alarm", "small_icon": "mtpush_notification_icon", "large_icon": "mtpush_notification_icon", "extras": {"通知 key": "通知 value"}, "priority": 1, "alert_type": 7, "sound": "coin", "channel_id": "money", "badge_add_num": 1, "badge_class": "com.engagelab.app.activity.MainActivity", "style": 2, "big_text": "黨的十八大提出,倡導富強、民主、文明、和諧,倡導自由、平等、公正、法治,倡導愛國、敬業、誠信、友善,積極培育和踐行社會主義核心價值觀。富強、民主、文明、和諧是國家層面的價值目標,自由、平等、公正、法治是社會層面的價值取向,愛國、敬業、誠信、友善是公民個人層面的價值準則,這 24 個字是社會主義核心價值觀的基本內容。", "inbox": { "inbox1": "this is inbox one", "inbox2": "this is inbox two", "inbox3": "this is inbox three" }, "big_pic_path": "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=96071541,1913562332&fm=26&gp=0.jpg", "intent": {"url": "intent:#Intent;component=com.engagelab.oaapp/com.engagelab.app.component.UserActivity400;end"} } }, "options": { "third_party_channel": { "vivo": { "classification": 1, "pushMode": 1 } } } }'
          curl --location --request POST 'http://pricloud-master-api.glqas.mtpushoa.com/v3/push' \
--header 'Authorization: Basic MWM0Yjc0OWExN2Y2YWNhMzM5NjBhNTYwOjQ5ZjlkODI2MDExMmI0YmVlMDVhMzQzOA==' \
--header 'Content-Type: application/json' \
--data-raw '{"platform":"android","audience": {"registration_id": ["1104a89792bbb659ec5"]
    },
    "notification": {
        "android": {
            "title": "通知 title",
            "alert": "通知內容",
            "builder_id": 0,
            "category": "alarm",
            "small_icon": "mtpush_notification_icon",
            "large_icon": "mtpush_notification_icon",
            "extras": {"通知 key": "通知 value"},
            "priority": 1,
            "alert_type": 7,
            "sound": "coin",
            "channel_id": "money",
            "badge_add_num": 1,
            "badge_class": "com.engagelab.app.activity.MainActivity",
            "style": 2,
            "big_text": "黨的十八大提出,倡導富強、民主、文明、和諧,倡導自由、平等、公正、法治,倡導愛國、敬業、誠信、友善,積極培育和踐行社會主義核心價值觀。富強、民主、文明、和諧是國家層面的價值目標,自由、平等、公正、法治是社會層面的價值取向,愛國、敬業、誠信、友善是公民個人層面的價值準則,這 24 個字是社會主義核心價值觀的基本內容。",
            "inbox": {
                "inbox1": "this is inbox one",
                "inbox2": "this is inbox two",
                "inbox3": "this is inbox three"
            },
            "big_pic_path": "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=96071541,1913562332&fm=26&gp=0.jpg",
            "intent": {"url": "intent:#Intent;component=com.engagelab.oaapp/com.engagelab.app.component.UserActivity400;end"}
        }
    },
    "options": {
        "third_party_channel": {
            "vivo": {
                "classification": 1,
                "pushMode": 1
            }
        }
    }
}'

        
此代碼塊在浮窗中顯示

參數說明

屬性 支持通道 類型 含義
title 所有 String 可選,標題
alert 所有 String 必選,內容
builder_id 僅 Engagelab int 可選,自訂樣式 id,默認使用系統樣式
category 僅 Engagelab String
  • 可選,通知類型,用於通知欄的排序或者過濾。
  • 種類繁多,類似 Notification.CATEGORY_ALARM、Notification#CATEGORY_CALL
  • large_icon 僅 Engagelab String 可選,大圖標,一般位於通知右邊
    extras 所有 JsonObject 可選,額外字段,key/value 格式均為 String
    priority 僅 Engagelab int 可選,通知的緊急程度,默認值為 0。
  • 低級,通知沒有 led 燈、震動和鈴聲,Notification.PRIORITY_LOW:-1
  • 普通,通知可以 led 燈、震動和鈴聲,Notification.PRIORITY_DEFAULT:0
  • 高級,通知可以 led 燈、震動和鈴聲,還可以懸浮窗彈出,Notification.PRIORITY_HIGH:1
  • alert_type 僅 Engagelab int 可選,通知用於鈴聲、震動、led 燈,三種場景可自由組合,Android 8.0 開始此屬性跟隨 channel。例如為 7 時,代表鈴聲、震動、led 燈都有,默認值為 Notification.DEFAULT_ALL:-1。
  • 鈴聲,Notification.DEFAULT_SOUND:1
  • 震動,Notification.DEFAULT_VIBRATE:2
  • led 燈,Notification.DEFAULT_LIGHTS:4
  • sound Engagelab/google/xiaomi String
  • 可選,通知附帶的鈴聲,需要提前在 res/raw 目錄存在鈴聲文件。
  • Android8.0 開始,鈴聲跟隨 channel,如果通知使用的 channel 沒有設置鈴聲,此通知不會對自訂鈴聲生效。
  • 建議提前將鈴聲設置在 channel 中,後續傳送通知時的 sound 和 channelId 中的鈴聲保持一致,即可通知鈴聲效果保持一致性。
  • channel_id Engagelab/google/huawei/xiaomi /oppo String 可選,從 Android8.0 開始需要,如果沒有提前設置 sdk 會幫忙設置(僅限 Engagelab 通道和應用程式在前台時的 google 通道)。
    badge_add_num Engagelab/huawei/xiaomi int 可選,應用程式角標增加數量,累加邏輯
    badge_class Engagelab/huawei/xiaomi String 可選,應用程式 MainActivity,用於角標展示
    style 僅 Engagelab int 可選,通知風格,默認值為 0
  • 大文本風格,NOTIFICATION_STYLE_BIG_TEXT:1
  • 收件箱風格,NOTIFICATION_STYLE_INBOX:2
  • 大圖片風格,NOTIFICATION_STYLE_BIG_PICTURE:3
  • big_text 僅 Engagelab String 可選,大文本,style 為 NOTIFICATION_STYLE_BIG_TEXT 生效
    inbox 僅 Engagelab JsonObject 可選,收件箱,style 為 NOTIFICATION_STYLE_INBOX 生效
    big_pic_path 僅 Engagelab String 可選,大圖片,style 為 NOTIFICATION_STYLE_BIG_PICTURE 生效
    Intent:url 所有 String 可選,MTPush4.0.0 開始生效,點擊通知(Engagelab+ 所有廠商)之後的跳轉,目前僅支持 activity,activity 跳轉使用 Intent.toURI()轉換得到

    在 Android 客戶端配置 activity 的示例代碼:

    package com.engagelab.app.component; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.widget.TextView; import android.widget.Toast; import com.engagelab.app.R; import com.engagelab.app.log.ExampleLogger; import com.engagelab.privates.push.api.MTPushPrivatesApi; import com.engagelab.privates.push.api.NotificationMessage; import com.engagelab.privates.push.constants.MTPushConstants; /** * 用於演示點擊通知後 activity 跳轉 * * 確保沒有調用 {@link MTPushPrivatesApi#configOldPushVersion(Context)},否則通知點擊跳轉不會跳轉到此頁面 * <p> * 不需要調用 {@link MTPushPrivatesApi#reportNotificationOpened(Context, String, byte, String)},sdk 內部已做處理 */ public class UserActivity400 extends Activity { private static final String TAG = "UserActivity400"; private TextView tvMessage; @Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState); setContentView(R.layout.activity_intent); tvMessage = findViewById(R.id.tv_message); onIntent(getIntent()); } @Override protected void onNewIntent(Intent intent) {super.onNewIntent(intent); onIntent(intent); } private void onIntent(Intent intent) { try {Toast.makeText(this, TAG, Toast.LENGTH_SHORT).show(); if (intent == null) {return;} Bundle bundle = intent.getExtras(); NotificationMessage notificationMessage = bundle.getParcelable("message"); if (notificationMessage == null) {return;} ExampleLogger.d(TAG, "notificationMessage:" + notificationMessage.toString()); tvMessage.setText(notificationMessage.toString()); } catch (Throwable throwable) {throwable.printStackTrace(); } } }
              package com.engagelab.app.component;
    
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.widget.TextView;
    import android.widget.Toast;
    
    import com.engagelab.app.R;
    import com.engagelab.app.log.ExampleLogger;
    import com.engagelab.privates.push.api.MTPushPrivatesApi;
    import com.engagelab.privates.push.api.NotificationMessage;
    import com.engagelab.privates.push.constants.MTPushConstants;
    
    /**
     * 用於演示點擊通知後 activity 跳轉
     *
     * 確保沒有調用 {@link MTPushPrivatesApi#configOldPushVersion(Context)},否則通知點擊跳轉不會跳轉到此頁面
     * <p>
     * 不需要調用 {@link MTPushPrivatesApi#reportNotificationOpened(Context, String, byte, String)},sdk 內部已做處理
     */
    public class UserActivity400 extends Activity {
    
        private static final String TAG = "UserActivity400";
    
        private TextView tvMessage;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_intent);
            tvMessage = findViewById(R.id.tv_message);
            onIntent(getIntent());
        }
    
        @Override
        protected void onNewIntent(Intent intent) {super.onNewIntent(intent);
            onIntent(intent);
        }
    
        private void onIntent(Intent intent) {
            try {Toast.makeText(this, TAG, Toast.LENGTH_SHORT).show();
                if (intent == null) {return;}
                Bundle bundle = intent.getExtras();
                NotificationMessage notificationMessage = bundle.getParcelable("message");
                if (notificationMessage == null) {return;}
                ExampleLogger.d(TAG, "notificationMessage:" + notificationMessage.toString());
                tvMessage.setText(notificationMessage.toString());
            } catch (Throwable throwable) {throwable.printStackTrace();
            }
        }
    
    }
    
            
    此代碼塊在浮窗中顯示
    <!-- 用於演示通知點擊跳轉 --> <activity android:name="com.engagelab.app.component.UserActivity400" android:exported="false" android:launchMode="singleTask" /> <!-- 白名單本地中轉驗證: 配置 ENGAGELAB_PRIVATES_TRANSFER 後,sdk 會做本地驗證; 不配置就不做本地驗證。如果開啟本地驗證,請將要跳轉的目標 Activity 配置在這裡; 如果有多個目標 Activity, 請用 / 分割開。 --> <meta-data android:name="ENGAGELAB_PRIVATES_TRANSFER" android:value="com.engagelab.app.component.UserActivity400" />
                <!-- 用於演示通知點擊跳轉 -->
      <activity
          android:name="com.engagelab.app.component.UserActivity400"
          android:exported="false"
          android:launchMode="singleTask" />
      <!-- 白名單本地中轉驗證: 配置 ENGAGELAB_PRIVATES_TRANSFER 後,sdk 會做本地驗證; 不配置就不做本地驗證。如果開啟本地驗證,請將要跳轉的目標 Activity 配置在這裡; 如果有多個目標 Activity, 請用 / 分割開。 -->
      <meta-data
          android:name="ENGAGELAB_PRIVATES_TRANSFER"
          android:value="com.engagelab.app.component.UserActivity400" />
    
            
    此代碼塊在浮窗中顯示
    在文档中心打开