admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package com.yeshi.fanli.util.push;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
 
import com.yeshi.fanli.entity.xinge.MessageInfo;
import com.yeshi.fanli.entity.xinge.PushRecord;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.push.PushService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
 
import net.sf.json.JSONObject;
 
public class PushUtils {
 
    @Resource
    private PushService pushService;
 
    /**
     * 小米全推
     * 
     * @param info
     * @param json
     * @param pushRecord
     * @return
     * @throws Exception
     */
    public static int allPushXiaoMi(MessageInfo info, JSONObject json, PushRecord pushRecord) throws Exception {
 
        if (Constant.IS_TEST)
            return 1;
 
        JSONObject mapXm = JSONObject.fromObject(json);
        String android = XiaoMiPushUtil.allPushAndroidForXM(info, mapXm);
 
        LogHelper.userInfo("安卓推送测试:" + android);
        pushRecord.setAndroidPushId(android);
 
        if (android != null) {
            return 1;
        } else {
            return 4;
        }
    }
 
    /**
     * IOS 全推送
     * 
     * @param info
     * @param json
     * @param pushRecord
     * @param type
     * @param deviceTokenList
     * @return
     * @throws Exception
     */
    public static int allPushIOS(MessageInfo info, PushRecord pushRecord, String url, int type,
            List<String> deviceTokenList) throws Exception {
 
        /*
         * com.yeshi.fanli.entity.system.System b_IOS =
         * systemService.getSystem("IOS",
         * Constant.systemCommonConfig.getIosBundleId());
         */
 
        if (Constant.IS_TEST)
            return 1;
 
        String IOS = IOSPushUtil.allPushIOS(deviceTokenList, info, url, type);
        LogHelper.userInfo("IOS的推送日志:" + IOS);
        pushRecord.setIosPushId(IOS);
 
        if (IOS != null) {
            return 1;
        } else {
            return 4;
        }
    }
 
    /**
     * 小米单推
     * 
     * @param info
     * @param json
     * @return
     */
    public static int singlePushXiaoMi(MessageInfo info, JSONObject json,List<String> regIds, PushRecord pushRecord) {
//        if (Constant.IS_TEST)
//            return 1;
 
        JSONObject mapXm = JSONObject.fromObject(json);
 
        String android = XiaoMiPushUtil.singlePushAndroidForXM(info, mapXm,regIds, null);
 
        LogHelper.userInfo("安卓推送测试:" + android);
        pushRecord.setAndroidPushId(android);
 
        if (android != null) {
            return 1;
        } else {
            return 4;
        }
    }
 
    public static int singlePushXiaoMiByRegisterId(MessageInfo info, JSONObject json, PushRecord pushRecord,
            String regId) {
        if (Constant.IS_TEST)
            return 1;
 
        JSONObject mapXm = JSONObject.fromObject(json);
 
        List<String> regIdList = new ArrayList<>();
        regIdList.add(regId);
        String android = XiaoMiPushUtil.pushBatchAndroidForXM(info, mapXm, regIdList);
 
        LogHelper.userInfo("安卓推送测试:" + android);
        pushRecord.setAndroidPushId(android);
 
        if (android != null) {
            return 1;
        } else {
            return 4;
        }
    }
 
    /**
     * IOS 单推
     * 
     * @param info
     * @param url
     * @param type
     * @param deviceTokenList
     * @return
     */
    public static String singlePushIOS(MessageInfo info, PushRecord pushRecord, String url, int type,
            List<String> deviceTokenList) {
        if (Constant.IS_TEST)
            return null;
        if (deviceTokenList != null && deviceTokenList.size() > 0) {
            for (String deviceToken : deviceTokenList) {
                if (!StringUtil.isNullOrEmpty(deviceToken)) {
                    try {
                        List<String> deviceList = new ArrayList<>();
                        deviceList.add(deviceToken);
                        String IOS = IOSPushUtil.allPushIOS(deviceList, info, url, type);
                        pushRecord.setIosPushId(IOS);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
 
            }
        }
 
        return null;
    }
 
}