Sends the same template-based message to all devices on the network.
Scheduled and recurring pushes are not supported when the target audience is a mobile analytics group or a custom tag group.
Before you call this API:
-
Create a target template with placeholders in the Message Push console to enable personalized messages per push ID. Create a template.
-
Import SDK dependencies. SDK preparation.
Request parameters
|
Parameter name |
Type |
Required |
Example |
Description |
|
classification |
String |
No |
1 |
The message type for the vivo push channel.
Default: 1. |
|
taskName |
String |
Yes |
Broadcast test task |
Push task name. |
|
appId |
String |
Yes |
ONEX570DA89211721 |
The mPaaS App ID. |
|
workspaceId |
String |
Yes |
test |
The mPaaS workspace. |
|
deliveryType |
Long |
Yes |
1 |
The target ID type. Valid values:
|
|
msgkey |
String |
Yes |
1578807462788 |
User-defined unique business message ID. |
|
expiredSeconds |
Long |
Yes |
300 |
Message validity period, in seconds. |
|
templateName |
String |
Yes |
Broadcast template |
Template name. Create templates in the console. |
|
templateKeyValue |
String |
No |
{"content":"Announcement content"} |
Template parameters in map format for the template specified by |
|
pushStatus |
Long |
No |
0 |
The logon status for broadcast push.
|
|
bindPeriod |
Integer |
No |
Logon duration. Required when
Note
The |
|
|
unBindPeriod |
Long |
No |
Logoff duration. Required when
|
|
|
androidChannel |
Integer |
No |
The Android message channel.
|
|
|
strategyType |
int |
No |
1 |
The push policy type.
Default: 0. |
|
StrategyContent |
String |
No |
{\”fixedTime\”:1630303126000,\”startTime\”:1625673600000,\”endTime\”:1630303126000,\”circleType\”:1,\”circleValue\”:[1, 7],\”time\”:\”13:45:11\”} |
Push policy details as a JSON string. Required when |
|
transparentMessagePayload |
Map<String, JSONObject> |
No |
- |
The vendor pass-through message body.
The format of the pass-through message body is as follows:
|
|
transparentMessageUrgency |
String |
No |
- |
Vendor pass-through message priority. Valid only when `transparentMessagePayload` is set. Only Huawei, Honor, and HarmonyOS support this parameter. Valid values: HIGH, NORMAL. For Huawei and Honor:
For HarmonyOS:
|
|
thirdChannelCategory |
Map |
No |
thirdChannelCategory: { "hms": "9", //Huawei FINANCE message "vivo": "1" //vivo IM message } |
Vendor message categorization. Vendor message categorization. |
|
notifyLevel |
Map |
No |
notifyLevel: {"oppo":"2"//OPPO notification bar + lock screen} |
Vendor message notification level. OPPO message levels:
|
|
miChannelId |
String |
No |
"123321" |
Xiaomi push channel ID. |
|
timeMode |
Integer |
No |
0 |
The time mode.
|
|
bindStartTime |
Long |
No |
1746720000000 |
The start timestamp for attachment. |
|
bindEndTime |
Long |
No |
1746806219999 |
The end timestamp for attachment. |
|
unBindStartTime |
Long |
No |
1746720000000 |
The start timestamp for detachment. |
|
unBindEndTime |
Long |
No |
1746806219999 |
The end timestamp for detachment. |
StrategyContent field description
Pass the value as a JSON string.
|
Parameter name |
Type |
Required |
Example |
Description |
|
fixedTime |
long |
No |
1630303126000 |
Scheduled push timestamp in milliseconds, accurate to the second. |
|
startTime |
long |
No |
1640966400000 |
Start timestamp of the recurring cycle. UNIX timestamp in milliseconds, accurate to the day. |
|
endTime |
long |
No |
1672416000000 |
End timestamp of the recurring cycle in milliseconds, accurate to the day. Cannot exceed 180 days from today. |
|
circleType |
int |
No |
3 |
Loop type:
|
|
circleValue |
int[] |
No |
[1,3] |
The recurrence value.
|
|
time |
String |
No |
09:45:11 |
Recurring push time in |
-
The maximum number of pending scheduled or recurring push tasks is 100 by default.
-
The recurring epoch starts at 00:00 on the start date and ends at 24:00 on the end date.
-
The start and end times for a recurring task cannot be earlier than 00:00 on the current day. The end time cannot be earlier than the start time.
Response parameters
|
Parameter name |
Type |
Example |
Description |
|
RequestId |
String |
B589F4F4-CD68-3CE5-BDA0-6597F33E23916512 |
The request ID. |
|
ResultCode |
String |
OK |
Request result code. |
|
ResultMessage |
String |
param is invalid |
Request error description. |
|
PushResult |
JSON |
Request result. |
|
|
Success |
boolean |
true |
Request status. |
|
ResultMsg |
String |
param is invalid |
Error details. |
|
Data |
String |
903bf653c1b5442b9ba07684767bf9c2 |
Scheduled push task ID. Non-empty when |
Code examples
Your AccessKey must have the `AliyunMPAASFullAccess` permission. Application-level access control for RAM accounts.
Java code example
To obtain the AccessKey ID and AccessKey secret used in the example below, see AccessKey management.
import com.alibaba.fastjson.JSON;
import com.aliyun.mpaas20201028.Client;
import com.aliyun.mpaas20201028.models.PushBroadcastRequest;
import com.aliyun.mpaas20201028.models.PushBroadcastResponse;
import com.aliyun.teaopenapi.models.Config;
import java.text.SimpleDateFormat;
public static void main(String[] args) throws Exception {
// An Alibaba Cloud account AccessKey has full access to all APIs. We recommend that you use a RAM user for API calls and daily O&M.
// We strongly recommend that you do not hard-code the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and threaten the security of all your resources.
// This example shows how to store the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// We recommend that you configure the environment variables first.
Config config = new Config();
// Required. Your AccessKey ID.
config.setAccessKeyId(System.getenv("MPAAS_AK_ENV"));
// Required. Your AccessKey secret.
config.setAccessKeySecret(System.getenv("MPAAS_SK_ENV"));
// The REGION_ID and Endpoint of mPaaS. The Hangzhou non-Gold environment is used as an example.
config.setRegionId("cn-hangzhou");
config.setEndpoint("mpaas.cn-hangzhou.aliyuncs.com");
Client client = new Client(config);
PushBroadcastRequest request = new PushBroadcastRequest();
request.setAppId("ONEX570DA89211721");
request.setWorkspaceId("test");
request.setTenantId("xxx");
request.setTemplateName("Test Template");
request.setExpiredSeconds(180L);
request.setTaskName("Broadcast Task");
request.setAndroidChannel(2);
// 1: Android, 2: iOS, 7: HarmonyOS
request.setDeliveryType(1L);
// 0: Fixed number of days, 1: Time range
// request.setTimeMode(1);
// 0: Query attached devices, 1: Query attached/detached device information, 2: Query detached device information
request.setPushStatus(0L);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long startTime = dateFormat.parse("2024-05-20 15:59:48").getTime();
long endTime = dateFormat.parse("2024-05-20 15:59:48").getTime();
request.setBindStartTime(startTime);
request.setBindEndTime(endTime);
request.setMsgkey(String.valueOf(System.currentTimeMillis()));
System.out.println("request==>"+JSON.toJSONString(request));
PushBroadcastResponse acsResponse = client.pushBroadcast(request);
System.out.println("response==>"+JSON.toJSONString(acsResponse));
}
Python code example
# -*- coding: utf8 -*-
from aliyunsdkcore.client import AcsClient
from aliyunsdkmpaas.request.v20190821 import PushBroadcastRequest
import json
import time
// An Alibaba Cloud account AccessKey has full access to all APIs, which poses a high security risk. We strongly recommend that you create and use a RAM user for API calls and daily O&M. Log on to the RAM console to create a RAM user.
// This example shows how to store the AccessKey and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// We strongly recommend that you do not hard-code the AccessKey and AccessKey secret in your code to avoid key leakage.
// We recommend that you configure the environment variables first.
# Initialize AcsClient instance
String accessKeyId = System.getenv("MPAAS_AK_ENV");
String accessKeySecret = System.getenv("MPAAS_SK_ENV");
client = AcsClient(
accessKeyId,
accessKeySecret,
"cn-hangzhou"
);
# Initialize a request and set parameters
request = PushBroadcastRequest.PushBroadcastRequest()
request.set_endpoint("mpaas.cn-hangzhou.aliyuncs.com")
request.set_AppId("ONEX570DA89211720")
request.set_WorkspaceId("test")
request.set_TemplateName("broadcastTemplate")
templatekv = {"content":"This is an announcement"}
request.set_TemplateKeyValue(json.dumps(templatekv))
request.set_DeliveryType(1)
request.set_TaskName("Python test broadcast task")
request.set_ExpiredSeconds(600)
request.set_Msgkey(str(time.time()))
# Print response
response = client.do_action_with_exception(request)
print response
Node.js code example
const sdk = require('@alicloud/mpaas20190821');
const { default: Client, PushBroadcastRequest } = sdk;
// Create a client
// An Alibaba Cloud account AccessKey has full access to all APIs, which poses a high security risk. We strongly recommend that you create and use a RAM user for API calls and daily O&M. Log on to the RAM console to create a RAM user.
// This example shows how to store the AccessKey and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
// We strongly recommend that you do not hard-code the AccessKey and AccessKey secret in your code to avoid key leakage.
// We recommend that you configure the environment variables first.
String accessKeyId = System.getenv("MPAAS_AK_ENV");
String accessKeySecret = System.getenv("MPAAS_SK_ENV");
const client = new Client({
accessKeyId,
accessKeySecret,
endpoint: 'mpaas.cn-hangzhou.aliyuncs.com',
apiVersion: '2019-08-21'
});
// Initialize request
const request = new PushBroadcastRequest();
request.appId = "ONEX570DA89211720";
request.workspaceId = "test";
request.templateName= "broadcastTemplate";
const templatekv = {
content: 'This is an announcement',
};
request.templateKeyValue = JSON.stringify(templatekv);
request.deliveryType = 1;
request.taskName = "Node.js test task";
request.expiredSeconds=600;
const extendedParam = {
test: 'Custom extended parameter'
};
request.extendedParams = JSON.stringify(extendedParam);
request.msgkey = String(new Date().valueOf())
// Call API
try {
client.pushBroadcast(request).then(res => {
console.log('SUCCESS', res);
}).catch(e => {
console.log('FAIL', e);
});
} catch(e) {
console.log('ERROR', e);
}
PHP code example
<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\MPaaS\MPaaS;
AlibabaCloud::accessKeyClient('accessKeyId', 'accessKeySecret')
->regionId('cn-hangzhou')
->asDefaultClient();
class Demo {
public function run() {
try {
$this->broadcastPush();
} catch (\Exception $e) {
}
}
public function broadcastPush(){
$request = MPaaS::v20190821()->pushBroadcast();
$result = $request->host("mpaas.cn-hangzhou.aliyuncs.com")
// Specifies whether to enable the debug mode
->debug(true)
->withAppId("ONEX570DA89211720")
->withWorkspaceId("test")
->withTemplateName("broadcastTemplate")
->withTemplateKeyValue(
json_encode(["content" => "This is an announcement"])
)
->withDeliveryType(1)
->withTaskName("PHP test broadcast task")
->withExpiredSeconds(600)
->withMsgkey("". time())
->request();
}
}