| | |
| | | package com.ruoyi.project.system.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.getui.push.v2.sdk.ApiHelper; |
| | | import com.getui.push.v2.sdk.GtApiConfiguration; |
| | | import com.getui.push.v2.sdk.api.PushApi; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | |
| | | // 推送 |
| | | sendRoutingPush( |
| | | sysNotice.getNoticeId(), |
| | | client.getCid(), |
| | | sysNotice.getNoticeTitle(), |
| | | sysNotice.getRemark() != null ? sysNotice.getRemark() : sysNotice.getNoticeContent(), |
| | |
| | | /** |
| | | * 将 Web 端分层全路径转换为 App 端组件路由 |
| | | */ |
| | | private String convertWebPathToAppPath(String webPath) { |
| | | public String convertWebPathToAppPath(String webPath) { |
| | | if (StringUtils.isEmpty(webPath)) { |
| | | return DEFAULT_APP_PAGE; |
| | | } |
| | |
| | | queryString = webPath.substring(index); |
| | | } |
| | | |
| | | String[] pathSegments = pathOnly.split("/"); |
| | | String lastSegment = ""; |
| | | for (int i = pathSegments.length - 1; i >= 0; i--) { |
| | | if (StringUtils.isNotEmpty(pathSegments[i])) { |
| | | lastSegment = pathSegments[i]; |
| | | break; |
| | | } |
| | | String lastSegment; |
| | | int lastSlashIndex = pathOnly.lastIndexOf("/"); |
| | | if (lastSlashIndex != -1) { |
| | | lastSegment = pathOnly.substring(lastSlashIndex + 1); |
| | | } else { |
| | | lastSegment = pathOnly; |
| | | } |
| | | |
| | | if (StringUtils.isEmpty(lastSegment)) { |
| | |
| | | SysMenu menu = sysMenuMapper.selectMenuByPath(lastSegment); |
| | | |
| | | if (menu != null && StringUtils.isNotEmpty(menu.getAppComponent())) { |
| | | String appComponent = menu.getAppComponent(); |
| | | if (appComponent.startsWith("/")) { |
| | | appComponent = appComponent.substring(1); |
| | | String appPath = menu.getAppComponent(); |
| | | |
| | | if (appPath.startsWith("/")) { |
| | | appPath = appPath.substring(1); |
| | | } |
| | | return appComponent + queryString; |
| | | |
| | | // 拼接 Web 端原始参数并返回 |
| | | return appPath + queryString; |
| | | } |
| | | |
| | | return DEFAULT_APP_PAGE; |
| | |
| | | /** |
| | | * 发送单人路由推送 |
| | | */ |
| | | private void sendRoutingPush(String cid, String title, String content, String targetPath) { |
| | | log.info("准备推送消息: CID={}, Title={}, TargetPath={}", cid, title, targetPath); |
| | | private void sendRoutingPush(Long noticeId, String cid, String title, String content, String targetPath) { |
| | | log.info("准备推送消息:NoticeId={}, CID={}, Title={}, TargetPath={}", noticeId, cid, title, targetPath); |
| | | |
| | | PushDTO<Audience> pushDTO = new PushDTO<>(); |
| | | pushDTO.setRequestId("REQ_" + System.currentTimeMillis()); |
| | | |
| | | // 在线透传内容 |
| | | PushMessage pushMessage = new PushMessage(); |
| | | String transmissionContent = String.format( |
| | | "{\"title\":\"%s\",\"content\":\"%s\",\"payload\":\"%s\"}", |
| | | title, content, targetPath |
| | | ); |
| | | Map<String, Object> pushMessageMap = new HashMap<>(); |
| | | Map<String, Object> payloadMap = new HashMap<>(); |
| | | pushMessageMap.put("title", title); |
| | | pushMessageMap.put("content", content); |
| | | payloadMap.put("url", targetPath); |
| | | payloadMap.put("noticeId", noticeId); |
| | | pushMessageMap.put("payload", JSON.toJSONString(payloadMap)); |
| | | |
| | | String transmissionContent = JSON.toJSONString(pushMessageMap); |
| | | pushMessage.setTransmission(transmissionContent); |
| | | pushDTO.setPushMessage(pushMessage); |
| | | |
| | |
| | | pushDTO.setAudience(audience); |
| | | |
| | | // 离线推送通道 |
| | | pushDTO.setPushChannel(getPushChannel(title, content, targetPath)); |
| | | // pushDTO.setPushChannel(getPushChannel(noticeId, title, content, targetPath)); |
| | | |
| | | try { |
| | | ApiResult<Map<String, Map<String, String>>> result = pushApi.pushToSingleByCid(pushDTO); |
| | |
| | | } |
| | | |
| | | @NotNull |
| | | private PushChannel getPushChannel(String title, String content, String targetPath) { |
| | | private PushChannel getPushChannel(Long noticeId, String title, String content, String targetPath) { |
| | | PushChannel pushChannel = new PushChannel(); |
| | | AndroidDTO androidDTO = new AndroidDTO(); |
| | | Ups ups = new Ups(); |