Push a message to a specified push ID.
Before using this API, you must introduce 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 | simpleTest | Name of the push task. |
title | String | Yes | Test | Title of the message. |
content | String | Yes | Test | Body of the message. |
appId | String | Yes | ONEX570DA89211721 | mPaaS App ID |
workspaceId | String | Yes | test | mPaaS workspace |
deliveryType | Long | Yes | 3 | Target ID type, with the following options:
|
targetMsgkey | String | Yes | {“user1024”:”1578807462788”} | Push target in Map format:
Note The push target cannot exceed 10, meaning the |
expiredSeconds | Long | Yes | 300 | Message validity period in seconds. |
pushStyle | Integer | Yes | 0 | Push style:
|
extendedParams | String | No | {“key1”:”value1”} | Extended parameters in Map format. |
pushAction | Long | No | 0 | Redirection method after clicking the message:
The default is Web URL. |
uri | String | No | http://www | Redirection address after clicking the message. |
silent | Long | No | 1 | Whether silent:
|
notifyType | String | No | Indicates the message channel type:
| |
imageUrls | String | No | Large image links (JSON string), supporting OPPO, HMS, MIUI, FCM, and iOS push channels. You can also use | |
iconUrls | String | No | Icon links (JSON string), supporting OPPO, HMS, MIUI, FCM, and iOS push channels. You can also use | |
strategyType | Integer | 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 |
smsStrategy | int | No | 2 | SMS strategy:
|
smsSignName | String | No | mPaaS test | SMS signature |
smsTemplateCode | String | No | SMS_216070269 | SMS template ID |
smsTemplateParam | String | No | {\"code\": 123456} | Actual value corresponding to the SMS template variable, in JSON format. |
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" | ChannelId of Xiaomi vendor push channel |
activityEvent | String | No | Real-time activity event, optional update/end:
| |
activityContentState | JSONObject | No | The | |
dismissalDate | long | No | Expiration time of the real-time activity message (timestamp in seconds), optional field. If not passed, the default expiration time of the iOS system is 12h. |
Regarding the smsStrategy parameter:
If the value of
smsStrategyis not 0,smsSignName,smsTemplateCode, andsmsTemplateParamare required.
Regarding the activityEvent parameter:
When
activityEventis an end event, the expiration time set bydismissalDatewill be effective.When
activityEventis an update event, the expiration time set bydismissalDatewill not be effective.If the end event is specified but
dismissalDateis not, the iOS system will default to ending the real-time activity after 4 hours.
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 timestamp for the start of the loop cycle (unit: milliseconds, accurate to the day). When the push policy type is loop ( |
endTime | long | No | 1672416000000 | The timestamp of the loop cycle end time (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 (hour, minute, second, format is HH:mm:ss). When the push policy type is loop ( |
By default, the maximum number of unexecuted scheduled or loop push tasks is 100.
The loop cycle runs from 00:00 of the start date to 24:00 of the end date.
The loop start and end times must not be earlier than 00:00 of the current day, and the end time must not be earlier than the start time.
Return 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 |
ResultMsg | String | param is invalid | Request error content. The |
Data | String | 903bf653c1b5442b9ba07684767bf9c2 | Scheduled push task ID. This field is not empty when |
Code examples
Ensure that your AccessKey has the AliyunMPAASFullAccess permission. For more information, see Application-Level Access Control for RAM Accounts.
Java code example
Click here to learn how to obtain your AccessKeyId and AccessKeySecret in the code example below.
DefaultProfile.addEndpoint("cn-hangzhou", "mpaas", "mpaas.cn-hangzhou.aliyuncs.com");
// Create a DefaultAcsClient instance and initialize it
// The Alibaba Cloud account AccessKey has access to all APIs. It is recommended to use RAM users for API access or daily operations.
// We strongly recommend that you do not save the AccessKey ID and AccessKey Secret in the project code. Otherwise, the AccessKey may be leaked, compromising the security of all resources in your account.
// This example demonstrates saving the AccessKey ID and AccessKey Secret in environment variables. You can also save them in configuration files based on your business needs.
// 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);
// Create an API request and set parameters
PushSimpleRequest request = new PushSimpleRequest();
request.setAppId("ONEX570DA89211721");
request.setWorkspaceId("test");
request.setTaskName("Test task");
request.setTitle("Test");
request.setContent("Test");
request.setDeliveryType(3L);
Map<String,String> extendedParam = new HashMap<String, String>();
extendedParam.put("key1","value1");
request.setExtendedParams(JSON.toJSONString(extendedParam));
request.setExpiredSeconds(300L);
request.setPushStyle(2);
String imageUrls = "{\"defaultUrl\":\"https://pre-mpaas.oss-cn-hangzhou.aliyuncs.com/tmp/test.png\",\"oppoUrl\":\"https://pre-mpaas.oss-cn-hangzhou.aliyuncs.com/tmp/test.png\",\"miuiUrl\":\"https://pre-mpaas.oss-cn-hangzhou.aliyuncs.com/tmp/test.png\",\"fcmUrl\":\"https://pre-mpaas.oss-cn-hangzhou.aliyuncs.com/tmp/test.png\",\"iosUrl\":\"https://pre-mpaas.oss-cn-hangzhou.aliyuncs.com/tmp/test.png\"}";
String iconUrls = "{\"defaultUrl\":\"https://pre-mpaas.oss-cn-hangzhou.aliyuncs.com/tmp/test.png\",\"hmsUrl\":\"https://pre-mpaas.oss-cn-hangzhou.aliyuncs.com/tmp/test.png\",\"oppoUrl\":\"https://pre-mpaas.oss-cn-hangzhou.aliyuncs.com/tmp/test.png\",\"miuiUrl\":\"https://pre-mpaas.oss-cn-hangzhou.aliyuncs.com/tmp/test.png\"}";
request.setImageUrls(imageUrls);
request.setIconUrls(iconUrls);
request.setStrategyType(2);
request.setStrategyContent("{\"fixedTime\":1630303126000,\"startTime\":1625673600000,\"endTime\":1630303126000,\"circleType\":1,\"circleValue\":[1, 7],\"time\":\"13:45:11\"}");
Map<String,String> target = new HashMap<String, String>();
String msgKey = String.valueOf(System.currentTimeMillis());
target.put("user1024",msgKey);
request.setTargetMsgkey(JSON.toJSONString(target));
// Initiate the request and handle the response or exceptions
PushSimpleResponse response;
try {
response = client.getAcsResponse(request);
System.out.println(response.getResultCode());
System.out.println(response.getResultMessage());
} catch (ClientException e) {
e.printStackTrace();
}Python code example
from aliyunsdkcore.client import AcsClient
from aliyunsdkmpaas.request.v20190821 import PushSimpleRequest
import json
// The Alibaba Cloud account AccessKey has access to all APIs, which is very risky. We strongly recommend that you create and use RAM users for API access or daily operations. Please log on to the RAM console to create RAM users
// This example demonstrates saving the AccessKey and AccessKeySecret in environment variables. You can also save them in configuration files based on your business needs
// We strongly recommend that you do not save the 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");
# Initialize AcsClient instance
client = AcsClient(
"cn-hangzhou",
accessKeyId,
accessKeySecret
);
# Initialize a request and set parameters
request = PushSimpleRequest.PushSimpleRequest()
request.set_endpoint("mpaas.cn-hangzhou.aliyuncs.com")
request.set_AppId("ONEX570DA89211721")
request.set_WorkspaceId("test")
request.set_Title( "Python test")
request.set_Content( "Test 2")
request.set_DeliveryType(3)
request.set_TaskName("Python test task")
request.set_ExpiredSeconds(600)
target = {"user1024":str(time.time())}
request.set_TargetMsgkey(json.dumps(target))
# Print response
response = client.do_action_with_exception(request)
print responseNode.js code example
const sdk = require('@alicloud/mpaas20190821');
const { default: Client, PushSimpleRequest } = sdk;
// Create a client
// The Alibaba Cloud account AccessKey has access to all APIs, which is very risky. We strongly recommend that you create and use RAM users for API access or daily operations. Please log on to the RAM console to create RAM users
// This example demonstrates saving the AccessKey and AccessKeySecret in environment variables. You can also save them in configuration files based on your business needs
// We strongly recommend that you do not save the 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 PushSimpleRequest();
request.appId = "ONEX570DA89211721";
request.workspaceId = "test";
request.title = "Node test";
request.content = "Test";
request.deliveryType = 3;
request.taskName = "Node test task";
request.expiredSeconds=600;
const extendedParam = {
test: 'Custom extended parameter'
};
request.extendedParams = JSON.stringify(extendedParam);
// Value is the business message ID, please keep it unique
const target = {
"userid1024": String(new Date().valueOf())
};
request.targetMsgkey = JSON.stringify(target);
// Call the API
try {
client.pushSimple(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->simplePush();
} catch (\Exception $e) {
}
}
public function simplePush() {
$request = MPaaS::v20190821()->pushSimple();
$result = $request->withAppId("ONEX570DA89211721")
->withWorkspaceId("test")
->withTitle("PHP test")
->withContent("Test 3")
->withDeliveryType(3)
->withTaskName("PHP test task")
->withExpiredSeconds(600)
->withTargetMsgkey(
json_encode(["userid1024" => "".time() ]
))
// Endpoint
->host("mpaas.cn-hangzhou.aliyuncs.com")
// Whether to enable debug mode
->debug(true)
->request();
}
}