com.blade.kit.json.JSONObject.put() - java examples

Here are the examples of the java api com.blade.kit.json.JSONObject.put() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

7 Examples 7

18 View Complete Implementation : WechatApp.java
Copyright Apache License 2.0
Author : Zhyblx
/**
 * 微信状态通知
 */
public boolean wxStatusNotify() {
    String Url = this.BASE_URL + WechatInterface.WXSTATUS_CODE + this.Preplaced_TICKET;
    JSONObject body = new JSONObject();
    body.put("BaseRequest", BaseRequest);
    body.put("Code", 3);
    body.put("FromUserName", this.User.getString("UserName"));
    body.put("ToUserName", this.User.getString("UserName"));
    body.put("ClientMsgId", DateKit.getCurrentUnixTime());
    HttpRequest request = HttpRequest.post(Url).header("Content-Type", "application/json;charset=utf-8").header("Cookie", this.Cookie).send(body.toString());
    LOGGER.info("[*] " + request);
    String res = request.body();
    request.disconnect();
    if (StringKit.isBlank(res)) {
        return false;
    }
    try {
        JSONObject jsonObject = (JSONObject) JSON.parse(res);
        JSONObject BaseResponse = (JSONObject) jsonObject.get("BaseResponse");
        if (null != BaseResponse) {
            int ret = BaseResponse.getInt("Ret", -1);
            return ret == 0;
        }
    } catch (Exception e) {
    }
    return false;
}

18 View Complete Implementation : WechatApp.java
Copyright Apache License 2.0
Author : Zhyblx
/**
 * 消息检查
 */
public int[] syncCheck() {
    int[] arr = new int[2];
    String Url = this.WEBPUSH_URL + "/synccheck";
    JSONObject body = new JSONObject();
    body.put("BaseRequest", BaseRequest);
    HttpRequest request = null;
    String res = null;
    request = HttpRequest.get(Url, true, "r", DateKit.getCurrentUnixTime() + StringKit.getRandomNumber(5), "skey", this.SKEY, "uin", this.WXUIN, "sid", this.WXSID, "deviceid", this.DEVICEID, "synckey", this.SYNCKEY, "_", System.currentTimeMillis()).header("Cookie", this.Cookie);
    LOGGER.info("[*] " + request);
    // 当res为空的时候,程序就开始报错了
    // res = request.body();
    /**
     *   循环的作用是排错
     *   原理:当res 为空的情况下,会一直循环获取内容,直到有内容的才跳出循环
     */
    int i = 1;
    while (i > 0) {
        // 当 res 出错的时候,异常不处理,res 字符串为空;然后继续执行循环提,直到拿到内容。
        try {
            res = request.body();
        } catch (Exception e) {
            res = "";
        }
        if (res != null || "".equals(res) || res.length() != 0) {
            break;
        }
    }
    request.disconnect();
    if (StringKit.isBlank(res)) {
        return arr;
    }
    String retcode = Matchers.match("retcode:\"(\\d+)\",", res);
    String selector = Matchers.match("selector:\"(\\d+)\"}", res);
    if (null != retcode && null != selector) {
        arr[0] = Integer.parseInt(retcode);
        arr[1] = Integer.parseInt(selector);
        return arr;
    }
    return arr;
}

18 View Complete Implementation : WechatApp.java
Copyright Apache License 2.0
Author : Zhyblx
/**
 * 获取最新消息
 */
