Skip to content

Commit 5e7eccc

Browse files
author
lizhijian
committed
通知栏图片、展开大图推送支持
1 parent 1f5cfd0 commit 5e7eccc

11 files changed

Lines changed: 450 additions & 221 deletions

File tree

README.md

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
## 更新日志
88

9+
### [2021-11-11]V1.2.9.2021111_release
10+
11+
* 增加通知栏图片,展开大图推送支持
12+
913
### [2019-01-14]V1.2.8.20190114_release
14+
1015
* update log config
1116

1217
### [2018-11-06]V1.2.7.20181228_release
@@ -81,6 +86,7 @@
8186
* [回执类型(CallBackType)](#CallBackType_index)
8287
* [回执参数(ExtraParam)](#ExtraParam_index)
8388
* [二.接口说明](#api_def_index)
89+
* [图片上传](#uploadImage_index)
8490
* [非任务推送](#UnTaskPush_index)
8591
* [pushId通知栏消息推送(pushMessage)](#VarnishedMessage_push_index)
8692
* [pushId透传消息推送(pushMessage)](#UnVarnishedMessage_push_index)
@@ -145,9 +151,11 @@ appId|Long|是|null|注册应用appId
145151
restrictedPackageNames|String[]|否|null|多包名配置【最长50】
146152
title|String|是|null|推送标题, 【字数限制1~32】
147153
content|String|是|null|推送内容, 【字数限制1~100】
148-
noticeBarType|int|否|0|通知栏样式(0, "标准"),(2, "安卓原生")【非必填,默认值为0】
149-
noticeExpandType|int|否|0|展开方式 (0, "标准"),(1, "文本")【非必填,默认值为0】
154+
noticeBarType|int|否|0|通知栏样式(0, "标准"),(1, "图片"),(2, "安卓原生")【非必填,默认值为0】
155+
noticeBarImgUrl|String|否|null|通知栏图片, 【noticeBarType为图片时,必填】
156+
noticeExpandType|int|否|0|展开方式 (0, "标准"),(1, "文本"),(2, "大图")【非必填,默认值为0】
150157
noticeExpandContent|String|否|null|展开内容, 【noticeExpandType为文本时,必填】
158+
noticeExpandImgUrl|String|否|null|展开大图url, 【noticeExpandType为大图时,必填】
151159
clickType|int|否|0|点击动作 (0,"打开应用"),(1,"打开应用页面"),(2,"打开URI页面"),(3, "应用客户端自定义")【非必填,默认值为0】
152160
url|String|否|null|URI页面地址, 【clickType为打开URI页面时,必填】
153161
parameters|JSONObject|否|null|透传参数 【JSON格式,非必填】
@@ -301,7 +309,59 @@ CALLBACK_TYPE|Enum|回执类型((1-送达回执, 2-点击回执, 3-送达与
301309

302310

303311
# 接口说明 <a name="api_def_index"/>
312+
## 图片上传<a name="uploadImage_index"/>
313+
314+
### 描述
315+
316+
> 通知栏图片、展开大图使用的图片链接需要由此接口上传生成
317+
318+
```
319+
注:上传的图片最多保留三天,请在需要时才上传
320+
```
321+
322+
### uploadImage上传接口
323+
324+
* 接口说明
325+
326+
| 接口 | 说明 |
327+
| ------------------------------------------------------------ | -------- |
328+
| public ResultPack<ImageInfo> uploadImage(long appId, int imgType, String imgUrl) | 上传图片 |
329+
330+
* 参数说明
331+
332+
| 参数名称 | 类型 | 必需 | 默认 | 描述 |
333+
| -------- | ------ | ---- | ---- | ------------ |
334+
| appId | long || null | 应用id |
335+
| imgType | int || null | 图片使用类型 |
336+
| imgUrl | String || null | 图片来源url |
337+
338+
* 返回值
339+
340+
```
341+
ImageInfo
342+
imgType:图片类型
343+
imgUrl:推送时使用的url
344+
```
345+
346+
* 示例
347+
348+
```java
349+
/**
350+
* 图片上传
351+
*/
352+
@Test
353+
public void testPicUpload()throws Exception{
354+
String imgUrl = "";
355+
IFlymePush push = new IFlymePush(APP_SECRET_KEY);
356+
ResultPack<ImageInfo> ret = push.uploadImage(appId,ImageInfo.NOTICE_BAR_IMG,imgUrl);
357+
System.out.println(ret.toString());
358+
}
359+
```
360+
361+
362+
304363
## 非任务推送 <a name="UnTaskPush_index"/>
364+
305365
### 描述
306366
> 向指定的pushId推送消息
307367
```

pom.xml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.meizu.flyme</groupId>
77
<artifactId>push-server-sdk</artifactId>
8-
<version>1.2.8.20190114_release</version>
8+
<version>1.2.9.20211111_release</version>
99

1010
<packaging>jar</packaging>
1111
<name>MeizuPushSDK</name>
@@ -19,6 +19,11 @@
1919
</properties>
2020

2121
<developers>
22+
<developer>
23+
<id>meizupush</id>
24+
<name>meizupush</name>
25+
<email>meizupush@meizu.com</email>
26+
</developer>
2227
<developer>
2328
<id>jasperxgwang</id>
2429
<name>jasperxgwang</name>
@@ -103,7 +108,7 @@
103108
<plugin>
104109
<groupId>org.apache.maven.plugins</groupId>
105110
<artifactId>maven-source-plugin</artifactId>
106-
<version>2.2.1</version>
111+
<version>3.2.1</version>
107112
<executions>
108113
<execution>
109114
<phase>package</phase>
@@ -124,12 +129,17 @@
124129
<goals>
125130
<goal>jar</goal>
126131
</goals>
132+
<configuration>
133+
<additionalparam>-Xdoclint:none</additionalparam>
134+
</configuration>
127135
</execution>
136+
128137
</executions>
129138
</plugin>
130139
<!-- GPG -->
131140
<plugin>
132141
<artifactId>maven-gpg-plugin</artifactId>
142+
<version>1.6</version>
133143
<configuration>
134144
<skip>false</skip>
135145
</configuration>
@@ -147,11 +157,11 @@
147157
</build>
148158
<distributionManagement>
149159
<snapshotRepository>
150-
<id>oss</id>
160+
<id>ossrh</id>
151161
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
152162
</snapshotRepository>
153163
<repository>
154-
<id>oss</id>
164+
<id>ossrh</id>
155165
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
156166
</repository>
157167
</distributionManagement>
@@ -164,18 +174,18 @@
164174
<plugin>
165175
<groupId>org.apache.maven.plugins</groupId>
166176
<artifactId>maven-resources-plugin</artifactId>
167-
<version>2.5</version>
177+
<version>3.2.0</version>
168178
<configuration>
169179
<encoding>UTF-8</encoding>
170180
</configuration>
171181
</plugin>
172182
<plugin>
173183
<groupId>org.apache.maven.plugins</groupId>
174184
<artifactId>maven-compiler-plugin</artifactId>
175-
<version>2.5.1</version>
185+
<version>3.8.1</version>
176186
<configuration>
177-
<source>1.6</source>
178-
<target>1.6</target>
187+
<source>1.8</source>
188+
<target>1.8</target>
179189
<encoding>UTF-8</encoding>
180190
</configuration>
181191
</plugin>

src/main/java/com/meizu/push/sdk/constant/SystemConstants.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ public class SystemConstants {
77

88
public static final String CHAR_SET = "UTF-8";
99

10-
public static final String SDK_VERSION = "1.2.8.20190114_release";
10+
public static final String SDK_VERSION = "1.2.9.2021111_release";
1111

1212
private static final String PUSH_HOST_NAME = "server-api-push.meizu.com";
1313
private static final String SUB_HOST_NAME = "api-push.meizu.com";
1414

15+
16+
/**
17+
* 推送服务:图片上传接口
18+
*/
19+
public static final String PUSH_UPLOAD_IMAGE = "http://" + PUSH_HOST_NAME + "/garcia/api/server/push/uploadImg";
1520
/**
1621
* 推送服务:pushId推送接口(透传消息)
1722
*/

src/main/java/com/meizu/push/sdk/server/IFlymePush.java

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,19 @@
88
import com.meizu.push.sdk.constant.SystemConstants;
99
import com.meizu.push.sdk.server.constant.ResultPack;
1010
import com.meizu.push.sdk.server.model.HttpResult;
11-
import com.meizu.push.sdk.server.model.push.Message;
12-
import com.meizu.push.sdk.server.model.push.PushResult;
13-
import com.meizu.push.sdk.server.model.push.UnVarnishedMessage;
14-
import com.meizu.push.sdk.server.model.push.VarnishedMessage;
11+
import com.meizu.push.sdk.server.model.push.*;
1512
import com.meizu.push.sdk.server.model.statistics.DailyPushStatics;
1613
import com.meizu.push.sdk.server.model.statistics.TaskStatistics;
1714
import com.meizu.push.sdk.utils.CollectionUtils;
1815
import com.meizu.push.sdk.utils.DateUtils;
1916
import com.meizu.push.sdk.utils.HttpClient;
2017
import com.meizu.push.sdk.utils.StringUtils;
21-
import com.meizu.push.sdk.vo.AdvanceInfo;
22-
import com.meizu.push.sdk.vo.ClickTypeInfo;
23-
import com.meizu.push.sdk.vo.NoticeBarInfo;
24-
import com.meizu.push.sdk.vo.NoticeExpandInfo;
25-
import com.meizu.push.sdk.vo.NotificationType;
26-
import com.meizu.push.sdk.vo.PushTimeInfo;
27-
import com.meizu.push.sdk.vo.UnVarnishedMessageJson;
28-
import com.meizu.push.sdk.vo.VarnishedMessageJson;
18+
import com.meizu.push.sdk.vo.*;
2919
import org.slf4j.Logger;
3020
import org.slf4j.LoggerFactory;
3121

3222
import java.io.IOException;
33-
import java.util.ArrayList;
34-
import java.util.Date;
35-
import java.util.HashMap;
36-
import java.util.List;
37-
import java.util.Map;
23+
import java.util.*;
3824

3925
/**
4026
* @author wangxinguo <wangxinguo@meizu.com>
@@ -56,6 +42,18 @@ public IFlymePush(String appSecret, boolean useSSL) {
5642
super(appSecret, useSSL);
5743
}
5844

45+
46+
public ResultPack<ImageInfo> uploadImage(long appId, int imgType, String imgUrl) throws IOException {
47+
if (appId == 0) {
48+
return ResultPack.failed("appId is illegal");
49+
}
50+
if (imgType != ImageInfo.NOTICE_BAR_IMG && imgType != ImageInfo.NOTICE_EXPAND_IMG) {
51+
return ResultPack.failed("imgType is illegal");
52+
}
53+
54+
return uploadImage(appId, imgType, imgUrl, 0);
55+
}
56+
5957
/**
6058
* 通知栏推送 不重试
6159
*
@@ -229,8 +227,8 @@ public ResultPack<Long> getTaskId(PushType pushType, Message message) throws IOE
229227
}
230228
VarnishedMessage msgInfo = (VarnishedMessage) message;
231229

232-
NoticeBarInfo noticeBarInfo = new NoticeBarInfo(msgInfo.getNoticeBarType(), msgInfo.getTitle(), msgInfo.getContent());
233-
NoticeExpandInfo noticeExpandInfo = new NoticeExpandInfo(msgInfo.getNoticeExpandType(), msgInfo.getNoticeExpandContent());
230+
NoticeBarInfo noticeBarInfo = new NoticeBarInfo(msgInfo.getNoticeBarType(), msgInfo.getTitle(), msgInfo.getContent(), msgInfo.getNoticeBarImgUrl());
231+
NoticeExpandInfo noticeExpandInfo = new NoticeExpandInfo(msgInfo.getNoticeExpandType(), msgInfo.getNoticeExpandContent(), msgInfo.getNoticeExpandImgUrl());
234232
ClickTypeInfo clickTypeInfo = new ClickTypeInfo(msgInfo.getClickType(), msgInfo.getUrl(), msgInfo.getParameters(), msgInfo.getActivity(), msgInfo.getCustomAttribute());
235233
PushTimeInfo pushTimeInfo = new PushTimeInfo(msgInfo.isOffLine(), msgInfo.getValidTime());
236234
NotificationType notificationType = new NotificationType(msgInfo.isVibrate(), msgInfo.isLights(), msgInfo.isSound());
@@ -383,8 +381,8 @@ public ResultPack<Long> pushToApp(PushType pushType, Message message) throws IOE
383381
}
384382
VarnishedMessage msgInfo = (VarnishedMessage) message;
385383

386-
NoticeBarInfo noticeBarInfo = new NoticeBarInfo(msgInfo.getNoticeBarType(), msgInfo.getTitle(), msgInfo.getContent());
387-
NoticeExpandInfo noticeExpandInfo = new NoticeExpandInfo(msgInfo.getNoticeExpandType(), msgInfo.getNoticeExpandContent());
384+
NoticeBarInfo noticeBarInfo = new NoticeBarInfo(msgInfo.getNoticeBarType(), msgInfo.getTitle(), msgInfo.getContent(), msgInfo.getNoticeBarImgUrl());
385+
NoticeExpandInfo noticeExpandInfo = new NoticeExpandInfo(msgInfo.getNoticeExpandType(), msgInfo.getNoticeExpandContent(), msgInfo.getNoticeExpandImgUrl());
388386
ClickTypeInfo clickTypeInfo = new ClickTypeInfo(msgInfo.getClickType(), msgInfo.getUrl(), msgInfo.getParameters(), msgInfo.getActivity(), msgInfo.getCustomAttribute());
389387
String startTime = "";
390388
if (msgInfo.getStartTime() != null) {
@@ -478,8 +476,8 @@ public ResultPack<Long> pushToTag(PushType pushType, Message message, List<Strin
478476
}
479477
VarnishedMessage msgInfo = (VarnishedMessage) message;
480478

481-
NoticeBarInfo noticeBarInfo = new NoticeBarInfo(msgInfo.getNoticeBarType(), msgInfo.getTitle(), msgInfo.getContent());
482-
NoticeExpandInfo noticeExpandInfo = new NoticeExpandInfo(msgInfo.getNoticeExpandType(), msgInfo.getNoticeExpandContent());
479+
NoticeBarInfo noticeBarInfo = new NoticeBarInfo(msgInfo.getNoticeBarType(), msgInfo.getTitle(), msgInfo.getContent(), msgInfo.getNoticeBarImgUrl());
480+
NoticeExpandInfo noticeExpandInfo = new NoticeExpandInfo(msgInfo.getNoticeExpandType(), msgInfo.getNoticeExpandContent(), msgInfo.getNoticeExpandImgUrl());
483481
ClickTypeInfo clickTypeInfo = new ClickTypeInfo(msgInfo.getClickType(), msgInfo.getUrl(), msgInfo.getParameters(), msgInfo.getActivity(), msgInfo.getCustomAttribute());
484482
String startTime = "";
485483
if (msgInfo.getStartTime() != null) {
@@ -610,6 +608,51 @@ public ResultPack<List<DailyPushStatics>> dailyPushStatics(long appId, Date star
610608
}
611609
}
612610

611+
private ResultPack<ImageInfo> uploadImage(long appId, int imgType, String imgUrl, int retries) throws IOException {
612+
int attempt = 0;
613+
ResultPack<ImageInfo> result;
614+
int backoff = 1000;
615+
boolean tryAgain;
616+
do {
617+
++attempt;
618+
logger.debug(String.format("attempt [%s] to uploadImage [%s]", attempt, imgUrl));
619+
result = this.uploadImageNoRetry(appId, imgType, imgUrl);
620+
tryAgain = result == null && attempt <= retries;
621+
backoff = getBackoffTime(backoff, tryAgain);
622+
} while (tryAgain);
623+
if (result == null) {
624+
throw new IOException(String.format("Could not send message after [%s] attempts", attempt));
625+
} else {
626+
return result;
627+
}
628+
}
629+
630+
private ResultPack<ImageInfo> uploadImageNoRetry(long appId, int imgType, String imgUrl) throws IOException {
631+
String _url = SystemConstants.PUSH_UPLOAD_IMAGE;
632+
StringBuilder body = newBody("pushIds", String.valueOf(appId));
633+
addParameter(body, "appId", String.valueOf(appId));
634+
addParameter(body, "imgType", String.valueOf(imgType));
635+
addParameter(body, "imgUrl", imgUrl);
636+
637+
HttpResult httpResult = super.post(useSSL, _url, body.toString());
638+
if (httpResult == null) {
639+
return null;
640+
}
641+
642+
String code = httpResult.getCode();
643+
String msg = httpResult.getMessage();
644+
String value = httpResult.getValue();
645+
if (SUCCESS_CODE.equals(code)) {
646+
try {
647+
ImageInfo imageInfo = JSONObject.parseObject(value, ImageInfo.class);
648+
return ResultPack.succeed(code, msg, imageInfo);
649+
} catch (Exception e) {
650+
return ResultPack.failed(code, String.format("ImageInfo转化异常,原始str:%s,msg:%s", value, e.getMessage()));
651+
}
652+
} else {
653+
return ResultPack.failed(code, msg);
654+
}
655+
}
613656

614657
private ResultPack<PushResult> pushMessage(UserType userType, PushType pushType, Message message, String targets, int retries) throws IOException {
615658
int attempt = 0;
@@ -675,8 +718,8 @@ private ResultPack<PushResult> pushMessageNoRetry(UserType userType, PushType pu
675718
} else if (PushType.STATUSBAR == pushType) {
676719
VarnishedMessage msgInfo = (VarnishedMessage) message;
677720

678-
NoticeBarInfo noticeBarInfo = new NoticeBarInfo(msgInfo.getNoticeBarType(), msgInfo.getTitle(), msgInfo.getContent());
679-
NoticeExpandInfo noticeExpandInfo = new NoticeExpandInfo(msgInfo.getNoticeExpandType(), msgInfo.getNoticeExpandContent());
721+
NoticeBarInfo noticeBarInfo = new NoticeBarInfo(msgInfo.getNoticeBarType(), msgInfo.getTitle(), msgInfo.getContent(), msgInfo.getNoticeBarImgUrl());
722+
NoticeExpandInfo noticeExpandInfo = new NoticeExpandInfo(msgInfo.getNoticeExpandType(), msgInfo.getNoticeExpandContent(), msgInfo.getNoticeExpandImgUrl());
680723
ClickTypeInfo clickTypeInfo = new ClickTypeInfo(msgInfo.getClickType(), msgInfo.getUrl(), msgInfo.getParameters(), msgInfo.getActivity(), msgInfo.getCustomAttribute());
681724
PushTimeInfo pushTimeInfo = new PushTimeInfo(msgInfo.isOffLine(), msgInfo.getValidTime());
682725
NotificationType notificationType = new NotificationType(msgInfo.isVibrate(), msgInfo.isLights(), msgInfo.isSound());

src/main/java/com/meizu/push/sdk/server/IFlymePushSub.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ public ResultPack<AliasInfo> subscribeAlias(String pushId, String alias) throws
126126
* 取消别名订阅
127127
*
128128
* @param pushId
129-
* @param alias
130129
* @return
131130
* @throws IOException
132131
*/
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.meizu.push.sdk.server.model.push;
2+
3+
import java.io.Serializable;
4+
5+
/**
6+
* 上传图片结果
7+
*/
8+
public class ImageInfo implements Serializable {
9+
10+
public static int NOTICE_BAR_IMG = 0;// 通知栏图片 请上传100kb以内的图片 gif,jpg,bmp,png,jpeg
11+
public static int NOTICE_EXPAND_IMG = 1; // 展开大图 请上传200kb以内的图片 gif,jpg,bmp,png,jpeg
12+
13+
private int imgType;
14+
private String imgUrl;
15+
16+
17+
public int getImgType() {
18+
return imgType;
19+
}
20+
21+
public void setImgType(int imgType) {
22+
this.imgType = imgType;
23+
}
24+
25+
public String getImgUrl() {
26+
return imgUrl;
27+
}
28+
29+
public void setImgUrl(String imgUrl) {
30+
this.imgUrl = imgUrl;
31+
}
32+
33+
@Override
34+
public String toString() {
35+
return "ImageInfo{" +
36+
"imgType=" + imgType +
37+
", imgUrl='" + imgUrl + '\'' +
38+
'}';
39+
}
40+
}

0 commit comments

Comments
 (0)