Here are the examples of the java api com.blade.kit.http.HttpRequest.body() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
8 Examples
15
Source : WechatApp.java
with Apache License 2.0
from Zhyblx
with Apache License 2.0
from 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;
}
13
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;
}
13
Source : WechatApp.java
with Apache License 2.0
from Zhyblx
with Apache License 2.0
from Zhyblx
/**
* 等待登录
* 扫描二维码并登陆
*/
public String waitForLogin() {
this.Tip = 1;
HttpRequest request = HttpRequest.get(WechatInterface.LOGIN_URL, true, "tip", this.Tip, "uuid", this.Uuid, "_", DateKit.getCurrentUnixTime());
LOGGER.info("[*] " + request.toString());
String Res = request.body();
request.disconnect();
if (null == Res) {
LOGGER.info("[*] 扫描二维码验证失败");
return "";
}
String Code = Matchers.match("window.code=(\\d+);", Res);
if (null == Code) {
LOGGER.info("[*] 扫描二维码验证失败");
return "";
} else {
if (Code.equals("201")) {
LOGGER.info("[*] 成功扫描,请在手机上点击确认以登录");
Tip = 0;
} else if (Code.equals("200")) {
LOGGER.info("[*] 正在登录...");
String pm = Matchers.match("window.redirect_uri=\"(\\S+?)\";", Res);
this.REDIRECT_URL = pm + "&fun=new";
LOGGER.info("[*] redirect_uri=%s" + this.REDIRECT_URL);
this.BASE_URL = this.REDIRECT_URL.substring(0, this.REDIRECT_URL.lastIndexOf("/"));
LOGGER.info("[*] base_uri=%s" + this.BASE_URL);
} else if (Code.equals("408")) {
LOGGER.info("[*] 登录超时");
} else {
LOGGER.info("[*] 扫描code=%s" + Code);
}
}
return Code;
}
13
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;
}
13
Source : WechatApp.java
with Apache License 2.0
from Zhyblx
with Apache License 2.0
from Zhyblx
/**
* 获取UUID:uuid是唯一的识别码
*/
public String getUUID() {
HttpRequest request = HttpRequest.get(WechatInterface.UUID_URL, true, "appid", "wx782c26e4c19acffb", "fun", "new", "lang", "zh_CN", "_", DateKit.getCurrentUnixTime());
// LOGGER.info 记录信息
LOGGER.info("[*] " + request);
String res = request.body();
// res 为UUID
request.disconnect();
// 如果返回的uuid信息不等于空
if (StringKit.isNotBlank(res)) {
// 将登陆信息赋值给code
String code = Matchers.match("window.QRLogin.code = (\\d+);", res);
// 如果登陆信息不等于空,那么微信登陆成功,否则反馈错误状态码
if (null != code) {
if (code.equals("200")) {
this.Uuid = Matchers.match("window.QRLogin.uuid = \"(.*)\";", res);
return this.Uuid;
} else {
LOGGER.info("[*] 错误的状态码: %s" + code);
}
}
}
return null;
}
13
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();
}
12
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;
}
11
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;
}