skjcmanager/skjcmanager-service/skjcmanager-alerts/src/main/java/cn/gistack/alerts/push/controller/PushController.java
@@ -27,7 +27,7 @@ } /** * 通过用户id推送消息,用于测试 * 通过用户id推送消息,用于2.0测试 * @param pushVO * @return */ skjcmanager/skjcmanager-service/skjcmanager-alerts/src/main/java/cn/gistack/alerts/push/service/impl/PushServiceImpl.java
@@ -14,16 +14,13 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.*; @Service @AllArgsConstructor public class PushServiceImpl implements IPushService { private static final String PUSH_CLIENT_ID = "push:client:id:"; private static final String UNI_CLOUD_PUSH_URL = "https://fc-mp-ad1ed7e3-700e-4fca-abae-0d097cc222b5.next.bspapp.com/push"; private static final String UNI_CLOUD_PUSH_URL = "https://fc-mp-ff11cc4d-ca8e-4b47-a57f-e26804379530.next.bspapp.com/push"; private BladeRedis bladeRedis; private IMessageClient messageClient; @@ -38,7 +35,7 @@ @Override public Boolean pushMessageList(List<MessageRecord> messageRecordList) { // 加入测试人员 addSendMsgTest(messageRecordList); // addSendMsgTest(messageRecordList); PushVO pushVO = new PushVO(); List<String> cIdList = new ArrayList<>(); //相同的消息推送给多用户 @@ -51,7 +48,7 @@ pushVO.setTitle(messageRecordList.get(0).getTheme()); pushVO.setContent(messageRecordList.get(0).getContent()); return geTuiUtils.pushMsg(pushVO.getCIds(),pushVO.getTitle(),pushVO.getContent()); return pushMessage(pushVO); } /** @@ -115,10 +112,10 @@ @Override public Boolean geTuiPushMessage(PushVO pushVO) { List<String> cIdList = new ArrayList<>(); cIdList.add(getClientIdByUserId(pushVO.getUserId())); return geTuiUtils.pushMsg(cIdList, pushVO.getTitle(), pushVO.getContent()); // return geTuiUtils.pushMsg(cIdList, pushVO.getTitle(), pushVO.getContent()); return geTuiUtils.myPushMessage(cIdList, pushVO.getTitle(), pushVO.getContent()); } /** @@ -128,17 +125,14 @@ * @return */ public String getClientIdByUserId(String userId) { if (Func.isEmpty(userId)) { throw new ServiceException("请填写用户id!"); } return bladeRedis.get(PUSH_CLIENT_ID + userId); } /** * 消息推送 * 2.0云函数消息推送 * * @param pushVO * @return @@ -148,14 +142,16 @@ RestTemplate template = new RestTemplate(); Map<String, Object> params = new LinkedHashMap<>(); //用户cId,可数组,可字符串 params.put("push_clientid", pushVO.getCIds()); params.put("pushClientid", pushVO.getCIds()); //标题 params.put("title", pushVO.getTitle()); //内容 params.put("content", pushVO.getContent()); params.put("requestId", UUID.randomUUID()); // UniCloudReturnRes uniCloudReturnRes = template.getForObject(UNI_CLOUD_PUSH_URL,UniCloudReturnRes.class,params); UniCloudReturnRes uniCloudReturnRes = template.postForObject(UNI_CLOUD_PUSH_URL, params, UniCloudReturnRes.class); return uniCloudReturnRes.getErrCode().equals(0) ? true : false; return uniCloudReturnRes.getErrCode().equals("0") ? true : false; } } skjcmanager/skjcmanager-service/skjcmanager-alerts/src/main/java/cn/gistack/alerts/push/utils/GeTuiUtils.java
@@ -33,6 +33,8 @@ @Resource(name = "myPushApi") private PushApi myPushApi; private final String APP_PACKAGE_NAME = "com.hubei.jingchuReservoir"; /** * 单点推送(离线不推送) * @@ -158,6 +160,8 @@ IosDTO iosDTO = new IosDTO(); iosDTO.setAps(aps); iosDTO.setType("notify"); PushChannel pushChannel = new PushChannel(); pushChannel.setIos(iosDTO); //安卓离线厂商通道推送消息体 @@ -265,4 +269,100 @@ System.out.println("code:" + apiResult.getCode() + ", msg: " + apiResult.getMsg()); } } /** * 自定义消息批量推送,支持离线和在线推送 * @param cids * @param title * @param content */ public Boolean myPushMessage(List<String> cids,String title,String content){ List<PushDTO<Audience>> list = new ArrayList<>(cids.size()); cids.forEach(cid -> { PushDTO<Audience> pushDTO = new PushDTO<>(); /**设置个推通道**/ // 唯一标识 pushDTO.setRequestId(UUID.randomUUID().toString()); // 消息内容 PushMessage pushMessage = new PushMessage(); //0无限制、1仅wifi pushMessage.setNetworkType(0); GTNotification gtNotification = new GTNotification(); pushMessage.setNotification(gtNotification); gtNotification.setTitle(title); gtNotification.setBody(content); gtNotification.setClickType("none"); pushDTO.setPushMessage(pushMessage); // 消息接受人 Audience audience = new Audience(); audience.addCid(cid); pushDTO.setAudience(audience); /**设置个推通道结束**/ //配置推送条件 // 1: 表示该消息在用户在线时推送个推通道,用户离线时推送厂商通道; // 2: 表示该消息只通过厂商通道策略下发,不考虑用户是否在线; // 3: 表示该消息只通过个推通道下发,不考虑用户是否在线; // 4: 表示该消息优先从厂商通道下发,若消息内容在厂商通道代发失败后会从个推通道下发。 Strategy strategy = new Strategy(); strategy.setDef(1); Settings settings = new Settings(); settings.setStrategy(strategy); pushDTO.setSettings(settings); settings.setTtl(3600000);//消息有效期,走厂商消息需要设置该值 /**设置厂商通道**/ PushChannel pushChannel = new PushChannel(); /**设置Android配置**/ AndroidDTO androidDTO = new AndroidDTO(); Ups ups = new Ups(); ThirdNotification notification1 = new ThirdNotification(); ups.setNotification(notification1); notification1.setTitle(title);//安卓离线展示的标题 notification1.setBody(content);//安卓离线展示的内容 notification1.setClickType("intent"); notification1.setIntent("intent:#Intent;launchFlags=0x04000000;action=android.intent.action.oppopush;component=com.hubei.jingchuReservoir/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title="+title +";S.content="+content+";S.payload=test;end"); //对不同厂商进行配置 // ups.addOption("HW", "/message/android/notification/badge/class", "io.dcloud.PandoraEntry "); ups.addOption("VV","/networkType",-1); androidDTO.setUps(ups); pushChannel.setAndroid(androidDTO); /**设置Android配置结束**/ /**设置IOS配置**/ //推送苹果离线通知标题内容 Alert alert = new Alert(); alert.setTitle(title);//苹果离线通知栏标题 alert.setBody(content);//苹果离线通知栏内容 Aps aps = new Aps(); //1表示静默推送(无通知栏消息),静默推送时不需要填写其他参数。 //苹果建议1小时最多推送3条静默消息 aps.setContentAvailable(0); aps.setSound("default"); aps.setAlert(alert); IosDTO iosDTO = new IosDTO(); iosDTO.setAps(aps); iosDTO.setType("notify"); pushChannel.setIos(iosDTO); /**设置IOS配置结束**/ pushDTO.setPushChannel(pushChannel); /**设置厂商通道结束**/ list.add(pushDTO); }); PushBatchDTO pushBatchDTO = new PushBatchDTO(); pushBatchDTO.setAsync(true); pushBatchDTO.setMsgList(list); //推送消息 ApiResult<Map<String, Map<String, String>>> mapApiResult = myPushApi.pushBatchByCid(pushBatchDTO); return mapApiResult.isSuccess(); } } skjcmanager/skjcmanager-service/skjcmanager-alerts/src/main/java/cn/gistack/alerts/push/vo/UniCloudReturnRes.java
@@ -9,7 +9,7 @@ private Object data; private Integer errCode; private String errCode; private String errMsg;