Here are the examples of the java api com.blade.kit.json.JSONObject.toString() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
5 Examples
11
Source : WechatApp.java
with Apache License 2.0
from Zhyblx
with Apache License 2.0
from 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();
}
10
Source : WechatApp.java
with Apache License 2.0
from Zhyblx
with Apache License 2.0
from 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;
}
10
Source : WechatApp.java
with Apache License 2.0
from Zhyblx
with Apache License 2.0
from 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;
}
9
Source : WechatApp.java
with Apache License 2.0
from Zhyblx
with Apache License 2.0
from 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;
}
8
Source : WechatApp.java
with Apache License 2.0
from Zhyblx
with Apache License 2.0
from 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;
}