yujian
2019-03-27 cdcbed9af813b2a02cdc01eefa24db8bec6b51a9
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
package com.yeshi.fanli.job;
 
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
 
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.factory.IOSPushFactory;
import com.yeshi.fanli.util.push.IOSPushUtil;
 
import net.sf.json.JSONObject;
 
@Component
public class PushJob {
 
    /**
     * 推送老版本IOS(每晚8点推送)
     */
    @Scheduled(cron = "0 0 20 * * ? ")
    public void pushOldIOS() {
        if (!Constant.IS_TASK)
            return;
        Scanner scanner = new Scanner(
                this.getClass().getClassLoader().getResourceAsStream("certificate/devicetoken.txt"));
        List<String> deviceList = new ArrayList<>();
        while (scanner.hasNext()) {
            deviceList.add(scanner.next().trim());
        }
        // 每次推送50条数据
        InputStream cer = null;
 
        int p = deviceList.size() / 50 + 1;
        JSONObject json = IOSPushFactory.createURLPush("https://0x9.me/TusaI", "返利券苹果端进行了重大更新!请立即升级",
                "更多优惠券,更高返利,尽在新版苹果端返利券!");
        for (int i = 0; i < p; i++) {
            cer = this.getClass().getClassLoader().getResourceAsStream("certificate/老版本-生产证书.p12");
            try {
                IOSPushUtil.pushIOS(
                        deviceList.subList(i * 50,
                                (i * 50 + 50) > deviceList.size() ? deviceList.size() : (i * 50 + 50)),
                        json, cer, "123");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 
}