package me.zhengjie.utils;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;

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

public class MessageSendUtils {

    /**
     * 发送IM信息
     * @param sendId    子系统发送的关联id
     * @param sendUserId    发送userId
     * @param text    发送的内容
     * @param usernames     接收信息者账号 多个以,隔开
     */
    public static void sendChatMessage(String sendId, String sendUserId, String text, String usernames){
        Map<String,Object> token = SecurityUtils.getToken("DMERPYT!@#$QWER2021+{:>");
        JSONObject query = new JSONObject();
        query.put("systemName","一卡通系统");
        query.put("sendId",sendId);//taskId
        query.put("sendUserId",sendUserId);
        JSONObject sendContentJSON = new JSONObject();
        sendContentJSON.put("text",text);
        query.put("sendContent",sendContentJSON);
        query.put("usernames",usernames);
        JSONObject param = new JSONObject();
        param.put("nonce",token.get("nonce"));
        param.put("timestamp",token.get("timestamp"));
        param.put("query",query);
        HttpRequest.get("https://smartpark.caih.com/zkxt/api/thirdparty/v1/message/sendChatMessage").header("XYTACCESSTOKEN", token.get("token").toString()).body(param.toJSONString()).execute().body();
    }

    /**
     * 发送IM信息
     * @param phone    接收手机号
     * @param context    发送内容
     */
    public static void sendMsg(String phone, String context){
        Map<String,Object> token = SecurityUtils.getToken("DMERPYT!@#$QWER2021+{:>");
        //短信通知
        String msgUrl = "https://smartpark.caih.com/zkxt/api/thirdparty/v1/message/sendMsg";
        JSONObject query = new JSONObject();
        query.put("phone",phone);
        query.put("context",context);
        JSONObject param = new JSONObject();
        param.put("nonce",token.get("nonce"));
        param.put("timestamp",token.get("timestamp"));
        param.put("query",query);
        HttpRequest.get(msgUrl).header("XYTACCESSTOKEN", token.get("token").toString()).body(param.toJSONString()).execute().body();
    }

}
