8000 mobpush-api-java-client init · MOBX/mobpush-api-java-client@c095257 · GitHub
[go: up one dir, main page]

Skip to content

Commit c095257

Browse files
committed
mobpush-api-java-client init
0 parents  commit c095257

31 files changed

+2575
-0
lines changed

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
*.class
2+
# Mobile Tools for Java (J2ME)
3+
.mtj.tmp/
4+
# Package Files #
5+
*.war
6+
*.ear
7+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
8+
hs_err_pid*
9+
*.settings
10+
*.prefs
11+
org.eclipse.core.resources.prefs
12+
target
13+
*.classpath
14+
*.project
15+
.externalToolBuilders/
16+
logs/
17+
*.log
18+
.DS_Store
19+
20+
#idea
21+
*.idea
22+
*.iml
23+
.svn
24+
*.svn
25+
26+
#project

README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# [MobPush API for Java](http://wiki.mob.com/mobpush-rest-api-接口文档/)
2+
3+
![image](https://github.com/MOBX/MOB-SMS-WEBAPI/blob/master/doc/images/logo.png)
4+
5+
**[MobPush API for Java](http://wiki.mob.com/mobpush-rest-api-接口文档/)**
6+
为了帮助开发者更方便接入MobPush免费推送SDK,提供完整的API接口的java实现,包含设备操作相关接口、推送操作相关接口以及公共接口。
7+
8+
了解更多 [MobPush 免费推送SDK.](http://mobpush.mob.com)
9+
10+
11+
## 优势
12+
13+
**免费使用****自定义UI****稳定服务****流程体验****数据同步****专业技术团队服务**
14+
15+
## 接口
16+
* 推送接口
17+
* 发送推送
18+
* 查询推送(根据batchId)
19+
* 查询推送(根据workno)
20+
* 推送统计接口
21+
* 查询推送统计(根据batchId)
22+
* 查询推送统计(根据workno)
23+
* 别名操作接口
24+
* 查询别名
25+
* 设置别名
26+
* 标签操作接口
27+
* 查询标签
28+
* 设置标签
29+
* 公共接口
30+
* 地理位置信息接口
31+
32+
## jar包依赖说明
33+
34+
主要需要依赖httpclient.jar 、fastjson.jar
35+
36+
* 如果使用 Maven 构建项目,则需要在你的项目 pom.xml 里增加:
37+
38+
```xml
39+
<dependency>
40+
<groupId>org.apache.httpcomponents</groupId>
41+
<artifactId>httpclient</artifactId>
42+
<version>4.5.3</version>
43+
<scope>compile</scope>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>org.slf4j</groupId>
48+
<artifactId>slf4j-api</artifactId>
49+
<version>1.7.7</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.slf4j</groupId>
53+
<artifactId>slf4j-log4j12</artifactId>
54+
<version>1.7.7</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>log4j</groupId>
58+
<artifactId>log4j</artifactId>
59+
<version>1.2.17</version>
60+
</dependency>
61+
62+
<dependency>
63+
<groupId>com.alibaba</groupId>
64+
<artifactId>fastjson</artifactId>
65+
<version>1.2.31</version>
66+
</dependency>
67+
```
68+
69+
* 如果不使用 Maven 构建项目,则项目 libs/ 目录下有依赖的 jar 可复制到你的项目里去。
70+
71+
## 使用注意事项
72+
* 初始化appkey、appSecret
73+
```Java
74+
MobPushConfig.appkey = "moba6b6c6d6";
75+
MobPushConfig.appSecret = "";
76+
```
77+
以上是使用时设置的方式,还可以直接引用源码在mob.push.api.MobPushConfig设置
78+
79+
## 使用DEMO
80+
81+
发送推送示例片段代码
82+
83+
```Java
84+
PushWork push = new PushWork(PlatEnum.all.getCode(),"test content" , PushTypeEnum.notify.getCode()) //初始化基础信息
85+
.buildTarget(TargetEnum._1.getCode(), null, null, null, null, null) // 设置推送范围
86+
.buildAndroid("Android Title", AndroidNotifyStyleEnum.normal.getCode(), null, true, true, true) //定制android样式
87+
.bulidIos("ios Title", "ios Subtitle", null, 1, null, null, null, null) //定制ios设置
88+
.buildExtra(1, "{\"key1\":\"value\"}", 1) // 设置扩展信息
89+
;
90+
91+
PushClient client = new PushClient();
92+
try {
93+
client.sendPush(push);
94+
} catch (ApiException e) {
95+
e.getStatus(); //错误请求状态码
96+
e.getErrorCode(); //错误状态码
97+
e.getErrorMessage(); //错误信息
98+
}
99+
100+
```

libs/commons-codec-1.9.jar

258 KB
Binary file not shown.

libs/commons-logging-1.2.jar

60.4 KB
Binary file not shown.

libs/fastjson-1.2.31.jar

452 KB
Binary file not shown.

libs/httpclient-4.5.3.jar

730 KB
Binary file not shown.

libs/httpcore-4.4.6.jar

316 KB
Binary file not shown.

libs/log4j-1.2.17.jar

478 KB
Binary file not shown.

libs/slf4j-api-1.7.7.jar

28.6 KB
Binary file not shown.

libs/slf4j-log4j12-1.7.7.jar

8.66 KB
Binary file not shown.

pom.xml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0"?>
2+
<project
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>com.mob.sdk.push</groupId>
7+
<artifactId>mobpush-api-java-client</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
<name>mobpush-api-java-client</name>
10+
<url>http://maven.apache.org</url>
11+
<description> MobPush API for Java </description>
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
</properties>
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.apache.httpcomponents</groupId>
18+
<artifactId>httpclient</artifactId>
19+
<version>4.5.3</version>
20+
<scope>compile</scope>
21+
</dependency>
22+
23+
<dependency>
24+
<groupId>org.slf4j</groupId>
25+
<artifactId>slf4j-api</artifactId>
26+
<version>1.7.7</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.slf4j</groupId>
30+
<artifactId>slf4j-log4j12</artifactId>
31+
<version>1.7.7</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>log4j</groupId>
35+
<artifactId>log4j</artifactId>
36+
<version>1.2.17</version>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>com.alibaba</groupId>
41+
<artifactId>fastjson</artifactId>
42+
<version>1.2.31</version>
43+
</dependency>
44+
</dependencies>
45+
</project>
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/**
2+
* Project Name:mobpush-api-java-client
3+
* File Name:MobPushClient.java
4+
* Package Name:mob.push.api
5+
* Date: 2018年2月2日
6+
* Time: 下午6:11:41
7+
*
8+
*/
9+
10+
package mob.push.api;
11+
12+
import java.util.List;
13+
14+
import mob.push.api.area.AreaClient;
15+
import mob.push.api.device.DeviceClient;
16+
import mob.push.api.exception.ApiException;
17+
import mob.push.api.model.Area;
18+
import mob.push.api.model.PushStats;
19+
import mob.push.api.model.PushWork;
20+
import mob.push.api.push.PushClient;
21+
import mob.push.api.stats.StatsClient;
22+
23+
/**
24+
* ClassName:MobPushClient <br/>
25+
* TODO ADD DESCRIPTION
26+
* Date: 2018年2月2日
27+
* Time: 下午6:11:41
28+
* @author hlliu
29+
*/
30+
public class MobPushClient {
31+
32+
PushClient _pushClient = new PushClient();
33+
34+
StatsClient _statsClient = new StatsClient();
35+
36+
DeviceClient _deviceClient = new DeviceClient();
37+
38+
AreaClient _areaClient = new AreaClient();
39+
40+
41+
/**
42+
* 推送接口 -- 发送推送
43+
* @param pushWork
44+
* @return
45+
* @throws ApiException
46+
*/
47+
public String push(PushWork pushWork) throws ApiException{
48+
return _pushClient.sendPush(pushWork);
49+
}
50+
51+
/**
52+
* 推送接口 -- 查询推送 根据BatchId
53+
* 根据创建id查询推送消息详情
54+
* @param batchId
55+
* @return
56+
* @throws ApiException
57+
*/
58+
public PushWork pushById(String batchId) throws ApiException{
59+
return _pushClient.getPushByBatchId(batchId);
60+
}
61+
62+
/**
63+
* 推送接口 -- 查询推送 根据workno
64+
* 根据自定义编号查询消息详情
65+
* @param workno
66+
* @return
67+
* @throws ApiException
68+
*/
69+
public PushWork pushByWorkno(String workno) throws ApiException{
70+
return _pushClient.getPushByWorkno(workno);
71+
}
72+
73+
/**
74+
* 推送统计-- 查询推送统计
75+
* 根据创建id查询推送统计
76+
* @param batchId
77+
* @return
78+
* @throws ApiException
79+
*/
80+
public PushStats statsById(String batchId) throws ApiException{
81+
return _statsClient.getStatsByBatchId(batchId);
82+
}
83+
84+
/**
85+
* 推送统计-- 查询推送统计
86+
* 根据自定义编号查询推送统计
87+
* @param workno
88+
* @return
89+
* @throws ApiException
90+
*/
91+
public PushStats statsByWorkno(String workno) throws ApiException{
92+
return _statsClient.getStatsByWorkno(workno);
93+
}
94+
95+
/**
96+
* 查询标签
97+
* 根据设备registrationId查询标签信息
98+
* @param registrationId
99+
* @return
100+
* @throws ApiException
101+
*/
102+
public String[] tagsByRegistrationId(String registrationId) throws ApiException{
103+
return _deviceClient.getDeviceTags(registrationId);
104+
}
105+
106+
/**
107+
* 设备绑定标签
108+
* @param tags
109+
* @param registrationId
110+
* @return
111+
* @throws ApiException
112+
*/
113+
public int tagsAdd(String[] tags, String registrationId) throws ApiException{
114+
return _deviceClient.addDeviceTags(tags, registrationId);
115+
}
116+
117+
/**
118+
* 删除指定设备标签
119+
* @param tags
120+
* @param registrationId
121+
* @return
122+
* @throws ApiException
123+
*/
124+
public int tagsRemove(String[] tags, String registrationId) throws ApiException{
125+
return _deviceClient.removeDeviceTags(tags, registrationId);
126+
}
127+
128+
/**
129+
* 清除指定标签
130+
* @param registrationId
131+
* @return
132+
* @throws ApiException
133+
*/
134+
public int tagsClean(String registrationId) throws ApiException{
135+
return _deviceClient.cleanDeviceTags(registrationId);
136+
}
137+
138+
/**
139+
* 获取指定设备别名
140+
* @param registrationId
141+
* @return
142+
* @throws ApiException
143+
*/
144+
public String aliasByRegistrationId(String registrationId) throws ApiException{
145+
return _deviceClient.getDeviceAlias(registrationId);
146+
}
147+
148+
/**
149+
* 设备绑定别名
150+
* @param alias
151+
* @param registrationId
152+
* @return (仅200表示成功)
153+
* @throws ApiException
154+
*/
155+
public int setAlias(String alias, String registrationId) throws ApiException{
156+
return _deviceClient.setDeviceAlias(alias, registrationId);
157+
}
158+
159+
/**
160+
* 清除设备别名
161+
* @param registrationId
162+
* @return
163+
* @throws ApiException
164+
*/
165+
public int cleanAlias(String registrationId) throws ApiException{
166+
return _deviceClient.cleanDeviceAlias(registrationId);
167+
}
168+
169+
/**
170+
* 获取地理位置列表 -- 中国下省份列表
171+
* @return
172+
* @throws ApiException
173+
*/
174+
public List<Area> area() throws ApiException{
175+
return _areaClient.getArea();
176+
}
177+
178+
/**
179+
* 获取地理位置列表 -- 子级列表
180+
* @param parentId
181+
* @return
182+
* @throws ApiException
183+
*/
184+
public List<Area> area(String parentId)throws ApiException{
185+
return _areaClient.getArea(parentId);
186+
}
187+
}
188+

0 commit comments

Comments
 (0)
0