package io.geekidea.springbootplus.test;

import cn.hutool.crypto.digest.MD5;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.wecloud.im.tillo.app_ws.model.request.ReceiveModel;

import java.util.Date;

/**
 * 生成测试appkey与appSecret对,并存入数据库
 */
//@RunWith(SpringJUnit4ClassRunner.class)
//@SpringBootTest
public class SignTest {

//    @Autowired
//    private ImClientService imClientService;

    /**
     * 获取sign,客户端sdk得到sign之后就可以进行登录 和开启websocket
     * <p>
     * sign = MD5{ clientId + AppKey + appSecret}
     *
     * @param AppKey
     * @param appSecret
     */
    private static void getSign(String timestemp, String clientId, String AppKey, String appSecret) {

        String sign = new MD5().digestHex(timestemp + clientId + AppKey + appSecret);

        System.out.println("timestemp:" + timestemp);
        System.out.println("sign:" + sign);

    }

    public static void main(String[] args) throws JsonProcessingException {
        String clientId = "c1";
        String appKey = "elLwpel1gWCHDqZy";
        String appSecret = "68809bb5a9077a83631aeb0b17b5965d6b2302faf2ab3737";
        String timestemp = String.valueOf(new Date().getTime());
        getSign(timestemp, clientId, appKey, appSecret);
        jsonTest();
    }

    private static void jsonTest() throws JsonProcessingException {
        String data = "{\n" +
                "\"reqId\":\"123123\",\n" +
                "\"cmd\":1,\n" +
                "\"data\":{\n" +
                "    \"type\":-1,\n" +
                "    \"text\":\"这是一个纯文本消息\",\n" +
                "    \"attrs\":{\n" +
                "    \"a\":\"attrs 是用来存储用户自定义的一些键值对\"}}\n" +
                "}\n";

        // json转换成对象
        JsonMapper jsonMapper = new JsonMapper();
        ReceiveModel receiveModel = jsonMapper.readValue(data, ReceiveModel.class);

        // data对象转换成json
        ObjectMapper objectMapper = new ObjectMapper();
        String s = objectMapper.writeValueAsString(receiveModel.getData());
    }


}
