package com.izouma.wenlvju.service;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.izouma.wenlvju.ApplicationTests;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;


public class EzvizTokenServiceTest extends ApplicationTests {

    @Autowired
    private EzvizTokenService ezvizTokenService;

    @Test
    public void getToken() {
        System.out.println(ezvizTokenService.getToken());
    }

    @Test
    public void test() {
        System.out.println(DateUtil.date(1624525723010L));
        System.out.println(Convert.toLocalDateTime(1624525723010L));
    }

    @Test
    public void test1() {
//        String str = "{\"msg\":\"操作成功!\",\"code\":\"200\",\"data\":{\"accessToken\":\"at.4jrsvi0u34xzz9rs8mz3uj04bzn489q6-230iyqmr9e-0yn79qd-7ezu9nfog\",\"expireTime\":1624525723010}}";
//
//        JSONObject json = JSONObject.parseObject(str);
//        String code = json.getString("code");
//        System.out.println(code);
//        JSONObject data = json.getJSONObject("data");
//        System.out.println(data.getString("accessToken"));
//        System.out.println(data.getLong("expireTime"));

        String str = "{\"msg\":\"操作成功!\",\"code\":\"200\",\"data\":[{\"id\":\"00da84fe3e2043389be46ab4c3fd133eF75663984\",\"deviceSerial\":\"F75663984\",\"deviceName\":\"C6C(F75663984)\",\"deviceType\":\"CS-C6C-3H3WFRV\",\"status\":1,\"defence\":0,\"deviceVersion\":\"V5.3.4 build 201107\",\"addTime\":1621311282892,\"updateTime\":1622603978000,\"parentCategory\":\"IPC\"}],\"page\":{\"total\":1,\"size\":10,\"page\":0}}";
        JSONObject json = JSONObject.parseObject(str);
//        String code = json.getString("code");
//        System.out.println(code);
        JSONArray data = JSONObject.parseArray(json.getString("data"));
        System.out.println(data);
        for (int i = 0; i < data.size(); i++) {
            JSONObject jsonObject = data.getJSONObject(i);
            String name = jsonObject.getString("deviceSerial");
            System.out.println(name);
        }
    }
}