package me.zhengjie.modules.dm.messageSendLog.util;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.base.BaseResponse;
import me.zhengjie.modules.dm.messageSendLog.domain.DmMessageSendLog;
import me.zhengjie.modules.dm.messageSendLog.service.DmMessageSendLogService;
import me.zhengjie.utils.StringUtils;

@Slf4j
public class SendMessageUtils {

    private static String erpapiUrl = "http://222.84.157.37:25894";

    /**
     * 发送
     */
    public static Boolean sendChatMessage(DmMessageSendLog dmMessageSendLog){
        String url = "/api-im-logic/busi/im/logic/c2c/sendChatMessage";
        //组装erp发送信息接口请求参数
        JSONObject bodyJSON = new JSONObject();
        bodyJSON.put("clientId","yw");
        bodyJSON.put("token","9cc3dbc9-415a-479f-a03a-cbe15412875b");
        bodyJSON.put("payload",dmMessageSendLog.getSendContent());
        bodyJSON.put("payloadType","text");
        bodyJSON.put("messageFrom","usky");
        bodyJSON.put("messageTo",dmMessageSendLog.getUsernames());
        log.info("bodyJSON:"+bodyJSON.toJSONString());
        String res = HttpRequest.get(erpapiUrl+url)
                .header("serviceId", "USky")
                .header("serviceUserId",dmMessageSendLog.getSendUserId())
                .body(bodyJSON.toJSONString()).execute().body();
        JSONObject json = JSONObject.parseObject(res);
        log.info("json:"+json);
        String code = json.getString("code");
        if(StringUtils.equals("0000",code)){
            return true;
        } else {
            return false;
        }
    }

}
