野狗实时通讯Utils

野狗官网:https://www.wilddog.com/

野狗实时通讯使用步骤
1.注册野狗
2.创建应用
野狗实时通讯Utils
3.使用工具类添加数据,数据结构
野狗实时通讯Utils
4.野狗工具类
4.1 "test"是上传路径设置,还有相同的.child(“paht”)也可以设置路径

SyncReference myRef = WilddogSync.getInstance().getReference("test");
/**
 * 野狗推送工具类
 */
public class WilddogUtils {
    private static final Logger logger = LoggerFactory.getLogger(WilddogUtils.class);

 	/**
 	* 数据添加
 	*/
    public static Boolean add(JSONObject params) {
        //json格式组装(这一步可以选择传入参数的方法)
        JSONObject params = new JSONObject();
        params.put("code",200);
        params.put("message","调用成功");
        JSONObject data = new JSONObject();
        data.put("longitude","118.163926");
        data.put("latitude","24.477643");
        params.put("data",data);
        //初始化野狗组件
        WilddogOptions options = new WilddogOptions.Builder().setSyncUrl(ErpConfiguration.getErpConfiguration().getWilddogUrl()).build();
        WilddogApp.initializeApp(options);
        //同步参数设置
        SyncReference myRef = WilddogSync.getInstance().getReference("test");
        myRef.setValue(params);
    }

    /**
     * 根据url,获取野狗上的存储资源
     * @param dispatch_id
     * @return
     */
    public static JSONObject getDispatchDistance() {
        try {
            HttpResponse response = HttpUtils.doGet("https://wd3644337152ffntoj.wilddogio.com/test.json");
            BufferedReader b = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"),8*1024);
            String line=b.readLine();

            JSONObject resultObj = JSONObject.parseObject(line);
            if (null == resultObj){
                throw new BussinessException("调用接口失败");
            }
            Integer code = resultObj.getInteger("code");
            if (200 != code) {
                throw new BussinessException(resultObj.getString("message"));
            }
            return resultObj.getJSONObject("data");
        } catch (Exception e) {
            throw new BussinessException("调用接口失败");
        }
    }

}