public JSONObject webwxsync() {
    String url = this.BASE_URL + "/webwxsync?lang=zh_CN&preplaced_ticket=" + this.Preplaced_TICKET + "&skey=" + this.SKEY + "&sid=" + this.WXSID + "&r=" + DateKit.getCurrentUnixTime();
    JSONObject body = new JSONObject();
    body.put("BaseRequest", BaseRequest);
    body.put("SyncKey", this.SyncKey);
    body.put("rr", DateKit.getCurrentUnixTime());
    HttpRequest request = HttpRequest.post(url).header("Content-Type", "application/json;charset=utf-8").header("Cookie", this.Cookie).send(body.toString());
    LOGGER.info("[*] " + request);
    String res = request.body();
    request.disconnect();
    if (StringKit.isBlank(res)) {
        return null;
    }
    JSONObject jsonObject = (JSONObject) JSON.parse(res);
    JSONObject BaseResponse = (JSONObject) jsonObject.get("BaseResponse");
    if (null != BaseResponse) {
        int ret = BaseResponse.getInt("Ret", -1);
        if (ret == 0) {
            this.SyncKey = (JSONObject) jsonObject.get("SyncKey");
            StringBuffer synckey = new StringBuffer();
            JSONArray list = (JSONArray) SyncKey.get("List");
            for (int i = 0, len = list.size(); i < len; i++) {
                JSONObject item = (JSONObject) list.get(i);
                synckey.append("|" + item.getInt("Key", 0) + "_" + item.getInt("Val", 0));
            }
            this.SYNCKEY = synckey.substring(1);
        }
    }
    return jsonObject;
}

18 View Complete Implementation : WechatApp.java
Copyright Apache License 2.0
Author : Zhyblx
/**
 * 登陆微信
 */
public boolean login() {
    HttpRequest request = HttpRequest.get(this.REDIRECT_URL);
    LOGGER.info("[*] " + request);
    String res = request.body();
    this.Cookie = CookieUtil.getCookie(request);
    request.disconnect();
    if (StringKit.isBlank(res)) {
        return false;
    }
    this.SKEY = Matchers.match("<skey>(\\S+)</skey>", res);
    this.WXSID = Matchers.match("<wxsid>(\\S+)</wxsid>", res);
    this.WXUIN = Matchers.match("<wxuin>(\\S+)</wxuin>", res);
    this.Preplaced_TICKET = Matchers.match("<preplaced_ticket>(\\S+)</preplaced_ticket>", res);
    LOGGER.info("[*] skey[%s]" + this.SKEY);
    LOGGER.info("[*] wxsid[%s]" + this.WXSID);
    LOGGER.info("[*] wxuin[%s]" + this.WXUIN);
    LOGGER.info("[*] preplaced_ticket[%s]" + this.Preplaced_TICKET);
    this.BaseRequest = new JSONObject();
    BaseRequest.put("Uin", this.WXUIN);
    BaseRequest.put("Sid", this.WXSID);
    BaseRequest.put("Skey", this.SKEY);
    BaseRequest.put("DeviceID", this.DEVICEID);
    return true;
}

18 View Complete Implementation : WechatApp.java
Copyright Apache License 2.0
Author : Zhyblx
/**
 * 获取联系人
 */
public boolean getContact() {
    String url = this.BASE_URL + "/webwxgetcontact?preplaced_ticket=" + this.Preplaced_TICKET + "&skey=" + this.SKEY + "&r=" + DateKit.getCurrentUnixTime();
    JSONObject body = new JSONObject();
    body.put("BaseRequest", BaseRequest);
    HttpRequest request = HttpRequest.post(url).header("Content-Type", "application/json;charset=utf-8").header("Cookie", this.Cookie).send(body.toString());
    LOGGER.info("[*] " + request);
    String res = request.body();
    request.disconnect();
    if (StringKit.isBlank(res)) {
        return false;
    }
    try {
        JSONObject jsonObject = (JSONObject) JSON.parse(res);
        // AddressBook类的作用:
        // 1.导出好友列表
        // 2.判断好友是否在数据库中存在,如果是数据库中不存在的好友,那么会将最新的好友存储在数据库中
        AddressBook.getAddressBookList(jsonObject);
        JSONObject BaseResponse = (JSONObject) jsonObject.get("BaseResponse");
        if (null != BaseResponse) {
            int ret = BaseResponse.getInt("Ret", -1);
            if (ret == 0) {
                this.MemberList = (JSONArray) jsonObject.get("MemberList");
                this.ContactList = new JSONArray();
                if (null != MemberList) {
                    for (int i = 0, len = MemberList.size(); i < len; i++) {
                        JSONObject contact = (JSONObject) this.MemberList.get(i);
                        // 公众号/服务号
                        if (contact.getInt("VerifyFlag", 0) == 8) {
                            continue;
                        }
                        // 特殊联系人
                        // if (SpecialUsers.contains(contact.getString("UserName"))) {
                        // continue;
                        // }
                        // 群聊
                        if (contact.getString("UserName").indexOf("@@") != -1) {
                            continue;
                        }
                        // 自己
                        if (contact.getString("UserName").equals(this.User.getString("UserName"))) {
                            continue;
                        }
                        ContactList.add(contact);
                    }
                    return true;
                }
            }
        }
    } catch (Exception e) {
    }
    return false;
}

