// // 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 = this.cardService.proxyfindCard(); String stt = ""; for(int i = t; i < total; ++i) { ++numm; if (numm == 90) { stt = stt + ((Card)card.get(i)).getCardnumber(); } else { stt = stt + ((Card)card.get(i)).getCardnumber() + ","; } } System.out.println(stt); 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; System.out.println(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; 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"); 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")); // Date date = new Date(); // Date endDay=date1.parse(cardl.getEnddate());//结束时间 // Long starTime = date.getTime(); // Long endTime=endDay.getTime(); // Long num11=endTime-starTime;//时间戳相差的毫秒数 // cardl.setRemainingdays(+num11/24/60/60/1000+"天"); // cardl.setUptime(date1.format(calendar.getTime())); this.cardService.proxyupXinXi(cardl); } t += 90; total += 90; try { TimeUnit.SECONDS.sleep(12L); } catch (InterruptedException var59) { var59.printStackTrace(); } } int sheng = num % 90; List 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; System.out.println(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; 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("循环结束,等待定时器触发再次调用"); } }