package com.ruoyi.common.utils.goeasy;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.goeasy.GoEasy;
import io.goeasy.publish.GoEasyError;
import io.goeasy.publish.PublishListener;

public class GoEasyUtils {

    static String regionHost = "https://rest-hz.goeasy.io";

    static String appkey = "BC-d4519ea15c3f4d67a0d923dc980cbdac";

    public static void main(String[] args) {
        //sendGoeasy("689191586282475520",1,"");


        String channel = "";

        String str = "https://rest-hz.goeasy.io/v2/pubsub/presence/herenow?appkey="+appkey+"&channel="+channel+"&limit=10";

        HttpUtil.get(str);


    }


    /**
     * 发送消息
     * @param userId
     * @param code
     * @param data
     */
    public static void sendGoeasy(String userId,Integer code,String data){

        GoEasyVo goEasyVo = new GoEasyVo();
        goEasyVo.setCode(code);
        goEasyVo.setData(data);
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(goEasyVo));

        //新加坡rest-host：rest-singapore.goeasy.io
        GoEasy goEasy = new GoEasy(regionHost, appkey);
        goEasy.publish(userId, String.valueOf(jsonObject),new PublishListener(){
            @Override
            public void onSuccess() {
                System.out.println("Publish success.");
            }
            @Override
            public void onFailed(GoEasyError error) {
                System.out.println("Failed to Publish message, error:" + error.getCode() + " , " + error.getContent());
            }
        });
    }
}
