消息 API
createMessage
Anchor link toPOST https://api.pushwoosh.com/json/1.3/createMessage
创建一个新的推送通知。
请求正文
Anchor link to| 名称 | 类型 | 描述 |
|---|---|---|
| auth* | string | 来自 Pushwoosh 控制面板的 API 访问令牌。 |
| application* | string | Pushwoosh application code |
| notifications* | array | 消息参数的 JSON 数组。详情请参见下方的请求示例。 |
{ "status_code": 200, "status_message": "OK", "response": { "Messages": [ "C3F8-C3863ED4-334AD4F1" ] }}请求示例
Anchor link to{ "request": { "application": "XXXXX-XXXXX", // 必需。Pushwoosh application code。 "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌。 "notifications": [{ "send_date": "now", // 可选。YYYY-MM-DD HH:mm 或 'now' "content": { // 可选。对象或字符串。 "en": "English", // 对于 Windows,请改用 "wns_content"。 "fr": "French" }, "title": { // 可选。对象或字符串。 "en": "Title", // 如果指定了特定平台的标题,则此项将被忽略 "fr": "Titre" // 'ios_title'、'android_header' 等。 }, // 请参见下方的特定平台参数示例。 "subtitle":{ // 可选。对象或字符串。 "en": "Subtitle", // 如果指定了特定平台的标题,则此项将被忽略 "fr": "Sous-titre" // 'ios_subtitle' 等。 }, // 请参见下方的特定平台参数示例。 "ignore_user_timezone": true, // 可选。 "timezone": "America/New_York", // 可选。如果忽略,则 "send_date" 默认为 UTC-0。 // 有关支持的时区,请参见 https://php.net/manual/timezones.php // 。 "campaign": "CAMPAIGN_CODE", // 可选。您希望将此推送消息分配到的 // 营销活动代码。 "geozone": { // 可选。发送到地理区域 "lat": 22.22, "lng": 33.33, "range": 110 }, "rich_media": "XXXXX-XXXXX", // 可选。从 Pushwoosh 控制面板中 // 富媒体编辑器页面的 URL 栏复制富媒体代码。 "link": "https://google.com", // 可选。对于深层链接,请添加 "minimize_link": 0 "minimize_link": 0, // 可选。0 — 不最小化,2 — bitly。默认为 2。 // 请注意,短链接服务有调用次数限制。 // "data": { // 可选。JSON 字符串或 JSON 对象,将作为 "key": "value" // "u" 参数在有效负载中传递(转换为 JSON 字符串)。 }, "transactionId": "unique UUID", // 可选。唯一的消息标识符,用于防止在网络问题 // 情况下出现重复。在 Pushwoosh 端存储 5 分钟。 // "platforms": [ // 可选。1 — iOS;3 — Android;7 — Mac OS X;8 — Windows; 1, 3, 7, 8, 9, 10, // 9 — Amazon;10 — Safari;11 — Chrome; 11, 12, 17 // 12 — Firefox;17 — Huawei ], "preset": "XXXXX-XXXXX", // 可选。来自您控制面板的推送预设代码。 // 如果在请求中发送了特定参数, // 它们将覆盖预设的参数。 "send_rate": 100, // 可选。节流。有效值为 100 到 1000 推送/秒。 "send_rate_avoid": true, // 可选。如果设置为 true,节流限制将不适用于 // 此特定推送通知。 // 模板相关,请参阅模板引擎指南以了解更多信息 "template_bindings": { // 可选。 "TemplatePlaceholder": "Value" }, "dynamic_content_placeholders": { // 可选。用于动态内容的占位符,以替代设备标签。 "firstname": "John", "lastname": "Doe" },
// 频率上限参数。确保在控制面板中配置了全局频率上限。 "capping_days": 30, // 可选。频率上限的天数(最多 30 天) "capping_count": 10, // 可选。在 'capping_days' 周期内, // 可从特定应用发送到特定设备的最大推送数。 // 如果创建的消息超过了设备的 'capping_count' 限制, // 则不会将其发送到该设备。 // "capping_exclude": true, // 可选。如果设置为 true,此推送通知将 // 不计入未来推送的频率上限。 "capping_avoid": true, // 可选。如果设置为 true,频率上限将不适用于 // 此特定推送通知。
// 要通过 API 将消息保存到收件箱,请使用 "inbox_date" 或 "inbox_image"。 // 当至少使用这些参数之一时,消息将被保存。 "inbox_date": "2017-02-02", // 可选。指定何时从收件箱中删除消息。 // 消息将在指定日期的 00:00:01 UTC 从收件箱中删除, // 因此前一天是用户可以在其收件箱中看到消息的最后一天。 // 如果未指定,默认删除日期是发送日期的第二天。 // "inbox_image": "Inbox image URL", // 可选。显示在消息旁的图片。 "inbox_days": 5, // 可选。指定何时从收件箱中删除消息 // (收件箱消息的生命周期,以天为单位)。 // 可替代 "inbox_date" 参数使用。 // 最多 30 天。
"devices": [ // 可选。指定令牌或 hwid 以发送定向推送 "hwid_XXXX" // 通知。数组中不超过 1000 个令牌/hwid。 ], // 如果设置,消息将仅发送到 // 列表中的设备。设备列表不允许使用应用程序组。 // iOS 推送令牌只能是小写。
// 以用户为中心的推送通知 "users": [ // 可选。如果设置,消息将仅传递到 "user_XXXX" // 指定的用户 ID(通过 /registerUser 调用设置)。 ], // 如果与 devices 参数一起指定, // 后者将被忽略。数组中不超过 1000 个用户 ID。 // 用户列表不允许使用应用程序组。
// 过滤器和条件 "filter": "FILTER_NAME", // 可选。 "conditions": [ // 可选。请参见下面的备注。 ["Country", "EQ", "fr"], ["Language", "EQ", "en"] ], "conditions_operator": "AND" // 可选。条件数组的逻辑运算符。 // 可能的值:AND | OR。默认为 AND。 }] }}VoIP 通知请求示例
Anchor link toPushwoosh 支持 iOS 和 Android 的 VoIP 风格通话通知。
您可以在下方找到每个平台的 createMessage API 请求示例。
{ "request": { "application": "XXXXX-XXXXX", // 必需。Pushwoosh application code。 "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌。 "notifications": [ { "voip_push": true, // 必需。发送 VoIP 推送通知需要此参数。 "ios_root_params": { "aps": { "mutable-content": 1 // iOS10+ 媒体附件必需。 }, "callerName": "CallerName", // 可选。来电者姓名。如果未指定,则显示“未知来电者”。 "video": true, // 可选。指示是否支持视频通话。 "supportsHolding": true, // 可选。指示是否支持呼叫保持功能。 "supportsDTMF": false, // 可选。控制双音多频信号支持。 "callId": "42", // 可选。要取消的呼叫的唯一标识符。 "cancelCall": true // 可选。设置为 "true" 以取消具有指定 "callId" 的呼叫。 } } ] }}Android
Anchor link to{ "request": { "application": "XXXXX-XXXXX", // 必需。Pushwoosh application code。 "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌。 "notifications": [ { "voip_push": true, // 必需。发送 VoIP 推送通知需要此参数。 "android_root_params": { "callerName": "callerName", // 可选。来电者姓名。如果未指定,则显示“未知来电者”。 "video": true, // 可选。指示是否支持视频通话。 "callId": 42, // 可选。要取消的呼叫的唯一标识符。 "cancelCall": true // 可选。设置为 "true" 以取消具有指定 "callId" 的呼叫。 } } ] }}特定平台参数
Anchor link toiOS 参数
Anchor link to{ "request": { "application": "12345-67891", // 必需。Pushwoosh application code "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌 "notifications": [{ "ios_title": { // 可选。对象或字符串。为推送通知添加 iOS 特定标题。 "en": "title" }, "ios_subtitle": { // 可选。对象或字符串。为推送通知添加 iOS 特定副标题。 "en": "subtitle" }, "ios_content": { // 可选。对象或字符串。为推送通知添加 iOS 特定内容。 "en": "content" }, "ios_badges": 5, // 可选。iOS 应用程序角标数字。 // 使用 "+n" 或 "-n" 将角标值增加/减少 n。 "ios_sound": "sound file.wav", // 可选。应用程序主包中的声音文件名。 // 如果留空,设备将产生默认系统声音。 "ios_sound_off": true, // 可选。启用/禁用由 "ios_sound" 字段设置的声音。 "ios_ttl": 3600, // 可选。生存时间参数 - 消息最大生命周期(秒)。 "ios_silent": 1, // 可选。启用静默通知(忽略 "sound" 和 "content")。 "ios_category_id": "1", // 可选。来自 Pushwoosh 的 iOS8 类别 ID。 "ios_root_params": { // 可选。aps 字典的根级别参数。 "aps": { "content-available": "0", // 可选。设置为 "1" 发送静默推送,"0" 发送常规推送。 "mutable-content": 1 // iOS10+ 媒体附件必需。 }, "callerName": "CallerName", // 可选 VoIP 参数。来电者姓名。如果未指定,则显示“未知来电者”。 "video": true, // 可选 VoIP 参数。指示是否支持视频通话。 "supportsHolding": true, // 可选 VoIP 参数。指示是否支持呼叫保持功能。 "supportsDTMF": false, // 可选 VoIP 参数。控制双音多频信号支持。 "data": {} // 可选用户提供的数据,最大 4KB }, "ios_attachment": "URL", // 可选。在通知中插入媒体内容。 "ios_thread_id": "some thread id", // 可选。用于对相关通知进行分组的标识符。 // 具有相同线程 ID 的消息将在锁定屏幕和 // 通知中心中分组。 "ios_critical": true, // 可选。将 iOS 通知标记为紧急警报, // 即使设备静音或开启 // “勿扰模式”也会播放声音。 "ios_category_custom": "category", // 可选。自定义 APNS 类别。 "ios_interruption_level": "active", // 可选。 "passive"、"active"、"time-sensitive"、 // "critical" 之一。指示通知的重要性和 // 传递时间。详情请参阅 // 一次性推送指南。 "apns_trim_content": 1 // 可选。(0|1) 用省略号修剪超出的内容字符串。 }] }}Android 参数
Anchor link to{ "request": { "application": "12345-67891", // 必需。Pushwoosh application code "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌 "notifications": [{ "android_header": { // 可选。Android 通知标题。 "en": "header" }, "android_content": { // 可选。Android 通知内容。 "en": "content" }, "android_root_params": { // 可选。自定义键值对象。 "key": "value", // Android 有效负载接收者的根级别参数。 "CancelID": 12345678, // 可选。取消具有指定消息 ID 的推送通知 "voip": true, // 必需的 VoIP 参数。发送 VoIP 推送通知需要此参数。 "callerName": "callerName", // 可选的 VoIP 参数。来电者姓名。如果未指定,则显示“未知来电者”。 "video": true, // 可选的 VoIP 参数。指示是否支持视频通话。 }, // (从消息历史记录中获取 ID) "android_sound": "soundfile", // 可选。无文件扩展名。如果留空, // 设备将产生默认系统声音。 "android_sound_off": true, // 可选。启用/禁用由 "android_sound" 字段设置的声音 "android_icon": "icon.png", // 可选。 "android_custom_icon": "URL.png", // 可选。图像文件的完整 URL。 "android_banner": "URL.png", // 可选。图像文件的完整 URL。 "android_badges": 5, // 可选。Android 应用程序图标角标数字。 // 使用 "+n" 或 "-n" 将角标值增加/减少 n。 "android_gcm_ttl": 3600, // 可选。生存时间参数 — 消息最大生命周期(秒)。 "android_vibration": 0, // 可选。Android 高优先级推送的强制振动。 "android_led": "#rrggbb", // 可选。LED 十六进制颜色,设备将尽力近似。 "android_priority": -1, // 可选。为 Android 8.0 及更高版本的设备设置 "importance" 参数, // 以及为 Android 7.1 及更低版本的设备设置 "priority" 参数。 // 建立通知渠道或特定通知的 // 中断级别。有效值为 -2、-1、0、1、2。 "android_delivery_priority": "normal", // 可选。"normal" 或 "high"。 // 当设备处于省电模式时, // 启用通知的传递。 "android_ibc": "#RRGGBB", // 可选。Lollipop 上的图标背景颜色,#RRGGBB, // #AARRGGBB,"red","black","yellow" 等。 "android_silent": 1, // 可选。0 或 1。启用静默通知。 // 忽略声音和内容 "android_group_id": "123" // 可选。用于对相关通知进行分组的标识符。具有 // 相同线程 ID 的消息将在 // 通知中心中分组。 }] }}华为参数
{ "request": { "application": "12345-67891", // 必需。Pushwoosh application code "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌 "notifications": [{ "huawei_android_header": { // 可选。对象或字符串。通知标题 "en": "header" }, "huawei_android_content": { // 可选。对象或字符串。通知内容 "en": "content" }, "huawei_android_badges": true, // 可选。 "huawei_android_silent": 0, // 可选。0 或 1。启用静默通知。 // 忽略声音和内容 "huawei_android_icon": "URL.png", // 可选。 "huawei_android_led": "#FF0011", // 可选。LED 十六进制颜色,设备将尽力近似 "huawei_android_vibration": 1, // 可选。华为高优先级推送的强制振动 "huawei_android_sound": "sound.wav", // 可选。如果留空,设备将产生 // 默认系统声音 "huawei_android_sound_off": true, // 可选。启用/禁用由 // "huawei_android_sound" 字段设置的声音 "huawei_android_custom_icon": "URL.png", // 可选 "huawei_android_gcm_ttl": 2400, // 可选。生存时间参数 - 消息最大 // 生命周期(秒) "huawei_android_banner": "URL.png", // 可选。图像文件的完整路径 URL "huawei_android_root_params": { // 可选。自定义键值对象。 "key": "value" // 华为有效负载接收者的根级别参数。 }, "huawei_android_priority": 0, // 可选。有效值:-2、-1、0、1、2 "huawei_android_ibc": "#0011AA", // 可选。Lollipop 上的图标背景颜色 "huawei_android_lockscreen": 1, // 可选 "huawei_android_delivery_priority": "normal", // 可选。"normal" 或 "high"。在省电模式下启用 // 通知传递 "huawei_android_group_id": "group_id" // 可选。用于对相关通知进行分组的标识符 }] }}Safari 参数
Anchor link to{ "request": { "application": "12345-67891", // 必需。Pushwoosh application code "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌 "notifications": [{ "safari_url_args": [ // 必需,但值可以为空 "firstArgument", "secondArgument" ], "safari_title": { // 可选。对象或字符串。通知的标题。 "en": "content" }, "safari_content": { // 可选。对象或字符串。通知的内容。 "en": "content" }, "safari_action": "Click here", // 可选。 "safari_ttl": 3600 // 可选。生存时间参数 — 消息的最大 // 生命周期(秒)。 }] }}Chrome 参数
Anchor link to{ "request": { "application": "12345-67891", // 必需。Pushwoosh application code "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌 "notifications": [{ "chrome_title": { // 可选。对象或字符串。您可以在此参数中指定消息的 "en": "title" // 标题。 }, "chrome_content": { // 可选。对象或字符串。您可以在此参数中指定消息的 "en": "content" // 内容。 }, "chrome_icon": "URL.png", // 可选。图标的完整 URL 或扩展资源文件路径 "chrome_gcm_ttl": 3600, // 可选。生存时间参数 – 消息最大生命周期(秒)。 "chrome_duration": 20, // 可选。最大 50 秒。更改 chrome 推送显示时间。 // 设置为 0 以显示推送,直到用户与其交互。 "chrome_image": "image_URL", // 可选。大图的 URL。 "chrome_root_params": { // 可选。设置发送到 Chrome 的消息的特定参数。 "key": "value" }, "chrome_button_text1": "text1", // 可选 "chrome_button_url1": "button1_URL", // 可选。如果未设置 chrome_button_text1,则忽略。 "chrome_button_text2": "text2", // 可选 "chrome_button_url2": "button2_url" // 可选。如果未设置 chrome_button_text2,则忽略。 }] }}Firefox 参数
Anchor link to{ "request": { "application": "12345-67891", // 必需。Pushwoosh application code "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌 "notifications": [{ "firefox_title": { // 可选。对象或字符串。您可以在此处指定消息标题。 "en": "title" }, "firefox_content": { // 可选。对象或字符串。您可以在此处指定消息内容。 "en": "content" }, "firefox_icon": "URL.png", // 可选。图标的完整路径 URL 或 // 扩展资源中文件的路径。 "firefox_root_params": { // 可选。设置发送到 Firefox 的消息的特定参数。 "key": "value" } }] }}Amazon 参数
Anchor link to{ "request": { "application": "12345-67891", // 必需。Pushwoosh application code "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌 "notifications": [{ "adm_header": { // 可选。对象或字符串。您可以在此处指定消息标题。 "en": "header" }, "adm_content": { // 可选。对象或字符串。您可以在此处指定消息内容。 "en": "content" }, "adm_root_params": { // 可选。自定义键值对象 "key": "value" }, "adm_sound": "push.mp3", // 可选。 "adm_sound_off": true, // 可选。启用/禁用由 "adm_sound" 字段设置的声音 "adm_icon": "icon.png", // 可选。图标的完整 URL。 "adm_custom_icon": "URL.png", // 可选。 "adm_banner": "URL.png", // 可选。 "adm_ttl": 3600, // 可选。生存时间参数 — 消息的最大 // 生命周期(秒)。 "adm_priority": -1 // 可选。Amazon 推送抽屉中推送的优先级, // 有效值为 -2、-1、0、1 和 2。 }] }}Mac OS X 参数
Anchor link to{ "request": { "application": "12345-67891", // 必需。Pushwoosh application code "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌 "notifications": [{ "mac_title": { // 可选。对象或字符串。为推送通知添加标题。 "en": "title" }, "mac_subtitle": { // 可选。为推送通知添加副标题。 "en": "subtitle" }, "mac_content": { // 可选。为推送通知添加内容。 "en": "content" }, "mac_badges": 3, // 可选。 "mac_sound": "sound.caf", // 可选。 "mac_sound_off": true, // 可选。启用/禁用由 "mac_sound" 字段设置的声音 "mac_root_params": { // 可选。 "content-available": 1 }, "mac_ttl": 3600 // 可选。生存时间参数 — 消息最大生命周期(秒)。 }] }}Windows 参数
Anchor link to{ "request": { "application": "12345-67891", // 必需。Pushwoosh application code "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌 "notifications": [{ "wns_content": { // 必需。以 MIME 的 base64 编码的通知内容(XML 或原始) // ,形式为对象或字符串 "en": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48YmFkZ2UgdmFsdWU9ImF2YWlsYWJsZSIvPg==", "de": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48YmFkZ2UgdmFsdWU9Im5ld01lc3NhZ2UiLz4=" }, "wns_type": "Badge", // 可选。'Tile' | 'Toast' | 'Badge' | 'Raw' "wns_tag": "myTag", // 可选。用于磁贴替换策略。 // 不超过 16 个字符的字母数字字符串。 "wns_cache": 1, // 可选。(1|0) 转换为 X-WNS-Cache-Policy 值。 "wns_ttl": 600 // 可选。通知的过期时间(秒)。 }] }}响应:
| HTTP 状态码 | status_code | 描述 |
|---|---|---|
| 200 | 200 | 消息创建成功 |
| 200 | 210 | 参数错误。更多信息请参见 status_message |
| 400 | N/A | 请求字符串格式错误 |
| 500 | 500 | 内部错误 |
API 消息跟踪
Anchor link to出于负载均衡的目的,我们不存储通过 API 发送且“devices”参数数组中包含少于 10 个设备的消息。因此,此类消息将不会显示在您的消息历史记录中。
要在测试阶段查看推送报告,请使用 API 消息跟踪。开启此选项ON允许您_在 1 小时内覆盖此限制,并将此类推送保存在消息历史记录中_。API 消息跟踪将在 1 小时后自动关闭OFF。
API 消息跟踪可以在消息历史记录页面通过点击右上角的开始 API 消息跟踪来激活。
标签条件
Anchor link to每个标签条件都是一个类似 [tagName, operator, operand] 的数组,其中
- tagName:标签名称
- operator:“EQ” | “IN” | “NOTEQ” | “NOTIN” | “LTE” | “GTE” | “BETWEEN” | “NOTSET” | “ANY”
- operand:字符串 | 整数 | 数组 | 日期
操作符描述
Anchor link to- EQ:标签值等于操作数;
- IN:标签值与操作数相交(操作数必须始终是数组);
- NOTEQ:标签值不等于操作数;
- NOTIN:标签值不与操作数相交(操作数必须始终是数组);
- GTE:标签值大于或等于操作数;
- LTE:标签值小于或等于操作数;
- BETWEEN:标签值大于或等于最小操作数值但小于或等于最大操作数值(操作数必须始终是数组);
- NOTSET:标签未设置。不考虑操作数;
- ANY:标签具有任何值。不考虑操作数。
字符串标签
Anchor link to有效操作符:EQ, IN, NOTEQ, NOTIN, NOTSET, ANY
有效操作数:
- EQ, NOTEQ:操作数必须是字符串;
- IN, NOTIN:操作数必须是字符串数组,如
["value 1", "value 2", "value N"]; - NOTSET:标签未设置。不考虑操作数;
- ANY:标签具有任何值。不考虑操作数。
整数标签
Anchor link to有效操作符:EQ, IN, NOTEQ, NOTIN, BETWEEN, GTE, LTE, NOTSET, ANY
有效操作数:
- EQ, NOTEQ, GTE, LTE:操作数必须是整数;
- IN, NOTIN:操作数必须是整数数组,如
[value 1, value 2, value N]; - BETWEEN:操作数必须是整数数组,如
[min_value, max_value]; - NOTSET:标签未设置。不考虑操作数;
- ANY:标签具有任何值。不考虑操作数。
日期标签
Anchor link to有效操作符:EQ, IN, NOTEQ, NOTIN, BETWEEN, GTE, LTE, NOTSET, ANY
有效操作数:
"YYYY-MM-DD 00:00"(字符串)- unix 时间戳
1234567890(整数) "N days ago"(字符串) 用于操作符 EQ, BETWEEN, GTE, LTE
布尔标签
Anchor link to有效操作符:EQ, NOTSET, ANY
有效操作数:0, 1, true, false
列表标签
Anchor link to有效操作符:IN, NOTIN, NOTSET, ANY
有效操作数:操作数必须是字符串数组,如 ["value 1", "value 2", "value N"]。
/createMessage 代码片段
Anchor link to/createMessage 请求示例:
#!/bin/bash
#Usageif [ ! -n "$1" ] || [ ! -n "$2" ]then echo "`basename $0` usage: api_token appid message"; exit 1;fi;MESSAGE="$3";if [ -z "$3" ]thenMESSAGE='One push to rule them all!'fi;
echo -e "Response:"curl --data-binary "{\"request\": {\"application\":\"$2\", \"auth\":\"$1\", \"notifications\": [{ \"send_date\": \"now\", \"content\": \"$MESSAGE\" }] }}" \-H "Content-type: application/json" \"https://api.pushwoosh.com/json/1.3/createMessage"echo "";exit 0;<?phpdefine('PW_AUTH', 'API TOKEN');define('PW_APPLICATION', 'APPLICATION CODE');define('PW_DEBUG', true);
function pwCall($method, $data) { $url = 'https://api.pushwoosh.com/json/1.3/' . $method; $request = json_encode(['request' => $data]);
$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch);
if (defined('PW_DEBUG') && PW_DEBUG) { print "[PW] request: $request"; print "[PW] response: $response"; print '[PW] info: ' . print_r($info, true); }}
pwCall('createMessage', array( 'application' => PW_APPLICATION, 'auth' => PW_AUTH, 'notifications' => array( array( 'send_date' => 'now', 'content' => 'test', 'data' => array('custom' => 'json data'), 'link' => 'https://pushwoosh.com/' ) ) ));-module(pushwoosh).-export([run/0, stop/0, sendMessage/1]).%% sendMessage argument: message text %%
%% Authentication & App_id %%-define(PW_AUTH, "YOUR_AUTH_TOKEN").-define(PW_APPLICATION, "YOUR_PUSHWOOSH_APP_CODE").
%% KickStart %%run() -> application:start(unicode), application:start(crypto), application:start(public_key), application:start(ssl), application:start(inets), %% HTTP Client verbosity options flase, verbose, debug httpc:set_options([{verbose, false}]).stop() -> application:stop(ssl), application:stop(public_key), application:stop(crypto), application:stop(inets).%% JSON Wars !encode(S) -> encode(S, [$"]).encode([], Acc) -> lists:reverse([$" | Acc]);encode([C | Cs], Acc) -> Hex = lists:flatten(io_lib:format("~4.16.0b", [C])), encode(Cs, lists:reverse(Hex) ++ "u\" ++ Acc).
sendMessage(Message_text) -> %% URL to JSON API 1.3 Url = "https://api.pushwoosh.com/json/1.3/createMessage", EncodedMessage = encode(Message_text), {ok, Response} = httpc:request( %%Method post, %%Request {Url, [{"User-Agent", "Erlang exemple"}], "application/json; charset=UTF-8", "{\"request\":{ \"application\": \""?PW_APPLICATION"\", \"auth\": \""?PW_AUTH"\", \"notifications\": [{ \"send_date\": \"now\", \"content\": "++EncodedMessage++" }]}}"}, %%HTTP options [{ssl,[{verify, verify_none}]}, {version, "HTTP/1.0"}], %%Options []), io:format("And received ~p", [Response]).class PushNotification
#- PushWoosh API Documentation https://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/ #- Two methods here: # - PushNotification.new.notify_all(message) Notifies all with the same option # - PushNotification.new.notify_devices(notification_options = {}) Notifies specific devices with custom options
include HTTParty #Make sure to have the HTTParty gem declared in your gemfile https://github.com/jnunemaker/httparty default_params :output => 'json' format :json
def initialize #- Change to your settings @auth = {:application => "00000-00000",:auth => "auth_token"} end
# PushNotification.new.notify_all("This is a test notification to all devices") def notify_all(message) notify_devices({:content => message}) end
# PushNotification.new.notify_device({ # :content => "TEST", # :data => {:custom_data => value}, # :devices => array_of_tokens #}) def notify_devices(notification_options = {}) #- Default options, uncomment :data or :devices if needed default_notification_options = { # YYYY-MM-DD HH:mm OR 'now' :send_date => "now", # Object( language1: 'content1', language2: 'content2' ) OR string :content => { :fr => "Test", :en => "Test" }, # JSON string or JSON object "custom": "json data" #:data => { # :custom_data => value #}, # omit this field (push notification will be delivered to all the devices for the application), or provide the list of devices IDs #:devices => {} }
#- Merging with specific options final_notification_options = default_notification_options.merge(notification_options)
#- Constructing the final call options = @auth.merge({:notifications => [final_notification_options]}) options = {:request => options} #- Executing the POST API Call with HTTPARTY - :body => options.to_json allows us to send the json as an object instead of a string response = self.class.post("https://api.pushwoosh.com/json/1.3/createMessage", :body => options.to_json,:headers => { 'Content-Type' => 'application/json' }) endend// Uses JSON classes from https://json.org/java/
package com.arellomobile;
import org.json.*;import java.io.*;import java.net.*;
public class SendPushNotificationSample{ public static final String PUSHWOOSH_SERVICE_BASE_URL = "https://api.pushwoosh.com/json/1.3/"; private static final String AUTH_TOKEN = "YOUR_AUTH_TOKEN"; private static final String APPLICATION_CODE = "PW_APPLICATION_CODE";
public static void main(String[] args) throws JSONException, MalformedURLException { String method = "createMessage"; URL url = new URL(PUSHWOOSH_SERVICE_BASE_URL + method);
JSONArray notificationsArray = new JSONArray() .put(new JSONObject().put("send_date", "now") .put("content", "test") .put("link", "https://pushwoosh.com/"));
JSONObject requestObject = new JSONObject() .put("application", APPLICATION_CODE) .put("auth", AUTH_TOKEN) .put("notifications", notificationsArray);
JSONObject mainRequest = new JSONObject().put("request", requestObject); JSONObject response = SendServerRequest.sendJSONRequest(url, mainRequest.toString());
System.out.println("Response is: " + response); }}
class SendServerRequest{ static JSONObject sendJSONRequest(URL url, String request) { HttpURLConnection connection = null; try { connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setDoInput(true); connection.setDoOutput(true);
DataOutputStream writer = new DataOutputStream(connection.getOutputStream()); writer.write(request.getBytes("UTF-8")); writer.flush(); writer.close();
return parseResponse(connection); } catch (Exception e) { System.out.println("An error occurred: " + e.getMessage()); return null; } finally { if (connection != null) { connection.disconnect(); } } }
static JSONObject parseResponse(HttpURLConnection connection) throws IOException, JSONException { String line; BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder response = new StringBuilder();
while ((line = reader.readLine()) != null) { response.append(line).append(''); } reader.close();
return new JSONObject(response.toString()); }}import json
PW_AUTH = 'API TOKEN'PW_APPLICATION_CODE = 'APPLICATION CODE'
try: # For Python 3.0 and later from urllib.request import urlopen from urllib.request import Requestexcept ImportError: # Fall back to Python 2's urllib2 from urllib2 import urlopen from urllib2 import Request
def pw_call(method, data): url = 'https://api.pushwoosh.com/json/1.3/' + method data = json.dumps({'request': data}) req = Request(url, data.encode('UTF-8'), {'Content-Type': 'application/json'}) try: f = urlopen(req) response = f.read() f.close() print('Pushwoosh response: ' + str(response)) except Exception as e: print ('Request error: ' + str(e))
if __name__ == '__main__': pw_call('createMessage', { 'auth': PW_AUTH, 'application': PW_APPLICATION_CODE, 'notifications': [ { 'send_date': 'now', 'content': 'test', 'data': {"custom": "json data"}, 'link': 'https://pushwoosh.com' } ] } )using System;using System.IO;using System.Net;using Newtonsoft.Json.Linq;
namespace WebApplication1{ public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string pwAuth = "YOUR_AUTH_TOKEN"; string pwApplication = "PW_APPLICATION_CODE"; JObject json = new JObject( new JProperty("application", pwApplication), new JProperty("auth", pwAuth), new JProperty("notifications", new JArray( new JObject( new JProperty("send_date", "now"), new JProperty("content", "test"), new JProperty("wp_type", "Toast"), new JProperty("wp_count", 3), new JProperty("data", new JObject( new JProperty("custom", "json data"))), new JProperty("link", "https://pushwoosh.com/"), new JProperty("conditions", new JArray( (object)new JArray("Color", "EQ", "black"))))))); PWCall("createMessage", json); } private void PWCall(string action, JObject data) { Uri url = new Uri("https://api.pushwoosh.com/json/1.3/" + action); JObject json = new JObject(new JProperty("request", data)); DoPostRequest(url, json); } private void DoPostRequest(Uri url, JObject data) { HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); req.ContentType = "text/json"; req.Method = "POST"; using (var streamWriter = new StreamWriter(req.GetRequestStream())) { streamWriter.Write(data.ToString()); } HttpWebResponse httpResponse; try { httpResponse = (HttpWebResponse)req.GetResponse(); } catch (Exception exc) { throw new Exception(string.Format("Problem with {0}, {1}", url, exc.Message)); } using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var responseText = streamReader.ReadToEnd(); Page.Response.Write(responseText); } } }}package main
import( "fmt" "encoding/json" "net/http" "bytes" "io/ioutil")
const ( PW_APPLICATION = "APPLICATION CODE" PW_AUTH = "API TOKEN" PW_ENDPOINT = "https://api.pushwoosh.com/json/1.3/")
func pwCall(method string, data []byte) (bool) { url := PW_ENDPOINT + method request, err := http.NewRequest("POST", url, bytes.NewBuffer(data)) request.Header.Set("Content-Type", "application/json")
client := http.Client{} response, err := client.Do(request) if err != nil { fmt.Println("Error occur: " + err.Error()) return false } defer response.Body.Close()
fmt.Println("Response Status: ", response.Status) if (response.StatusCode == 200) { body, _ := ioutil.ReadAll(response.Body) fmt.Println("Response Body: ", string(body)) return true } return false}
func main() { requestData := map[string]interface{}{ "request": map[string]interface{} { "auth": PW_AUTH, "application": PW_APPLICATION, "notifications": []interface{}{ map[string]interface{} { "send_date": "now", "content": "test", "link": "https://pushwoosh.com", }, }, }, } jsonRequest, _ := json.Marshal(requestData) requestString := string(jsonRequest) fmt.Println("Request body: " + requestString)
pwCall("createMessage", jsonRequest)}$.ajax({ type: "POST", url: "https://api.pushwoosh.com/json/1.3/createMessage", data: JSON.stringify({ "request": { "application": "APPLICATION CODE", "auth": "API TOKEN", "notifications": [{ "send_date": "now", "ignore_user_timezone": true, "content": "Hello world!" }] } }), dataType: "json"}).done(function(data) { console.log(data);});deleteMessage
Anchor link toPOST https://api.pushwoosh.com/json/1.3/deleteMessage
删除一个预定的消息。
请求正文
Anchor link to| 名称 | 类型 | 描述 |
|---|---|---|
| auth* | string | 来自 Pushwoosh 控制面板的 API 访问令牌。 |
| message* | string | 在 /createMessage 请求中获得的 消息代码。 |
{ "status_code": 200, "status_message": "OK"}{ "request":{ "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌 "message": "xxxx-xxxxxxx-xxxxxx" // 必需。在 /createMessage 中获得的消息代码 }}状态码:
| HTTP 状态码 | status_code | 描述 |
|---|---|---|
| 200 | 200 | 消息删除成功 |
| 200 | 210 | 参数错误。更多信息请参见 status_message |
| 400 | N/A | 请求字符串格式错误 |
| 500 | 500 | 内部错误 |
<?php// see https://gomoob.github.io/php-pushwoosh/delete-message.htmluse Gomoob\Pushwoosh\Model\Request\DeleteMessageRequest;
// creates request instance$request = DeleteMessageRequest::create()->setMessage('MESSAGE_CODE');
// call '/deleteMessage' Web Service$response = $pushwoosh->deleteMessage($request);
if($response->isOk()) { print 'Great, my message has been deleted !';} else { print 'Oups, the deletion failed :-('; print 'Status code : ' . $response->getStatusCode(); print 'Status message : ' . $response->getStatusMessage();}getMessageDetails
Anchor link toPOST https://api.pushwoosh.com/json/1.3/getMessageDetails
检索消息详情。
请求正文
Anchor link to| 名称 | 类型 | 描述 |
|---|---|---|
| auth* | string | 来自 Pushwoosh 控制面板的 API 访问令牌。 |
| message* | string | 消息代码 或消息 ID。 |
{ "status_code": 200, "status_message": "OK", "response": { "message": { "id": 2068991743, "created": "2016-09-14 17:19:42", "send_date": "2016-09-14 17:19:41", "status": "done", "content": { "en": "Hello {Name|CapitalizeFirst|friend}! 🚀" }, "platforms": "[1]", "ignore_user_timezone": "1", "code": "XXXX-92B4C3C5-A7F5EF70", "data": { "key": "value" } } }}{ "request":{ "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌 "message": "xxxx-xxxxxxx-xxxxxx" // 必需。消息代码或消息 ID }}createTargetedMessage
Anchor link toPOST https://api.pushwoosh.com/json/1.3/createTargetedMessage
创建一个新的定向推送通知。
请求正文
Anchor link to| 名称 | 类型 | 描述 |
|---|---|---|
| auth* | string | 来自 Pushwoosh 控制面板的 API 访问令牌。 |
| devices_filter* | string | 见下文备注。 |
| send_date* | string | YYYY-MM-DD HH:mm 或 ‘now’。 |
| ignore_user_timezone | boolean | 如果忽略,“send_date” 默认为 UTC-0。 |
| timezone | string | 如果忽略,“send_date” 默认为 UTC-0。 |
| campaign | string | 您希望将此推送消息分配到的营销活动代码。 |
| content* | string | 通知内容。详情请参见请求示例。 |
| transactionId | string | 唯一的消息标识符,用于防止在网络问题情况下出现重复消息。在 Pushwoosh 端存储 5 分钟。 |
| link | string | 用户打开推送消息后要打开的链接。 |
| minimize_link | integer | 0 - 不最小化,2 - bit.ly。默认为 2。 |
| data | object | JSON 字符串或 JSON 对象。将作为 “u” 参数在有效负载中传递(转换为 JSON 字符串)。 |
| preset | string | 预设代码。 |
| send_rate | integer | 节流。有效值为每秒 100 到 1000 次推送。 |
| inbox_date | string | 指定何时从收件箱中删除消息。 |
| inbox_image | string | 在收件箱中消息旁边显示的图像 URL。 |
{ "status_code": 200, "status_message": "OK", "response": { "messageCode": "97B0-C7473871-2FBDFDC6" }}由于语法错误,无法完成请求。更多响应示例:
{ "status_code": 210, "status_message": "Errors occurred while compiling filter", "response": { "errors": [{ "message": "Invalid tag set specification. \")\" expected.", "type": "syntax" }] }}{ "status_code": 210, "status_message": "Errors occurred while compiling filter", "response": { "errors": [{ "message": "Application \"11111-11111\" not found", "type": "semantic", "near": "\"11111-11111\"" }] }}{ "status_code": 210, "status_message": "Errors occurred while compiling filter", "response": { "errors": [{ "message": "Invalid character \"/\" at 1:19", "type": "lexical" }] }}{ "request": { "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌 "devices_filter": "A(\"XXXXX-XXXXX\") * T(\"City\", EQ, \"Name\")", // 必需。语法解释如下 "send_date": "now", // 可选。YYYY-MM-DD HH:mm 或 'now' "ignore_user_timezone": true, // 可选。 "timezone": "America/New_York", // 可选。如果忽略,"send_date" 默认为 UTC-0。 // 更多信息 https://php.net/manual/timezones.php。 "campaign": "CAMPAIGN_CODE", // 可选。您希望将此推送消息分配到的营销活动代码。 "content": { // 可选。对象或字符串。对于 Windows,请改用 "wns_content"。 "en": "English", "de": "Deutsch" }, "transactionId": "unique UUID", // 可选。唯一的消息标识符,用于防止在网络问题 // 情况下出现重复消息。在 Pushwoosh 端存储 // 5 分钟。 "rich_media": "XXXXX-XXXXX", // 可选。从 Pushwoosh 控制面板的 // 富媒体编辑器页面的 URL 栏复制富媒体代码。 "link": "https://google.com", // 可选。对于深层链接,请添加 "minimize_link": 0 "minimize_link": 0, // 可选。0 — 不最小化,2 — bitly。默认为 2。 // Google URL 缩短服务自 2019 年 3 月 30 日起已停用。 // 请注意,短链接服务有调用次数限制。 // "data": { // 可选。JSON 字符串或 JSON 对象。 "key": "value" // 将作为 "u" 参数在有效负载中传递 }, // (转换为 JSON 字符串)。 "preset": "XXXXX-XXXXX", // 可选。来自您控制面板的推送预设代码。 "send_rate": 100, // 可选。节流。有效值为每秒 100 到 1000 次推送。 "dynamic_content_placeholders": { // 可选。用于动态内容的占位符,以替代设备标签。 "firstname": "John", "lastname": "Doe" },
// 要通过 API 将消息保存到收件箱,请使用 "inbox_date" 或 "inbox_image"。 // 当至少使用这些参数之一时,消息将被保存。 "inbox_image": "Inbox image URL", // 可选。显示在消息旁的图片。 "inbox_date": "2017-02-02" // 可选。指定何时从收件箱中删除消息。 // 消息将在指定日期的 00:00:01 UTC 从收件箱中删除, // 因此前一天是用户可以在其收件箱中看到消息的最后 // 一天。 // 如果未指定,默认删除日期是发送日期的 // 第二天。 }}{ "request": { "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌 "devices_filter": "FILTER CONDITION", "send_date": "now", // 可选。YYYY-MM-DD HH:mm 或 'now' "content": { // 可选。对象或字符串。 "en": "English", // 对于 Windows,请改用 "wns_content"。 "de": "Deutsch" }, "ignore_user_timezone": true, // 可选。 "timezone": "America/New_York", // 可选。如果忽略,"send_date" 默认为 UTC-0。 // 更多信息 https://php.net/manual/timezones.php。 "campaign": "CAMPAIGN_CODE", // 可选。您希望将此推送消息分配到的营销活动代码。
// iOS 相关参数 "ios_badges": 5, // 可选。iOS 应用程序角标数字。 // 使用 "+n" 或 "-n" 将角标值增加/减少 n。 "ios_sound": "sound file.wav", // 可选。应用程序主包中的声音文件名。 // 如果留空,设备在收到推送时 // 不会产生声音。 "ios_sound_off": true, // 可选。启用/禁用由 "ios_sound" 字段设置的声音。 "ios_ttl": 3600, // 可选。生存时间参数 — 消息最大生命周期(秒)。 "ios_silent": 1, // 可选。启用静默通知(忽略 "sound" 和 "content")。 "ios_category_id": "1", // 可选。来自 Pushwoosh 的 iOS8 类别 ID。 "ios_category_custom": "category", // 可选。自定义 APNS 类别。 "ios_root_params": { // 可选。aps 字典的根级别参数。 "aps": { "content-available": "0", // 可选。设置为 "1" 发送静默推送,"0" 发送常规推送。 "mutable-content": 1 // iOS10+ 媒体附件必需。 }, "attachment": "YOUR_ATTACHMENT_URL", // iOS10+ 媒体附件 URL。 "data": {} // 可选。用户提供的数据,最大 4KB }, "apns_trim_content": 1, // 可选。(0|1) 用省略号修剪超出的内容字符串。 "ios_title": { // 可选。为 iOS 推送通知添加标题。 "en": "title" }, "ios_subtitle": { // 可选。为 iOS 推送通知添加副标题。 "en": "subTitle" }, "ios_content": { // 可选。为 iOS 推送通知添加内容。 "en": "content" },
// Android 相关参数 "android_root_params": { // 可选。自定义键值对象。 "key": "value" // Android 有效负载接收者的根级别参数。 }, "android_sound": "soundfile", // 可选。无文件扩展名。如果留空,设备 // 在收到推送时不会产生声音。 "android_sound_off": true, // 可选。启用/禁用由 "android_sound" 字段设置的声音 "android_header": { // 可选。对象或字符串。Android 通知标题。 "en": "header" }, "android_content": { // 可选。对象或字符串。Android 通知内容。 "en": "content" }, "android_icon": "icon.png", "android_custom_icon": "URL.png", // 可选。图像文件的完整路径 URL。 "android_banner": "URL.png", // 可选。图像文件的完整路径 URL。 "android_badges": 5, // 可选。整数。Android 应用程序图标角标数字。 // 使用 "+n" 或 "-n" 将角标值增加/减少 n。 "android_gcm_ttl": 3600, // 可选。生存时间参数 — 消息最大生命周期(秒)。 "android_vibration": 0, // 可选。Android 高优先级推送的强制振动。 "android_led": "#rrggbb", // 可选。LED 十六进制颜色,设备将尽力近似。 "android_priority": -1, // 可选。为 Android 8.0 及更高版本的设备设置 "importance" 参数, // 以及为 Android 7.1 及更低版本的设备设置 "priority" 参数。 // 建立通知渠道或特定通知的中断 // 级别。 // 有效值为 -2、-1、0、1、2。 "android_delivery_priority": "normal", // 可选。"normal" 或 "high"。当设备处于省电模式时, // 启用通知的传递。 "android_ibc": "#RRGGBB", // 可选。Lollipop 上的图标背景颜色,#RRGGBB, // #AARRGGBB,"red","black","yellow" 等。 "android_silent": 1, // 可选。0 或 1。启用静默通知。 // 忽略声音和内容
// Amazon 相关参数 "adm_root_params": { // 可选。自定义键值对象 "key": "value" }, "adm_sound": "push.mp3", "adm_sound_off": true, // 可选。启用/禁用由 "adm_sound" 字段设置的声音 "adm_header": { "en": "Header" }, "adm_content": { "en": "content" }, "adm_icon": "icon.png", "adm_custom_icon": "URL.png", "adm_banner": "URL.png", "adm_ttl": 3600, // 可选。生存时间参数 — 消息最大 // 生命周期(秒)。 "adm_priority": -1, // 可选。Amazon 推送抽屉中推送的优先级, // 有效值为 -2、-1、0、1 和 2。
// Mac OS X 相关参数 "mac_badges": 3, "mac_sound": "sound.caf", "mac_sound_off": true, "mac_root_params": { "content-available": 1 }, "mac_ttl": 3600, // 可选。生存时间参数 — 消息最大生命周期(秒)。 "mac_title": { // 可选。为推送通知添加标题。 "en": "title" }, "mac_subtitle": { // 可选。为 MacOS 推送通知添加副标题。 "en": "subtitle" }, "mac_content": { // 可选。为 MacOS 推送通知添加内容。 "en": "content" },
// Windows 相关参数 "wns_content": { // 必需。以 MIME 的 base64 编码的通知内容(XML 或原始) // ,形式为对象或字符串 "en": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48YmFkZ2UgdmFsdWU9ImF2YWlsYWJsZSIvPg==", "de": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48YmFkZ2UgdmFsdWU9Im5ld01lc3NhZ2UiLz4=" }, "wns_type": "Badge", // 'Tile' | 'Toast' | 'Badge' | 'Raw' "wns_tag": "myTag", // 可选。用于磁贴替换策略。 // 不超过 16 个字符的字母数字字符串。 "wns_cache": 1, // 可选。(1|0) 转换为 X-WNS-Cache-Policy 值。 "wns_ttl": 600, // 可选。通知的过期时间(秒)。
// Safari 相关参数 "safari_title": { // 可选。对象或字符串。通知的标题。 "en": "title" }, "safari_content": { // 可选。对象或字符串。通知的内容。 "en": "content" }, "safari_action": "Click here", // 可选。 "safari_url_args": [ // 必需,但值可以为空 "firstArgument", "secondArgument" ], "safari_ttl": 3600, // 可选。生存时间参数 — 消息的最大 // 生命周期(秒)。
// Chrome 相关参数 "chrome_title": { // 可选。您可以在此参数中指定消息的标题。 "en": "title" }, "chrome_content": { // 可选。您可以在此参数中指定消息的内容。 "en": "content" }, "chrome_icon": "icon_URL", // 可选。图标的完整路径 URL 或扩展资源文件路径 "chrome_gcm_ttl": 3600, // 可选。生存时间参数 – 消息最大生命周期(秒)。 "chrome_duration": 20, // 可选。更改 chrome 推送显示时间。设置为 0 以显示推送 // 直到用户与其交互。 "chrome_image": "image_URL", // 可选。大图的 URL "chrome_root_params": { // 可选。设置发送到 Chrome 的消息的特定参数。 "key": "value" }, "chrome_button_text1": "text1", // 可选。 "chrome_button_url1": "button1_URL", // 可选。如果未设置 chrome_button_text1,则忽略。 "chrome_button_text2": "text2", // 可选。 "chrome_button_url2": "button2_url", // 可选。如果未设置 chrome_button_text2,则忽略。
// Firefox 相关参数 "firefox_title": { // 可选。对象或字符串。您可以在此处指定消息标题。 "en": "title" }, "firefox_content": { // 可选。对象或字符串。您可以在此处指定消息内容。 "en": "content" }, "firefox_icon": "icon_URL", // 可选。图标的完整路径 URL 或 // 扩展资源中文件的路径。 "firefox_root_params": { // 可选。设置发送到 Firefox 的消息的特定参数。 "key": "value" } }}基本原理非常简单——所有过滤都在实体的集合上执行。
集合定义为:
1. 订阅特定应用 (A) 的设备;
2. 匹配指定标签值 (T) 或特定应用标签值 (AT) 的设备;\
让我们根据上面的列表尝试一些示例。
定向应用订阅者
Anchor link to“A” 过滤器定义了订阅特定应用的设备集合:
A("XXXXX-XXXXX", ["iOS", "Android", "OsX", "Windows", "Amazon", "Safari", "Chrome", "Firefox"])
其中
- “XXXXX-XXXXX” – Pushwoosh Application Code
- [“iOS”, “Android”, …] – 目标平台数组。如果省略,消息将发送到此应用可用的所有平台。
按标签值过滤
Anchor link to“T” 过滤器定义了分配了指定标签值的设备集合。
T(\"Age\", IN, [17,20])
定义了“age”标签设置为 17、18、19、20 之一的设备集合。
标签类型和操作符
Anchor link to理解标签在应用之间共享非常重要,它为细分和过滤目标用户提供了非常强大的工具,而无需将自己绑定到特定应用。
标签可以是三种不同类型之一:字符串、整数、列表。标签类型定义了您可以对特定标签使用的操作符。
字符串标签
Anchor link to适用操作符:
- EQ – 定向具有指定标签值的设备
- IN – 定向具有任何指定标签值的设备
- NOTIN – 定向没有指定标签值的设备
- NOTEQ – 定向标签值不等于指定值的设备
- NOTSET – 定向未指定标签值的设备
- ANY – 定向为指定标签设置了任何值的设备
示例:
T (\"Age\", EQ, 30) – 过滤年龄为 30 岁的用户
T (\"favorite_color\", IN, [\"red\",\"green\",\"blue\"]) – 过滤选择红色、绿色或蓝色作为他们最喜欢颜色的用户。
T (\"Name", NOTSET, \"\") – 定向没有 Name 标签值的设备。
您可以对字符串标签使用数值,但这些值将被转换为字符串。
整数标签
Anchor link to适用操作符:
- GTE – 大于或等于指定值
- LTE– 小于或等于指定值
- EQ – 等于指定值
- BETWEEN – 介于指定的最小值和最大值之间
- IN – 任何指定值
- NOTIN – 没有分配给设备的指定值
- NOTEQ – 标签值不等于指定值的设备
- NOTSET – 没有为指定标签设置值的设备
- ANY – 为指定标签设置了任何值的设备
示例:
T (\"Level\", EQ, 14) – 仅过滤 14 级的用户。
T (\"Level\", BETWEEN, [1,5) – 过滤 1、2、3、4 和 5 级的用户。
T (\"Level", GTE, 29) – 定向至少达到 29 级的用户。
列表标签
Anchor link to适用操作符:
- IN – 具有任何指定标签值的设备
示例:T("Category", IN, ["breaking_news","business","politics"])
日期标签
Anchor link to适用操作符:
- GTE – 大于或等于指定值
- LTE– 小于或等于指定值
- EQ – 等于指定值
- BETWEEN – 介于指定的最小值和最大值之间
- NOTEQ – 标签值不等于指定值的设备
- NOTSET – 没有为指定标签设置值的设备
- ANY – 为指定标签设置了任何值的设备
示例:
AT("7777D-322A7","Last Application Open", BETWEEN, ["2022-02-28", "2022-03-02"])
AT("7777D-322A7","Last Application Open", GTE, "90 days ago")
- “+” – 连接两个集合(等于 OR)
- “*” – 两个集合的交集(等于 AND)
- “\” – 从一个集合中减去另一个集合(等于 NOT)
所有操作都是左结合的。“+”和“*”具有相同的优先级。“\”具有更高的优先级。您可以使用括号来定义计算的优先级。
请注意,“\”操作不是可交换的。A("12345-12345") \ A("67890-67890") 与 A("67890-67890") \ A("12345-12345") 不同。
getPushHistory
Anchor link toPOST https://api.pushwoosh.com/json/1.3/getPushHistory
获取包含推送详情的消息历史记录。
请求正文
Anchor link to| 名称 | 类型 | 描述 |
|---|---|---|
| auth* | string | 来自 Pushwoosh 控制面板的 API 访问令牌。 |
| limitMessages | integer | 限制响应中的消息数量。可能的值从 10 到 1000。 |
| source | string | 推送历史来源。可以为 null 或:“CP”, “API”, “GeoZone”, “RSS”, “AutoPush”, “A/B Test”。 |
| searchBy | string | 可能的搜索依据值。可以为 null 或:“notificationID”, “notificationCode”, “applicationCode”, “campaignCode”。 |
| value | string | 根据 “searchBy” 字段设置的搜索值。 |
| lastNotificationID | string | 用于分页。上一次 /getPushHistory 调用的最后一个 messageId。详情见下文。 |
{ "status_code": 200, "status_message": "OK", "response": { "rows": [{ "id": 10191611434, "code": "8071-07AD1171-77238AD1", "createDate": "2020-09-14 12:26:21", "sendDate": "2020-09-14 12:26:21", "content": { "en": "Hello!" }, "url": null, "ios_title": null, "ios_subtitle": null, "ios_root_params": null, "android_header": null, "android_root_params": null, "conditions": null, "conditions_operator": "AND", "filter_code": "E3A64-A5F3C", "filter_conditions": "#In-app Purchase(≠0)", "filter_name": "Purchased something", "geozone": null, "campaignId": "", "campaignName": "", "subscription_segments": null, "open": { "C90C0-0E786": { "IOS": 0 } }, "sent": { "C90C0-0E786": { "IOS": 1 } }, "ctr": { "C90C0-0E786": 0 } }, { "id": 10191609202, "code": "41CA-83F8E0D7-7A63822B", "createDate": "2020-09-14 12:25:55", "sendDate": "2020-09-14 12:25:55", "content": { "en": "Hi!" }, "url": null, "ios_title": null, "ios_subtitle": null, "ios_root_params": null, "android_header": null, "android_root_params": null, "conditions": null, "conditions_operator": "AND", "filter_code": null, "filter_conditions": null, "filter_name": null, "geozone": null, "campaignId": "", "campaignName": "", "subscription_segments": { "2D732-BB981": "News" }, "open": { "C90C0-0E786": { "CHROME": 0, "IOS": 0 } }, "sent": { "C90C0-0E786": { "CHROME": 1, "IOS": 2 } }, "ctr": { "C90C0-0E786": 0 } }] }}{ "request":{ "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌 "source": null, // 可选。可能的值为 null, "CP", "API", "GeoZone", // "RSS", "AutoPush", "A/B Test" "searchBy": "applicationCode", // 可选。可能的值为 "", "notificationID", // "notificationCode", "applicationCode", "campaignCode" "value": "C8717-703F2", // 可选。根据 "searchBy" 字段设置的搜索值。 "lastNotificationID": 0, // 可选。用于分页。上一次 /getPushHistory // 调用的最后一个 messageId。详情见下文。 "limitMessages": 1000 // 可选。可能的值从 10 到 1000。 }}此方法将返回账户中按消息 ID 排序的 1000 条消息。要获取第二页,请在 lastNotificationId 参数中指定上一次响应的最后一条消息 ID。
响应数据类型
Anchor link toid -- int | 0code -- stringcreateDate -- string (date: %Y-%m-%d %H:%M:%S)sendDate -- string (date: %Y-%m-%d %H:%M:%S)content -- array ( dict {lang: value} | list [])title -- array ( dict {lang: value} | list [])subtitle -- array ( dict {lang: value} | list [])url -- stringios_title -- string | array ( dict {lang: value} ) | nullios_subtitle -- string | array ( dict {lang: value} ) | nullios_root_params -- dict (JSON) | nullandroid_header -- string | array ( dict {lang: value} ) | nullandroid_root_params -- dict (JSON) | nullconditions -- list (JSON) | nullconditions_operator -- string | nullfilter_code -- string | nullfilter_name -- string | nullfilter_conditions -- string | nullgeozone -- string | nullcampaignId -- string | ""campaignName -- string | ""subscription_segments (obsolete) -- list (JSON) | nulldata -- dict (JSON) | nullopen -- dict [dict [string: int]] | "" 示例: 'open': {'AAAAA-BBBBB': {'IOS': 1, 'ANDROID': 1}}sent -- dict [dict [string: int]] | "" 示例: 'sent': {'AAAAA-BBBBB': {'IOS': 10, 'ANDROID': 10}}ctr -- dict [string: int] | "" 示例: {'AAAAA-BBBBB': 1}errors -- dict [string: int] | "" 示例: {'ANDROID': 1, 'IOS': 1}cancelMessage
Anchor link toPOST https://api.pushwoosh.com/json/1.3/cancelMessage
删除一个预定的消息。
请求正文
Anchor link to| 名称 | 类型 | 描述 |
|---|---|---|
| auth* | string | 来自 Pushwoosh 控制面板的 API 访问令牌。 |
| message* | string | 在 /createMessage 响应中获得的消息代码。 |
{ "status_code":200, "status_message":"OK"}{ "request":{ "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh 控制面板的 API 访问令牌 "message": "xxxx-xxxxxxx-xxxxxx" // 必需。在 /createMessage 响应中获得的消息代码 }}状态码:
| HTTP 状态码 | status_code | 描述 |
|---|---|---|
| 200 | 200 | 消息取消成功 |
| 200 | 210 | 参数错误。更多信息请参见 status_message。 |
| 400 | N/A | 请求字符串格式错误 |
| 500 | 500 | 内部错误 |