admin
2021-07-22 5f9704c02fc61da33ed4d3db0d1172976e461089
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package com.ks.push.utils;
 
import com.ks.push.pojo.DO.BPushMessage;
import com.ks.push.pojo.DO.PushPlatform;
import org.yeshi.utils.push.*;
import org.yeshi.utils.push.entity.PushAppInfo;
import org.yeshi.utils.push.entity.PushMessage;
 
import java.util.List;
 
public class PushUtil {
 
    /**
     * 推送通知
     *
     * @param platform
     * @param appInfo
     * @param pushMessage
     * @param tokenList
     * @throws Exception
     */
    public static void pushNotifyCation(PushPlatform platform, PushAppInfo appInfo, BPushMessage pushMessage, List<String> tokenList) throws Exception {
        if (appInfo == null) {
            throw new Exception("应用参数为空");
        }
 
        if (pushMessage == null) {
            throw new Exception("消息为空");
        }
 
        if (tokenList == null || tokenList.size() == 0) {
            throw new Exception("token为空");
        }
        PushMessage message = new PushMessage(pushMessage.getTitle(), pushMessage.getContent(), pushMessage.getAndroidActivity(), pushMessage.getAndroidActivityScheme(), pushMessage.getAndroidHostPath(), pushMessage.getExtras());
 
        if (platform == PushPlatform.xm) {
            pushXM(appInfo, message, tokenList);
        } else if (platform == PushPlatform.hw) {
            pushHW(appInfo, message, tokenList);
        } else if (platform == PushPlatform.oppo) {
            pushOPPO(appInfo, message, tokenList);
        } else if (platform == PushPlatform.vivo) {
            pushVIVO(appInfo, message, tokenList);
        } else if (platform == PushPlatform.mz) {
            pushMZ(appInfo, message, tokenList);
        }
    }
 
    /**
     * 小米推送
     *
     * @param appInfo
     * @param message
     * @param tokenList
     * @throws Exception
     */
    private static void pushXM(PushAppInfo appInfo, PushMessage message, List<String> tokenList) throws Exception {
        XiaoMiPushUtil.pushNotificationByRegIds(appInfo, message, tokenList);
    }
 
    /**
     * 华为推送
     *
     * @param appInfo
     * @param message
     * @param tokenList
     * @throws Exception
     */
    private static void pushHW(PushAppInfo appInfo, PushMessage message, List<String> tokenList) throws Exception {
        HuaWeiPushUtil.pushNotificationByTokens(appInfo, message, tokenList);
    }
 
    /**
     * OPPO推送
     *
     * @param appInfo
     * @param message
     * @param tokenList
     * @throws Exception
     */
    private static void pushOPPO(PushAppInfo appInfo, PushMessage message, List<String> tokenList) throws Exception {
        OppoPushUtil.pushNotificationByRegIds(appInfo, message, tokenList);
    }
 
    /**
     * VIVO推送
     *
     * @param appInfo
     * @param message
     * @param tokenList
     * @throws Exception
     */
    private static void pushVIVO(PushAppInfo appInfo, PushMessage message, List<String> tokenList) throws Exception {
        VIVOPushUtil.pushNotificationByRegIds(appInfo, message, tokenList);
    }
 
    /**
     * 魅族推送
     *
     * @param appInfo
     * @param message
     * @param tokenList
     * @throws Exception
     */
    private static void pushMZ(PushAppInfo appInfo, PushMessage message, List<String> tokenList) throws Exception {
        MeiZuPushUtil.pushNotificationByPushId(appInfo, message, tokenList);
    }
 
 
}