package com.fs.qw;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fs.qw.config.QwConfig;
import com.hc.openapi.tool.codec.DigestUtils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

import static com.fs.qw.utils.QwUtil.sendQwHttp;

public class test1 {
    public static boolean verifyMD5(String input, String expectedMD5) {
        String actualMD5 = DigestUtils.md5Hex(input);

        return actualMD5.equals(expectedMD5);
    }

    public static void main(String[] args) {
//        String input = QwConfig.APP_KEY+QwConfig.APP_SECRET+"8da9d86b914148dc8bef35efee7b09f3"+"89483588a685426d83ccbf6f77ca567e";
//        String expectedMD5 = "a7281f88442b8f2c2d4a23c7eb087677";
//
//        boolean isVerified = verifyMD5(input, expectedMD5);
//        System.out.println("MD5 verification result: " + isVerified);

//        Instant instant = Instant.ofEpochSecond(1698817430L);
//        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//        System.out.println(localDateTime.format(formatter));

        String json = "[{\"avatar\":\"http://wx.qlogo.cn/mmhead/Q3auHgzwzM4qCB1MNA6PTO8MDXiavEEklbYx0BlX1uRP7KbleAg1rmw/0\",\"nickName\":\"RつE\",\"remark\":\"傻子\",\"userId\":7881300287915556},{\"avatar\":\"https://wework.qpic.cn/wwpic/352309_dDsF9RXLQq-f872_1692169234/0\",\"nickName\":\"张玉朋\",\"remark\":\"\",\"userId\":1688856679458971}]";

        JSONArray jsonArray = JSON.parseArray(json);
        StringBuilder nickNames = new StringBuilder();
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            if (jsonObject.getString("remark")!=null&&!jsonObject.getString("remark").equals("")){
                String nickName = jsonObject.getString("remark");
                if (i > 0) {
                    nickNames.append(",");
                }
                nickNames.append(nickName);
            }else {
                String nickName = jsonObject.getString("nickName");
                if (i > 0) {
                    nickNames.append(",");
                }
                nickNames.append(nickName);
            }
        }
        System.out.println("Combined nickNames: " + nickNames.toString());
    }
}
