Push
描述
推送高级接口。
请求参数
基础参数
推送目标(destination)
推送配置(config)
Title/Body/Summary 展开说明如下:
下述配置仅作用于iOS通知任务
- [backcolor=transparent]【注意】若没有进行iOS 10通知相关配置(iOSTitle / iOSSubTitle / iOSMutableContent / iOSNotificationCategory),通知payload保持老版本不变,已经保证对老版本payload兼容性;若进行iOS 10通知相关配置,请确保客户端业务逻辑对payload相关字段处理的兼容性;iOS通知payload字段参考iOS 10通知适配-第3节。
下述配置仅作用于iOS消息
下述配置仅作用于Android通知任务
推送控制(push control)
响应参数
错误码
对于所有接口的通用性错误,请参考
错误代码表。
示例
请求示例
- [backcolor=transparent]http[backcolor=transparent]:[backcolor=transparent]//cloudpush.aliyuncs.com/?Action=Push
- [backcolor=transparent]&[backcolor=transparent]AppKey[backcolor=transparent]=[backcolor=transparent]23267207
- [backcolor=transparent]&[backcolor=transparent]Target[backcolor=transparent]=[backcolor=transparent]device[backcolor=transparent]&
- [backcolor=transparent]&[backcolor=transparent]TargetValue[backcolor=transparent]=[backcolor=transparent]e2ba19de97604f55b165576736477b74[backcolor=transparent]%[backcolor=transparent]2C92a1da34bdfd4c9692714917ce22d53d
- [backcolor=transparent]&[backcolor=transparent]Title[backcolor=transparent]=[backcolor=transparent]hello
- [backcolor=transparent]&[backcolor=transparent]Body[backcolor=transparent]=[backcolor=transparent]hello
- [backcolor=transparent]&[backcolor=transparent]Type[backcolor=transparent]=[backcolor=transparent]1
- [backcolor=transparent]&[backcolor=transparent]AndroidOpenType[backcolor=transparent]=[backcolor=transparent]1
- [backcolor=transparent]&[backcolor=transparent]DeviceType[backcolor=transparent]=[backcolor=transparent]3
- [backcolor=transparent]&[backcolor=transparent]Remind[backcolor=transparent]=[backcolor=transparent]false
- [backcolor=transparent]&[backcolor=transparent]StoreOffline[backcolor=transparent]=[backcolor=transparent]false
- [backcolor=transparent]&<公共请求参数>
返回示例
XML格式
- [backcolor=transparent]<?[backcolor=transparent]xml version[backcolor=transparent]=[backcolor=transparent]'1.0'[backcolor=transparent] encoding[backcolor=transparent]=[backcolor=transparent]'UTF-8'[backcolor=transparent]?>
- [backcolor=transparent]<PushResponse>
- [backcolor=transparent] [backcolor=transparent]<ResponseId>[backcolor=transparent]129376928[backcolor=transparent]</ResponseId>
- [backcolor=transparent]</PushResponse>
JSON格式
- [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]"ResponseId"[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]"129377184"
- [backcolor=transparent]}
Java示例代码
- [backcolor=transparent]PushRequest[backcolor=transparent] pushRequest [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]PushRequest[backcolor=transparent]();
- [backcolor=transparent]// 推送目标
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAppKey[backcolor=transparent]([backcolor=transparent]appKey[backcolor=transparent]);
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setTarget[backcolor=transparent]([backcolor=transparent]"all"[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]//推送目标: device:推送给设备; account:推送给指定帐号,tag:推送给自定义标签; all: 推送给全部
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setTargetValue[backcolor=transparent]([backcolor=transparent]"all"[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]//根据Target来设定,如Target=device, 则对应的值为 设备id1,设备id2. 多个值使用逗号分隔.(帐号与设备有一次最多100个的限制)
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setDeviceType[backcolor=transparent]([backcolor=transparent]3[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// 设备类型deviceType 取值范围为:0~3. iOS设备: 0; Android设备: 1; 全部: 3, 这是默认值.
- [backcolor=transparent]// 推送配置
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setType[backcolor=transparent]([backcolor=transparent]1[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// 0:表示消息(默认为0), 1:表示通知
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setTitle[backcolor=transparent]([backcolor=transparent]"Hello"[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// 消息的标题
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setBody[backcolor=transparent]([backcolor=transparent]"PushRequest body"[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// 消息的内容
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setSummary[backcolor=transparent]([backcolor=transparent]"PushRequest summary"[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// 通知的摘要
- [backcolor=transparent]// 推送配置: iOS
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setiOSBadge[backcolor=transparent]([backcolor=transparent]"5"[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// iOS应用图标右上角角标
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setiOSMusic[backcolor=transparent]([backcolor=transparent]"default"[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// iOS通知声音
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setiOSExtParameters[backcolor=transparent]([backcolor=transparent]"{\"k1\":\"ios\",\"k2\":\"v2\"}"[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]//自定义的kv结构,开发者扩展用 针对iOS设备
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setApnsEnv[backcolor=transparent]([backcolor=transparent]"DEV"[backcolor=transparent]);
- [backcolor=transparent]// pushRequest.setRemind(true); // 当APP不在线时候,是否通过通知提醒
- [backcolor=transparent]// 推送配置: Android
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidOpenType[backcolor=transparent]([backcolor=transparent]"3"[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// 点击通知后动作,1:打开应用 2: 打开应用Activity 3:打开 url
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidOpenUrl[backcolor=transparent]([backcolor=transparent]"http://www.baidu.com"[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// Android收到推送后打开对应的url,仅仅当androidOpenType=3有效
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setAndroidExtParameters[backcolor=transparent]([backcolor=transparent]"{\"k1\":\"android\",\"k2\":\"v2\"}"[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// 设定android类型设备通知的扩展属性
- [backcolor=transparent]// 推送控制
- [backcolor=transparent]final[backcolor=transparent] [backcolor=transparent]Date[backcolor=transparent] pushDate [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]Date[backcolor=transparent]([backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]currentTimeMillis[backcolor=transparent]()[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]3600[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent] [backcolor=transparent]1000[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// 一小时后发送, 也可以设置成你指定固定时间
- [backcolor=transparent]final[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] pushTime [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]ParameterHelper[backcolor=transparent].[backcolor=transparent]getISO8601Time[backcolor=transparent]([backcolor=transparent]pushDate[backcolor=transparent]);
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setPushTime[backcolor=transparent]([backcolor=transparent]pushTime[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// 延后推送。可选,如果不设置表示立即推送
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setStoreOffline[backcolor=transparent]([backcolor=transparent]true[backcolor=transparent]);[backcolor=transparent] [backcolor=transparent]// 离线消息是否保存,若保存, 在推送时候,用户即使不在线,下一次上线则会收到
- [backcolor=transparent]final[backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] expireTime [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]ParameterHelper[backcolor=transparent].[backcolor=transparent]getISO8601Time[backcolor=transparent]([backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]Date[backcolor=transparent]([backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]currentTimeMillis[backcolor=transparent]()[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] [backcolor=transparent]12[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent] [backcolor=transparent]3600[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent] [backcolor=transparent]1000[backcolor=transparent]));[backcolor=transparent] [backcolor=transparent]// 12小时后消息失效, 不会再发送
- [backcolor=transparent]pushRequest[backcolor=transparent].[backcolor=transparent]setExpireTime[backcolor=transparent]([backcolor=transparent]expireTime[backcolor=transparent]);
- [backcolor=transparent]PushResponse[backcolor=transparent] pushResponse [backcolor=transparent]=[backcolor=transparent] client[backcolor=transparent].[backcolor=transparent]getAcsResponse[backcolor=transparent]([backcolor=transparent]pushRequest[backcolor=transparent]);
- [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]printf[backcolor=transparent]([backcolor=transparent]"RequestId: %s, ResponseId: %s, message: %s\n"[backcolor=transparent],
- [backcolor=transparent] pushResponse[backcolor=transparent].[backcolor=transparent]getRequestId[backcolor=transparent](),[backcolor=transparent] pushResponse[backcolor=transparent].[backcolor=transparent]getResponseId[backcolor=transparent](),[backcolor=transparent] pushResponse[backcolor=transparent].[backcolor=transparent]getMessage[backcolor=transparent]());
- [backcolor=transparent]com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]exceptions[backcolor=transparent].[backcolor=transparent]ClientException[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]Push[backcolor=transparent] [backcolor=transparent]Failed[backcolor=transparent] [backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]Push[backcolor=transparent] [backcolor=transparent]Fail[backcolor=transparent]![backcolor=transparent] [backcolor=transparent]排查步骤
- [backcolor=transparent]1[backcolor=transparent]、检查[backcolor=transparent]SDK[backcolor=transparent]的版本号,是否是最新版本?
- [backcolor=transparent]2[backcolor=transparent]、[backcolor=transparent]title[backcolor=transparent]是不是大于[backcolor=transparent]20[backcolor=transparent]个字符了?
- [backcolor=transparent]3[backcolor=transparent]、是不是有必填参数没有填写?[backcolor=transparent] [backcolor=transparent]高级接口因为既可以发送[backcolor=transparent]iOS[backcolor=transparent]也可以发送[backcolor=transparent]Android[backcolor=transparent],所以[backcolor=transparent]iOS[backcolor=transparent]和[backcolor=transparent]Android[backcolor=transparent]必填参数都需要填写,参数的完整性校验之后才会按照参数设置走[backcolor=transparent]iOS[backcolor=transparent]或者[backcolor=transparent]Android[backcolor=transparent]的发送流程。