fei.wang
2024-03-21 ab64b09ce3020b376af1e6ee0326ea71330d34ad
src/main/java/com/flow/quartz/MyJob.java
@@ -9,6 +9,7 @@
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;
@@ -28,6 +29,7 @@
import java.util.concurrent.TimeUnit;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.springframework.beans.factory.annotation.Autowired;
public class MyJob {
@@ -48,7 +50,7 @@
        int length = 30;
        Random random = new Random();
        for(int i = length; i > 0; --i) {
        for (int i = length; i > 0; --i) {
            int index = random.nextInt(str.length());
            nonce = nonce + str.charAt(index);
        }
@@ -61,7 +63,7 @@
        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();
        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");
@@ -74,7 +76,7 @@
        StringBuilder response1 = new StringBuilder();
        String line;
        while((line = reader.readLine()) != null) {
        while ((line = reader.readLine()) != null) {
            response1.append(line);
        }
@@ -87,7 +89,7 @@
        int total1 = result.getInt("total");
        JSONArray list = result.getJSONArray("list");
        System.out.println("定时器执行成功!更新数据");
        int num = total1;
        int num = total1;  //第三方所有卡号
        int t = 0;
        int total = 90;
        int num1 = 0;
@@ -99,25 +101,28 @@
        String stringSignTemp1;
        String line1;
        String stt1;
        while(numm < num) {
        while (numm < num) {
            ++num1;
            System.out.println("第" + num1 + "次调用接口从" + t + "到" + total + "结束:总条数" + num);
            List<Card> card = this.cardService.proxyfindCard();
            String stt = "";
            String stt = ""; //从数据库查询的卡号
            for(int i = t; i < total; ++i) {
            for (int i = t; i < total; ++i) {
                ++numm;
                if (numm == 90) {
                    stt = stt + ((Card)card.get(i)).getCardnumber();
                    stt = stt + ((Card) card.get(i)).getCardnumber();
                } else {
                    stt = stt + ((Card)card.get(i)).getCardnumber() + ",";
                    if (card.size() <= i) {
                        break;
                    } else {
                        stt = stt + ((Card) card.get(i)).getCardnumber() + ",";
                    }
                }
            }
            System.out.println(stt);
            stt1 = "";
            for(int i = length; i > 0; --i) {
            for (int i = length; i > 0; --i) {
                index = random.nextInt(str.length());
                stt1 = stt1 + str.charAt(index);
            }
@@ -126,13 +131,13 @@
            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;
            stringSignTemp1 = stringSignTemp1 + "?cNo=" + stt.replaceAll("\\s+", "");
            URL url1 = new URL(stringSignTemp1);
            HttpURLConnection connection1 = (HttpURLConnection)url1.openConnection();
            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");
@@ -145,7 +150,7 @@
            StringBuilder response11 = new StringBuilder();
            while((line1 = reader1.readLine()) != null) {
            while ((line1 = reader1.readLine()) != null) {
                response11.append(line1);
            }
@@ -157,120 +162,114 @@
            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);
            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;
            }
            t += 90;
            total += 90;
            try {
                TimeUnit.SECONDS.sleep(12L);
            } catch (InterruptedException var59) {
                var59.printStackTrace();
            }
        }
        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;
        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);
        }
//
//        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("循环结束,等待定时器触发再次调用");
    }