场景介绍

场景介绍 场景说明 API文档
IOS推送通知(简单功能) 对应推送控制台简单功能。只能设置通知内容,推送目标等参数。详情见API文档入参介绍。 taobao.cloudpush.notice.ios (推送通知给ios设备)
Android 推送通知(简单功能) 对应推送控制台简单功能。只能输入通知内容,推送目标等参数。详情见API文档入参介绍。 taobao.cloudpush.notice.android (百川云推送发送通知给android)
IOS推送消息(简单功能) 对应推送控制台简单功能。只能设置消息内容,推送目标等参数。详情见API文档入参介绍。 taobao.cloudpush.message.ios (百川云推送发送消息给ios)
Android推送消息(简单功能) 对应推送控制台简单功能。只能设置消息内容,推送目标等参数。详情见API文档入参介绍。 taobao.cloudpush.message.android (百川云推送发送消息给android)
Android IOS 推送消息通知 高级接口      对应控制台高级设置。有参数可以控制 推送设备IOS\Android,推送消息\通知,设置防打扰时间,是否保存离线消息。IOS还可以控制 通知传递更多的自定义参数,通知的声音,app不在线时,是否通apns补发通知。Android还可以控制,点击通知后打开的动作,通知传递更多的自定义参数,通知的声音 taobao.cloudpush.push (百川用户使用云推送高级推送接口)

服务端集成准备步骤

1.1 下载 Open API SDK

百川应用控制台->SDK下载->服务端SDK->Java版本(如图)

1.2 SDK的依赖包下载

SDK 依赖一个Apache的commons-logging包,下载地址: commons-logging 。 

1.3 将SDK导入工程

      云推送Open API是一个标准的top的API接口,遵循的TOP的API的使用标准 ,云推送Open API环境一个线上的环境,URL是一个线上的TOP的网关地址。将下载的SDK包导入到工程中,即可调用API。

1.4 Open API环境说明

云推送API地址:API地址

api调用方法:api调用

API请求地址:http://gw.api.taobao.com/router/rest

安全参数:appkey和secret(百川应用控制台->证书权限管理处查看appkey和secret信息) 

IOS推送消息(简单)

     入参中body消息内容, 消息是在应用内接收 若需要传自定义参数,也可以通过此字段传递 应用内接收后做解析)。target 和target_value,target_value根据target来确定。如Target=device, 则对应的值为 设备id1,设备id2. 多个值使用逗号分隔 ,target=all时 target_value 也要传target_value=all。(非all时帐号与设备有一次最多100个的限制)

Java示例代码

1) 推送iOS所有设备

req.setBody("push all");
req.setTarget("all");
req.setTargetValue("all");

2) 推送指定设备

req.setBody("push device");
req.setTarget("device");
req.setTargetValue("device1,device2");//实际使用时,用真实的deviceId替换

3) 推送指定账号

req.setBody("push account");
req.setTarget("account");
req.setTargetValue("account1,account2");//实际使用时,用真实的accountd的值替换

4) 完整例子

import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.CloudpushMessageIosRequest;
import com.taobao.api.response.CloudpushMessageIosResponse;

/**
 * Created by mike
 *
*/

public class PushMessageIosTest {  
  private static String appkey="61246563";
  private static String secret="1hfhfhfjfjff822010abfacd54b070f";
  private static String url="http://gw.api.taobao.com/router/rest";
  public static void main(String[] args) {
        TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
        CloudpushMessageIosRequest req = new CloudpushMessageIosRequest();
        req.setBody("push all");
        req.setTarget("all");
        req.setTargetValue("all");
        try {
             CloudpushMessageIosResponse response = client.execute(req);
             System.out.println(response.getBody());
             if(response.isSuccess()){
                 System.out.println("push message is success!");
             }
         }
         catch (Exception e){
             System.out.println("push message is error!");
         }
      }
  }

Android推送消息(简单)

      入参中body消息内容, 消息是在应用内接收 若需要传自定义参数,也可以通过此字段传递 应用内接收后做解析)。target 和target_value,target_value根据target来确定。如Target=device, 则对应的值为 设备id1,设备id2. 多个值使用逗号分隔 ,target=all时 target_value 也要传target_value=all。(非all时帐号与设备有一次最多100个的限制)

