This operation pushes a message to a push ID.
Before you call this API, you must import the required dependencies. For more information, see SDK Preparation.
Request parameters
Parameter name | Type | Required | Example | Description |
classification | String | No | 1 | The message type for the vivo push channel.
The default value is 1. |
taskName | String | Yes | simpleTest | The name of the push task. |
title | String | Yes | Test | The title of the message. |
content | String | Yes | Test | The body of the message. |
appId | String | Yes | ONEX570DA89211721 | The mPaaS App ID. |
workspaceId | String | Yes | test | The mPaaS workspace. |
deliveryType | Long | Yes | 3 | The type of the target ID. Valid values:
|
targetMsgkey | String | Yes | {“user1024”:”1578807462788”} | The push target in a map format.
Note You can specify a maximum of 10 push targets. This means the |
expiredSeconds | Long | Yes | 300 | The validity period of the message in seconds. |
pushStyle | Integer | Yes | 0 | The push style.
|
extendedParams | String | No | {“key1”:”value1”} | The extended parameters in a map format. |
pushAction | Long | No | 0 | The action to take after a message is clicked.
The default value is Web URL. |
uri | String | No | http://www | The URL to which the user is redirected after the message is clicked. |
silent | Long | No | 1 | Specifies whether to send a silent push.
|
notifyType | String | No | The message channel type.
| |
imageUrls | String | No | The URL of the large image in a JSON string. This parameter is supported by OPPO, HMS, MIUI, FCM, and iOS push channels. You can also use | |
iconUrls | String | No | The URL of the icon in a JSON string. This parameter is supported by OPPO, HMS, MIUI, FCM, and iOS push channels. You can also use | |
strategyType | Integer | No | 1 | The push policy type.
The default value is 0. |
StrategyContent | String | No | {\”fixedTime\”:1630303126000,\”startTime\”:1625673600000,\”endTime\”:1630303126000,\”circleType\”:1,\”circleValue\”:[1, 7],\”time\”:\”13:45:11\”} | The details of the push policy in a JSON string. This parameter is required when |
smsStrategy | int | No | 2 | The SMS policy.
|
smsSignName | String | No | mPaaS Test | The SMS signature. |
smsTemplateCode | String | No | SMS_216070269 | The SMS template ID. |
smsTemplateParam | String | No | {\"code\": 123456} | The actual values for the variables in the SMS template, in JSON format. |
thirdChannelCategory | Map | No | thirdChannelCategory: { "hms": "9", // Huawei FINANCE: financial message "vivo": "1" // vivo: IM message } | Used to pass the vendor message category. For more information, see Vendor message categories. |
notifyLevel | Map | No | notifyLevel: {"oppo":"2"//OPPO: Notification bar + lock screen} | The notification level for vendor messages. For example, the OPPO message levels are as follows:
|
miChannelId | String | No | "123321" | The channelId for the Xiaomi push channel. |
activityEvent | String | No | The Live Activity event. Valid values are update or end.
| |
activityContentState | JSONObject | No | The | |
dismissalDate | long | No | The expiration time for the Live Activity message as a UNIX timestamp in seconds. This is an optional field. If not specified, the default iOS system expiration time of 12 hours is used. |
Notes on the smsStrategy parameter:
If the value of
smsStrategyis not 0, thesmsSignName,smsTemplateCode, andsmsTemplateParamparameters are required.
Notes on the activityEvent parameter:
When the
activityEventis an `end` event, the expiration time that is configured indismissalDateis applied.When the
activityEventis an `update` event, the expiration time that is configured indismissalDateis ignored.If you send an `end` event but do not specify a value for
dismissalDate, the iOS system ends the Live Activity after 4 hours by default.
StrategyContent field description
The value is converted from JSON to a string before it is passed.
Parameter Name | Type | Required | Example | Description |
fixedTime | long | No | 1630303126000 | The timestamp for the scheduled push in milliseconds, accurate to the second. |
startTime | long | No | 1640966400000 | The start timestamp of the recurring epoch in milliseconds, accurate to the day. |
endTime | long | No | 1672416000000 | The end timestamp of the recurring epoch in milliseconds, accurate to the day. The end time cannot be more than 180 days from the current day. |
circleType | int | No | 3 | The recurrence type.
|
circleValue | int[] | No | [1,3] | The recurrence value.
|
time | String | No | 09:45:11 | The time for the recurring push in HH:mm:ss format. |
The maximum number of unexecuted scheduled or recurring push tasks is 100 by default.
The recurring epoch is the period from 00:00 on the start date to 24:00 on the end date.
The start time and end time 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 | The result code of the request. |
ResultMessage | String | param is invalid | The error description of the request. |
PushResult | JSON | The result of the request. | |
Success | boolean | true | The request status. The |
ResultMsg | String | param is invalid | The error details of the request. The |
Data | String | 903bf653c1b5442b9ba07684767bf9c2 | The ID of the scheduled push task. This field is not empty when |
Code examples
Make sure that your AccessKey has the `AliyunMPAASFullAccess` permission. For more information, see Control access to applications for RAM accounts.
Java code example
Click here to learn how to obtain an AccessKey ID and an AccessKey secret for the code example below.
import com.alibaba.fastjson.JSON;
import com.aliyun.mpaas20201028.Client;
import com.aliyun.mpaas20201028.models.PushSimpleRequest;
import com.aliyun.mpaas20201028.models.PushSimpleResponse;
import com.aliyun.teaopenapi.models.Config;
import java.util.HashMap;
import java.util.Map;
public static void main(String[] args) throws Exception {
// Your 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 save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey leak and threaten the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret in environment variables. You can also save 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. This example uses a non-Gold region in Hangzhou.
config.setRegionId("cn-hangzhou");
config.setEndpoint("mpaas.cn-hangzhou.aliyuncs.com");
Client client = new Client(config);
PushSimpleRequest request = new PushSimpleRequest();
request.setAppId("ONEX570DA89211721");
request.setWorkspaceId("test");
request.setTenantId("xxx");
request.setTitle("Simple Test Title");
request.setContent("Simple Test Content");
request.setExpiredSeconds(180L);
request.setTaskName("-");
request.setDeliveryType(3L);
Map<String,String> targetMsgkey = new HashMap<>();
String msgKey = String.valueOf(System.currentTimeMillis());
targetMsgkey.put("push_test",msgKey);
request.setTargetMsgkey(JSON.toJSONString(targetMsgkey));
System.out.println("request==>"+JSON.toJSONString(request));
PushSimpleResponse pushSimpleResponse = client.pushSimple(request);
System.out.println("response==>"+JSON.toJSONString(pushSimpleResponse));
}Python code example
from aliyunsdkcore.client import AcsClient
from aliyunsdkmpaas.request.v20190821 import PushSimpleRequest
import json
# Your 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 save the AccessKey and AccessKey secret in environment variables. You can also save them in a configuration file as needed.
# We strongly recommend that you do not save the AccessKey and AccessKey secret in your code. This can lead to a key leak.
# We recommend that you configure the environment variables first.
accessKeyId = System.getenv("MPAAS_AK_ENV")
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.
// Your 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 save the AccessKey and AccessKey secret in environment variables. You can also save them in a configuration file as needed.
// We strongly recommend that you do not save the AccessKey and AccessKey secret in your code. This can lead to a key leak.
// We recommend that you configure the environment variables first.
const accessKeyId = System.getenv("MPAAS_AK_ENV");
const accessKeySecret = System.getenv("MPAAS_SK_ENV");
const client = new Client({
accessKeyId,
accessKeySecret,
endpoint: 'mpaas.cn-hangzhou.aliyuncs.com',
apiVersion: '2019-08-21'
});
// Initialize the 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);
// The value is the business message ID. Make sure it is 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")
// Specifies whether to enable debug mode.
->debug(true)
->request();
}
}