快速测试通知消息

最新更新:2023-02-28

后台下发通知消息

下发合集:电脑上下载 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
  • 大文本风格
    OTIFICATION_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" />
    
            
    此代码块在浮窗中显示
    在文档中心打开