java示例代码 

1) 推送Android所有设备

req.setBody("push all");
req.setTarget("all");
req.setTargetValue("all");

2) 推送指定设备

req.setBody("push device");
req.setTarget("device");
req.setTargetValue("device1,device2");//实际使用时,用真实的deviceId替换

3) 推送指定账号

req.setBody("push account");
req.setTarget("account");
req.setTargetValue("account1,account2");//实际使用时,用真实的accountd的值替换

4) 完整例子

import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.CloudpushMessageAndroidRequest;
import com.taobao.api.response.CloudpushMessageAndroidResponse;

/**
 * Created by mike
 *
*/

public class PushMessageIosTest {  
  private static String appkey="61246563";
  private static String secret="1hfhfhfjfjff822010abfacd54b070f";
  private static String url="http://gw.api.taobao.com/router/rest";
  public static void main(String[] args) {
        TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
        CloudpushMessageAndroidRequest req = new CloudpushMessageAndroidRequest();
        req.setBody("push all");
        req.setTarget("all");
        req.setTargetValue("all");
        try {
             CloudpushMessageAndroidResponse response = client.execute(req);
             System.out.println(response.getBody());
             if(response.isSuccess()){
                 System.out.println("push message is success!");
             }
         }
         catch (Exception e){
             System.out.println("push message is error!");
         }
      }
  }

IOS推送通知(简单)

      入参中target 和target_value。target_value根据target来确定。如Target=device, 则对应的值为 设备id1,设备id2. 多个值使用逗号分隔 ,target=all时 target_value 也要传target_value=all。(非all时帐号与设备有一次最多100个的限制)

Java示例代码

1) 推送iOS所有设备

req.setSummary("push all");
req.setTarget("all");
req.setTargetValue("all");
req.setEnv("env");
req.setExt("{"badge":1,"sound":"xxxx"}");

2) 推送指定设备

req.setSummary("push device");
req.setTarget("device");
req.setTargetValue("device1,device2");//实际使用时,用真实的deviceId替换
req.setEnv("env");
req.setExt("{"badge":1,"sound":"xxxx"}");

3) 推送指定账号

req.setSummary("push account");
req.setTarget("account");
req.setTargetValue("account1,account2");//实际使用时,用真实的account的值替换
req.setEnv("env");
req.setExt("{"badge":1,"sound":"xxxx"}");

4) 完整例子

import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.CloudpushNoticeIosRequest;
import com.taobao.api.response.CloudpushNoticeIosResponse;

/**
* Created by mike
*/
public class NoticeIosTest {
    private static String appkey="61246563";  
    private static String secret="1hfhfhfjfjff822010abfacd54b070f";
    private static String url="http://gw.api.taobao.com/router/rest";
    public static void main(String[] args){  
        TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
        CloudpushNoticeIosRequest req=new CloudpushNoticeIosRequest();
        req.setSummary("push all");
        req.setTarget("all");
        req.setTargetValue("all");
        req.setEnv("env");
        req.setExt("{"badge":1,"sound":"xxxx"}");
        try {
            CloudpushNoticeIosResponse response = client.execute(req);
            if(response.isSuccess()){
                System.out.println("push  notice is success!");
            }
        }
        catch (Exception e){
            System.out.println("push notice is error!");
        }

   }
}

 Android推送通知(简单)

      入参中target 和target_value。target_value根据target来确定。如Target=device, 则对应的值为 设备id1,设备id2. 多个值使用逗号分隔 ,target=all时 target_value 也要传target_value=all。(非all时帐号与设备有一次最多100个的限制)

Java示例代码

1) 推送Android所有设备

req.setSummary("push all");
req.setTitle("push title");
req.setTarget("all");
req.setTargetValue("all");

2) 推送指定设备

req.setSummary("push device");
req.setTitle("push title");
req.setTarget("device");
req.setTargetValue("device1,device2");//实际使用时,用真实的deviceId替换

3) 推送指定账号

