Push the same message to all devices across the network using a template.
Scheduled and loop pushes are not supported when the target is a mobile analytics group or a custom tag group.
Before using this API, ensure the following tasks are completed:
Create the target template in the message push console, including placeholders, to enable personalized message pushes. For more information, see Create Template.
Add SDK dependencies. For more information, see SDK Preparation.
Request Parameters
Parameter Name | Type | Required | Example | Description |
classification | String | No | 1 | Used to pass the message type of the vivo push channel:
If not filled, the default is 1. |
taskName | String | Yes | Broadcast Test Task | Name of the push task. |
appId | String | Yes | ONEX570DA89211721 | mPaaS App ID |
workspaceId | String | Yes | test | mPaaS Workspace |
deliveryType | Long | Yes | 1 | Target ID type, value options:
|
msgkey | String | Yes | 1578807462788 | Business message ID, user-defined, must be unique. |
expiredSeconds | Long | Yes | 300 | Message validity period, in seconds. |
templateName | String | Yes | Broadcast Template | Template name, created in the console. |
templateKeyValue | String | No | {"content":"Announcement content"} | Template parameters, in Map format, corresponding to the template specified by |
pushStatus | Long | No | 0 | Push login status during broadcast push:
|
bindPeriod | Integer | No | Login duration, required when
Note The | |
unBindPeriod | Long | No | Logout duration, required when
| |
androidChannel | Integer | No | Android message channel:
| |
strategyType | int | No | 1 | Push strategy type:
If not filled, the default is 0. |
StrategyContent | String | No | {"fixedTime":1630303126000,"startTime":1625673600000,"endTime":1630303126000,"circleType":1,"circleValue":[1, 7],"time":"13:45:11"} | Push strategy details (JSON string). Required when |
thirdChannelCategory | Map | No | thirdChannelCategory: { "hms": "9", // Huawei FINANCE financial type message "vivo": "1" // vivo IM type message } | Used to pass vendor message classification, for details, see Vendor Message Classification. |
notifyLevel | Map | No | notifyLevel: {"oppo":"2"// OPPO notification bar + lock screen} | Vendor message notification level, such as OPPO message level as follows:
|
miChannelId | String | No | "123321" | Xiaomi vendor push channel's channelId |
StrategyContent Field Description
Convert JSON format to a String to pass values.
Parameter Name | Type | Required | Example | Description |
fixedTime | long | No | 1630303126000 | Scheduled push timestamp (unit: milliseconds, accurate to seconds). When the push policy type is scheduled ( |
startTime | long | No | 1640966400000 | The start timestamp of the loop cycle (unit: milliseconds, accurate to the day). When the push strategy type is loop ( |
endTime | long | No | 1672416000000 | The timestamp for the end of the loop cycle (unit: milliseconds, accurate to the day). The loop end time must not exceed 180 days after the current day. When the push policy type is loop ( |
circleType | int | No | 3 | Loop type:
When the push policy type is loop ( |
circleValue | int[] | No | [1,3] | Loop value:
When the push policy type is loop ( |
time | String | No | 09:45:11 | Loop push time (hours, minutes, and seconds, format is HH:mm:ss). When the push policy type is loop ( |
The default maximum number of unexecuted scheduled or loop push tasks is 100.
The loop cycle runs from 00:00 of the start time to 24:00 of the end time.
The loop start and end times cannot be earlier than 00:00 of the current day, and the end time cannot be before the start time.
Response Parameters
Parameter Name | Type | Example | Description |
RequestId | String | B589F4F4-CD68-3CE5-BDA0-6597F33E23916512 | 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. The value of the |
ResultMsg | String | param is invalid | Request error content. The value of the |
Data | String | 903bf653c1b5442b9ba07684767bf9c2 | Scheduled push task ID. This field is not empty when |
Code Examples
Ensure your AccessKey has AliyunMPAASFullAccess permission. For details, see Application-Level Access Control for RAM Accounts.
Java Code Example
Click here to see how to retrieve AccessKeyId and AccessKeySecret in the code example below.
DefaultProfile.addEndpoint("cn-hangzhou", "mpaas", "mpaas.cn-hangzhou.aliyuncs.com");
// Create DefaultAcsClient instance and initialize
// Alibaba Cloud account AccessKey has access to all APIs, which is highly risky. We strongly recommend that you create and use a RAM user for API access or daily operations. Please log on to the RAM console to create a RAM user
// Here, saving AccessKey and AccessKeySecret in environment variables is used as an example. You can also save them in the configuration file based on your business needs
// We strongly recommend that you do not save AccessKey and AccessKeySecret in the code, as there is a risk of key leakage
// It is recommended to complete the environment variable configuration first
String accessKeyId = System.getenv("MPAAS_AK_ENV");
String accessKeySecret = System.getenv("MPAAS_SK_ENV");
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou", // Region ID
accessKeyId,
accessKeySecret);
IAcsClient client = new DefaultAcsClient(profile);
PushBroadcastRequest request = new PushBroadcastRequest();
request.setAppId("ONEX570DA89211720");
request.setWorkspaceId("test");
request.setDeliveryType(2L);
request.setMsgkey(String.valueOf(System.currentTimeMillis()));
request.setExpiredSeconds(600L);
request.setTaskName("Broadcast Task");
request.setTemplateName("Broadcast Test");
// This is an announcement: #content#
Map<String, String> templatekv = new HashMap<String, String>();
templatekv.put("content", "Announcement content");
request.setTemplateKeyValue(JSON.toJSONString(templatekv));
request.setStrategyType(2);
request.setStrategyContent("{\"fixedTime\":1630303126000,\"startTime\":1625673600000,\"endTime\":1630303126000,\"circleType\":1,\"circleValue\":[1, 7],\"time\":\"13:45:11\"}");
PushBroadcastResponse response;
try {
response = client.getAcsResponse(request);
System.out.println(response.getResultCode());
System.out.println(response.getResultMessage());
System.out.println(response.getPushResult().getData()); // Push task ID or scheduled push task ID
} catch (ClientException e) {
e.printStackTrace();
}
Python Code Example
# -*- coding: utf8 -*-
from aliyunsdkcore.client import AcsClient
from aliyunsdkmpaas.request.v20190821 import PushBroadcastRequest
import json
import time
// Alibaba Cloud account AccessKey has access to all APIs, which is highly risky. We strongly recommend that you create and use a RAM user for API access or daily operations. Please log on to the RAM console to create a RAM user
// Here, saving AccessKey and AccessKeySecret in environment variables is used as an example. You can also save them in the configuration file based on your business needs
// We strongly recommend that you do not save AccessKey and AccessKeySecret in the code, as there is a risk of key leakage
// It is recommended to complete the environment variable configuration 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 client
// Alibaba Cloud account AccessKey has access to all APIs, which is highly risky. We strongly recommend that you create and use a RAM user for API access or daily operations. Please log on to the RAM console to create a RAM user
// Here, saving AccessKey and AccessKeySecret in environment variables is used as an example. You can also save them in the configuration file based on your business needs
// We strongly recommend that you do not save AccessKey and AccessKeySecret in the code, as there is a risk of key leakage
// It is recommended to complete the environment variable configuration 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 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")
// Enable 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();
}
}