fei.wang
2024-05-13 b9b58b9ef261cb290d93465f88a2cbd814b576f0
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
 
package com.flow.quartz;
 
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.flow.pojo.Card;
import com.flow.service.CardService;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Base64;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
 
import org.springframework.beans.factory.annotation.Autowired;
 
public class MyJob {
    @Autowired
    CardService cardService;
 
    public MyJob() {
    }
 
    public void execute() throws NoSuchAlgorithmException, InvalidKeyException, IOException, ParseException {
        String accessKey = "448c2cedcdce41428a290d144e81ab6e";
        String str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String accessSecret = "RgoIWycMYGmQfrLwLuT2VWawAhwMO8w7P9zh2dZp";
        String nonce = "";
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String Timestamp = dateFormat.format(now);
        int length = 30;
        Random random = new Random();
 
        for (int i = length; i > 0; --i) {
            int index = random.nextInt(str.length());
            nonce = nonce + str.charAt(index);
        }
 
        String stringSignTemp = accessKey + nonce + Timestamp;
        Mac sha256Hmac = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKeySpec = new SecretKeySpec(accessSecret.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
        sha256Hmac.init(secretKeySpec);
        byte[] hmacBytes = sha256Hmac.doFinal(stringSignTemp.getBytes(StandardCharsets.UTF_8));
        String sign = Base64.getEncoder().encodeToString(hmacBytes);
        String targetUrl = "https://api.spruceiot.cn/api/v1/sim/list/query?pageIndex=1&pageSize=10";
        URL url = new URL(targetUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("Accept-Charset", "UTF-8");
        connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        connection.setRequestProperty("Access-Control-Allow-Origin", "http://localhost:8080");
        connection.setRequestProperty("AccessKey", accessKey);
        connection.setRequestProperty("Nonce", nonce);
        connection.setRequestProperty("Timestamp", Timestamp);
        connection.setRequestProperty("Sign", sign);
        connection.connect();
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        StringBuilder response1 = new StringBuilder();
 
        String line;
        while ((line = reader.readLine()) != null) {
            response1.append(line);
        }
 
        reader.close();
        connection.disconnect();
        JSONObject jsonObject = new JSONObject(response1);
        int code = jsonObject.getInt("code");
        String message = jsonObject.getStr("message");
        JSONObject result = jsonObject.getJSONObject("result");
        int total1 = result.getInt("total");
        JSONArray list = result.getJSONArray("list");
        System.out.println("定时器执行成功!更新数据");
        int num = total1;  //第三方所有卡号
        int t = 0;
        int total = 90;
        int num1 = 0;
        int numm = 0;
 
        int index;
        String nonce1;
        String Timestamp1;
        String stringSignTemp1;
        String line1;
        String stt1;
        while (numm < num) {
            ++num1;
            System.out.println("第" + num1 + "次调用接口从" + t + "到" + total + "结束:总条数" + num);
            List<Card> card = this.cardService.proxyfindCard();
            String stt = ""; //从数据库查询的卡号
 
            for (int i = t; i < total; ++i) {
                ++numm;
                if (numm == 90) {
                    stt = stt + ((Card) card.get(i)).getCardnumber();
                } else {
                    if (card.size() <= i) {
                        break;
                    } else {
                        stt = stt + ((Card) card.get(i)).getCardnumber() + ",";
                    }
 
                }
            }
            stt1 = "";
 
            for (int i = length; i > 0; --i) {
                index = random.nextInt(str.length());
                stt1 = stt1 + str.charAt(index);
            }
 
            Date now1 = new Date();
            SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyyMMddHHmmss");
            nonce1 = dateFormat1.format(now1);
            stringSignTemp1 = accessKey + stt1 + nonce1;
 
            byte[] hmacBytes1 = sha256Hmac.doFinal(stringSignTemp1.getBytes(StandardCharsets.UTF_8));
            Timestamp1 = Base64.getEncoder().encodeToString(hmacBytes1);
            stringSignTemp1 = "https://api.spruceiot.cn/api/v1/sim/detail/batch/query";
            stringSignTemp1 = stringSignTemp1 + "?cNo=" + stt.replaceAll("\\s+", "");
            URL url1 = new URL(stringSignTemp1);
            HttpURLConnection connection1 = (HttpURLConnection) url1.openConnection();
            connection1.setRequestProperty("Accept-Charset", "UTF-8");
            connection1.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
            connection1.setRequestProperty("Access-Control-Allow-Origin", "http://localhost:8080");
            connection1.setRequestProperty("AccessKey", accessKey);
            connection1.setRequestProperty("Nonce", stt1);
            connection1.setRequestProperty("Timestamp", nonce1);
            connection1.setRequestProperty("Sign", Timestamp1);
            connection1.connect();
            BufferedReader reader1 = new BufferedReader(new InputStreamReader(connection1.getInputStream(), "UTF-8"));
            StringBuilder response11 = new StringBuilder();
 
 
            while ((line1 = reader1.readLine()) != null) {
                response11.append(line1);
            }
 
            reader1.close();
            connection1.disconnect();
            JSONObject jsonObject1 = new JSONObject(response11);
            int code1 = jsonObject1.getInt("code");
            line1 = jsonObject1.getStr("message");
            JSONArray resultArray = jsonObject1.getJSONArray("result");
            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat date1 = new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
            if (resultArray!=null) {
                for (int i = 0; i < resultArray.size(); ++i) {
                    Card cardl = new Card();
                    JSONObject item1 = resultArray.getJSONObject(i);
                    cardl.setCardnumber(item1.getStr("iccid"));
                    cardl.setOperator(item1.getStr("operators"));
                    cardl.setCarddate(item1.getStr("serviceStartDate"));
                    cardl.setEnddate(item1.getStr("serviceEndDate"));
                    cardl.setEnterdate(item1.getStr("serviceStartDate"));
                    cardl.setZflow(item1.getInt("dataLimit"));
                    cardl.setSyflow(item1.getInt("dataUsage"));
                    cardl.setSyll(item1.getInt("dataLimit") - item1.getInt("dataUsage"));
                    cardl.setStatus(item1.getStr("status"));
                    cardl.setIccid(item1.getStr("msisdn"));
                    this.cardService.proxyupXinXi(cardl);
                }
                t += 90;
                total += 90;
                try {
                    TimeUnit.SECONDS.sleep(12L);
                } catch (InterruptedException var59) {
                    var59.printStackTrace();
                }
            }else{
                break;
            }
 
        }
//
//        int sheng = num % 90;
//        List<Card> card = this.cardService.proxyfindCard();
//        stt1 = "";
//        int i = 0;
//        index = sheng - 1;
//
//        for (int j = num - sheng; j < num - 1; ++j) {
//            ++i;
//            if (i == index) {
//                stt1 = stt1 + ((Card) card.get(j)).getCardnumber();
//            } else {
//                stt1 = stt1 + ((Card) card.get(j)).getCardnumber() + ",";
//            }
//        }
//
//        nonce1 = "";
//
//        for (i = length; i > 0; --i) {
//            index = random.nextInt(str.length());
//            nonce1 = nonce1 + str.charAt(index);
//        }
//
//        Date now1 = new Date();
//        SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyyMMddHHmmss");
//        Timestamp1 = dateFormat1.format(now1);
//        stringSignTemp1 = accessKey + nonce1 + Timestamp1;
//        byte[] hmacBytes1 = sha256Hmac.doFinal(stringSignTemp1.getBytes(StandardCharsets.UTF_8));
//        String sign1 = Base64.getEncoder().encodeToString(hmacBytes1);
//        String targetUrl1 = "https://api.spruceiot.cn/api/v1/sim/detail/batch/query";
//        targetUrl1 = targetUrl1 + "?cNo=" + stt1.replaceAll("\\s+", "");
//        URL url1 = new URL(targetUrl1);
//        HttpURLConnection connection1 = (HttpURLConnection) url1.openConnection();
//        connection1.setRequestProperty("Accept-Charset", "UTF-8");
//        connection1.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
//        connection1.setRequestProperty("Access-Control-Allow-Origin", "http://localhost:8080");
//        connection1.setRequestProperty("AccessKey", accessKey);
//        connection1.setRequestProperty("Nonce", nonce1);
//        connection1.setRequestProperty("Timestamp", Timestamp1);
//        connection1.setRequestProperty("Sign", sign1);
//        connection1.connect();
//        BufferedReader reader1 = new BufferedReader(new InputStreamReader(connection1.getInputStream(), "UTF-8"));
//        StringBuilder response11 = new StringBuilder();
//
//        while ((line1 = reader1.readLine()) != null) {
//            response11.append(line1);
//        }
//
//        reader1.close();
//        connection1.disconnect();
//        JSONObject jsonObject1 = new JSONObject(response11);
//        int code1 = jsonObject1.getInt("code");
//        String message1 = jsonObject1.getStr("message");
//        JSONArray resultArray = jsonObject1.getJSONArray("result");
//        Calendar calendar = Calendar.getInstance();
//        SimpleDateFormat date2 = new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
//
//        for (i = 0; i < resultArray.size(); ++i) {
//            Card cardl = new Card();
//            JSONObject item1 = resultArray.getJSONObject(i);
//            cardl.setCardnumber(item1.getStr("iccid"));
//            cardl.setOperator(item1.getStr("operators"));
//            cardl.setCarddate(item1.getStr("serviceStartDate"));
//            cardl.setEnddate(item1.getStr("serviceEndDate"));
//            cardl.setEnterdate(item1.getStr("serviceStartDate"));
//            cardl.setZflow(item1.getInt("dataLimit"));
//            cardl.setSyflow(item1.getInt("dataUsage"));
//            cardl.setStatus(item1.getStr("status"));
//            cardl.setIccid(item1.getStr("msisdn"));
//            cardl.setSyll(item1.getInt("dataLimit") - item1.getInt("dataUsage"));
//
////            Date date = new Date();
////            Date endDay=date2.parse(cardl.getEnddate());//结束时间
////            Long starTime = date.getTime();
////            Long endTime=endDay.getTime();
////            Long num11=endTime-starTime;//时间戳相差的毫秒数
////            cardl.setRemainingdays(+num11/24/60/60/1000+"天");
////            cardl.setUptime(date2.format(calendar.getTime()));
//            this.cardService.proxyupXinXi(cardl);
//        }
 
        System.out.println("循环结束,等待定时器触发再次调用");
    }
}