88import com .meizu .push .sdk .constant .SystemConstants ;
99import com .meizu .push .sdk .server .constant .ResultPack ;
1010import 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 .*;
1512import com .meizu .push .sdk .server .model .statistics .DailyPushStatics ;
1613import com .meizu .push .sdk .server .model .statistics .TaskStatistics ;
1714import com .meizu .push .sdk .utils .CollectionUtils ;
1815import com .meizu .push .sdk .utils .DateUtils ;
1916import com .meizu .push .sdk .utils .HttpClient ;
2017import 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 .*;
2919import org .slf4j .Logger ;
3020import org .slf4j .LoggerFactory ;
3121
3222import 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 ());
0 commit comments