req.setSummary("push account");
req.setTitle("push title");
req.setTarget("account");
req.setTargetValue("account1,account2");//实际使用时,用真实的account的值替换

4) 完整例子

import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.CloudpushNoticeAndroidRequest;
import com.taobao.api.response.CloudpushNoticeAndroidResponse;

/**
* Created by mike
*/
public class NoticeIosTest {
    private static String appkey="61246563";  
    private static String secret="1hfhfhfjfjff822010abfacd54b070f";
    private static String url="http://gw.api.taobao.com/router/rest";
    public static void main(String[] args){  
        TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
        CloudpushNoticeAndroidRequest req=new CloudpushNoticeAndroidRequest();
        req.setSummary("push all");
        req.setTitle("push title");
        req.setTarget("all");
        req.setTargetValue("all");
        try {
            CloudpushNoticeAndroidResponse response = client.execute(req);
            if(response.isSuccess()){
                System.out.println("push  notice is success!");
            }
        }
        catch (Exception e){
            System.out.println("push notice is error!");
        }

   }
}

IOS/Android推送通知/消息高级接口

对应控制台高级设置

1 公共参数:

target 和target_value如上介绍

device_type:设备类型:iOS:deviceType=0;Andriod:deviceType=1; 默认为全部(3)

type:0:表示消息(默认为0),1:表示通知

anti_harass_duration: 防打扰时长

anti_harass_start_time:防打扰开始时间

batch_number:用于效果统计

store_offline :离线消息是否保存

timeout:离线消息保存时长,取值范围为1~72,若不填,则表示不保存离线消息

title:通知标题

body: 消息内容 (消息是在应用内接收 若需要传自定义参数,也可以通过此字段传递 应用内接收后做解析),发送消息时候用到。

summery:通知摘要,通知的时候用到。

2 IOS 参数:

ios_badge:iOS应用图标右上角角标

ios_ext_parameters:自定义的kv结构,开发者扩展用 针对iOS设备 发IOS通知时候用到。

ios_music:iOS通知声音

remind:当APP不在线时候,是否通过通知提醒.。 该参数只针对iOS设备生效, 

3 Android参数:

android_open_type:点击通知后动作,1:打开应用 2: 打开应用Activity 3:打开 url

android_activity:Android对应的activity,仅仅当androidOpenType=2有效

android_open_url:Android收到推送后打开对应的url,仅仅当androidOpenType=3有效

android_ext_parameters:自定义的kv结构,开发者扩展用 发送Andriod通知时使用。

android_music:通知声音

1) 完整例子
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.CloudpushPushRequest;
import com.taobao.api.response.CloudpushPushResponse;

public class AdvancedPushTest {
    private static String appkey="61246563";  
    private static String secret="1hfhfhfjfjff822010abfacd54b070f";
    private static String url="http://gw.api.taobao.com/router/rest";
    public static void main(String[] args) {
        TaobaoClient client=new DefaultTaobaoClient(url, appkey, secret);
        CloudpushPushRequest req=new CloudpushPushRequest();
        req.setTarget("device");
        req.setTargetValue("device1,device2");
        req.setAndroidActivity("/store/...");
        req.setAndroidExtParameters("{k:v}");
        req.setAndroidMusic("default");
        req.setAndroidOpenType("1");
        req.setAndroidOpenUrl("http://www.taobao.com");
        req.setAntiHarassDuration(13L);
        req.setAntiHarassStartTime(1L);
        req.setBatchNumber("0001");
        req.setBody("this is push body");
        req.setDeviceType(3L);
        req.setIosBadge("1");
        req.setIosExtParameters("{k:v}");
        req.setIosMusic("default");
        req.setRemind(false);
        req.setStoreOffline(false);
        req.setSummery("this is summary");
        req.setTimeout(72L);
        req.setTitle("this is title");
        try {
            CloudpushPushResponse response = client.execute(req);
            if(response.isSuccess()){
                System.out.println("push message is success!");
            }
        }
        catch (Exception e){
            System.out.println("push message is error!");
        }
    }
}

  

技术咨询

 

 

旺旺群:1074804791

FAQ

关于此文档暂时还没有FAQ
返回
顶部