18 View Complete Implementation : WechatApp.java
Copyright Apache License 2.0
Author : Zhyblx
/**
 * 微信初始化
 */
public boolean wxInit() {
    String url = this.BASE_URL + "/webwxinit?r=" + DateKit.getCurrentUnixTime() + "&preplaced_ticket=" + this.Preplaced_TICKET + "&skey=" + this.SKEY;
    JSONObject body = new JSONObject();
    body.put("BaseRequest", this.BaseRequest);
    HttpRequest request = HttpRequest.post(url).header("Content-Type", "application/json;charset=utf-8").header("Cookie", this.Cookie).send(body.toString());
    LOGGER.info("[*] " + request);
    String res = request.body();
    request.disconnect();
    if (StringKit.isBlank(res)) {
        return false;
    }
    try {
        JSONObject jsonObject = (JSONObject) JSON.parse(res);
        if (null != jsonObject) {
            JSONObject BaseResponse = (JSONObject) jsonObject.get("BaseResponse");
            if (null != BaseResponse) {
                int ret = BaseResponse.getInt("Ret", -1);
                if (ret == 0) {
                    this.SyncKey = (JSONObject) jsonObject.get("SyncKey");
                    this.User = (JSONObject) jsonObject.get("User");
                    StringBuffer synckey = new StringBuffer();
                    JSONArray list = (JSONArray) SyncKey.get("List");
                    for (int i = 0, len = list.size(); i < len; i++) {
                        JSONObject item = (JSONObject) list.get(i);
                        synckey.append("|" + item.getInt("Key", 0) + "_" + item.getInt("Val", 0));
                    }
                    this.SYNCKEY = synckey.substring(1);
                    return true;
                }
            }
        }
    } catch (Exception e) {
    }
    return false;
}

18 View Complete Implementation : WechatApp.java
Copyright Apache License 2.0
Author : Zhyblx
/**
 * 发送消息
 */
private void webwxsendmsg(String content, String to) {
    String url = this.BASE_URL + "/webwxsendmsg?lang=zh_CN&preplaced_ticket=" + this.Preplaced_TICKET;
    JSONObject body = new JSONObject();
    String clientMsgId = DateKit.getCurrentUnixTime() + StringKit.getRandomNumber(5);
    JSONObject Msg = new JSONObject();
    Msg.put("Type", 1);
    Msg.put("Content", content);
    Msg.put("FromUserName", User.getString("UserName"));
    Msg.put("ToUserName", to);
    Msg.put("LocalID", clientMsgId);
    Msg.put("ClientMsgId", clientMsgId);
    body.put("BaseRequest", this.BaseRequest);
    body.put("Msg", Msg);
    HttpRequest request = HttpRequest.post(url).header("Content-Type", "application/json;charset=utf-8").header("Cookie", this.Cookie).send(body.toString());
    LOGGER.info("[*] " + request);
    request.body();
    request.disconnect();
}