# getui-pushapi-java-client-v2
**Repository Path**: buyanshang/getui-pushapi-java-client-v2
## Basic Information
- **Project Name**: getui-pushapi-java-client-v2
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2024-02-01
- **Last Updated**: 2024-02-01
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
欢迎使用[个推**PUSH** SDK For Java](https://docs.getui.com/getui/server/rest_v2/introduction/)。
`个推PUSH SDK For Java`的主要目标是提升开发者在**服务端**集成个推推送服务的开发效率。
开发者不需要进行复杂编程即可使用个推推送服务的各项常用功能,SDK可以自动帮您满足调用过程中所需的鉴权、组装参数、发送HTTP请求等非功能性要求。
下面向您介绍`个推PUSH SDK For Java`的使用方法。
## 环境要求
1. 需要配合`JDK 1.6`或其以上版本。
2. 使用`个推PUSH SDK`前,您需要先前往[个推开发者中心](https://dev.getui.com) 完成开发者接入的一些准备工作,创建应用。详细见[操作步骤](https://docs.getui.com/getui/start/devcenter/#1)
3. 准备工作完成后,前往[个推开发者中心](https://dev.getui.com)获取应用配置,后续将作为使用SDK的输入。详细见[操作步骤](https://docs.getui.com/getui/start/devcenter/#11)
## 安装依赖
### 通过[Maven](https://mvnrepository.com/artifact/com.getui.push/restful-sdk)来管理项目依赖
推荐通过Maven来管理项目依赖,您只需在项目的`pom.xml`文件中声明如下依赖
```xml
com.getui.push
restful-sdk
1.0.0.15
```
## 快速开始
### 普通调用
下列代码示例向您展示了使用`个推Push SDK For Java`调用一个API的3个主要步骤:
1. 设置参数,创建API。
2. 发起API调用。
3. 处理响应。
##### 使用示例:**创建API**
```java
public class TestCreatApi {
public void test() {
// 设置httpClient最大连接数,当并发较大时建议调大此参数。或者启动参数加上 -Dhttp.maxConnections=200
System.setProperty("http.maxConnections", "200");
GtApiConfiguration apiConfiguration = new GtApiConfiguration();
//填写应用配置
apiConfiguration.setAppId("xxx");
apiConfiguration.setAppKey("xxx");
apiConfiguration.setMasterSecret("xxx");
// 接口调用前缀,请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId
apiConfiguration.setDomain("https://restapi.getui.com/v2/");
// 实例化ApiHelper对象,用于创建接口对象
ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
// 创建对象,建议复用。目前有PushApi、StatisticApi、UserApi
PushApi pushApi = apiHelper.creatApi(PushApi.class);
}
}
```
##### 使用示例:**推送API**_根据cid进行单推
```java
public class TestPushApi {
//pushApi的创建见上述使用示例:创建API
public PushApi pushApi;
public void test() {
//根据cid进行单推
PushDTO pushDTO = new PushDTO();
// 设置推送参数
pushDTO.setRequestId(System.currentTimeMillis() + "");
/**** 设置个推通道参数 *****/
PushMessage pushMessage = new PushMessage();
pushDTO.setPushMessage(pushMessage);
GTNotification notification = new GTNotification();
pushMessage.setNotification(notification);
notification.setTitle("个title");
notification.setBody("个body");
notification.setClickType("url");
notification.setUrl("https://www.getui.com");
/**** 设置个推通道参数,更多参数请查看文档或对象源码 *****/
/**** 设置厂商相关参数 ****/
PushChannel pushChannel = new PushChannel();
pushDTO.setPushChannel(pushChannel);
/*配置安卓厂商参数*/
AndroidDTO androidDTO = new AndroidDTO();
pushChannel.setAndroid(androidDTO);
Ups ups = new Ups();
androidDTO.setUps(ups);
ThirdNotification thirdNotification = new ThirdNotification();
ups.setNotification(thirdNotification);
thirdNotification.setTitle("厂商title");
thirdNotification.setBody("厂商body");
thirdNotification.setClickType("url");
thirdNotification.setUrl("https://www.getui.com");
// 两条消息的notify_id相同,新的消息会覆盖老的消息,取值范围:0-2147483647
// thirdNotification.setNotifyId("11177");
/*配置安卓厂商参数结束,更多参数请查看文档或对象源码*/
/*设置ios厂商参数*/
IosDTO iosDTO = new IosDTO();
pushChannel.setIos(iosDTO);
// 相同的collapseId会覆盖之前的消息
iosDTO.setApnsCollapseId("xxx");
Aps aps = new Aps();
iosDTO.setAps(aps);
Alert alert = new Alert();
aps.setAlert(alert);
alert.setTitle("ios title");
alert.setBody("ios body");
/*设置ios厂商参数结束,更多参数请查看文档或对象源码*/
/*设置接收人信息*/
Audience audience = new Audience();
pushDTO.setAudience(audience);
audience.addCid("xxx");
/*设置接收人信息结束*/
/**** 设置厂商相关参数,更多参数请查看文档或对象源码 ****/
// 进行cid单推
ApiResult