2023-05-31 11:20:49 +08:00
|
|
|
package com.example.wxhk.util;
|
|
|
|
|
|
|
|
import com.example.wxhk.model.PrivateChatMsg;
|
2023-06-01 10:22:56 +08:00
|
|
|
import com.example.wxhk.model.request.*;
|
2023-06-01 11:13:49 +08:00
|
|
|
import com.example.wxhk.model.response.ContactList;
|
|
|
|
import com.example.wxhk.model.response.GroupMembers;
|
2023-06-01 09:57:03 +08:00
|
|
|
import com.example.wxhk.tcp.vertx.ArrHandle;
|
2023-05-31 11:20:49 +08:00
|
|
|
import com.example.wxhk.tcp.vertx.InitWeChat;
|
|
|
|
import io.vertx.core.json.JsonObject;
|
|
|
|
import org.dromara.hutool.core.util.XmlUtil;
|
|
|
|
import org.dromara.hutool.log.Log;
|
|
|
|
import org.w3c.dom.Document;
|
|
|
|
import org.w3c.dom.Node;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 常见方法
|
2023-06-01 09:57:03 +08:00
|
|
|
*
|
2023-05-31 11:20:49 +08:00
|
|
|
* @author wt
|
|
|
|
* @date 2023/05/29
|
|
|
|
*/
|
|
|
|
public class HttpSendUtil {
|
|
|
|
|
2023-06-01 09:57:03 +08:00
|
|
|
protected static final Log log = Log.get();
|
|
|
|
|
|
|
|
public static JsonObject 通过好友请求(PrivateChatMsg msg) {
|
2023-05-31 11:20:49 +08:00
|
|
|
Document document = XmlUtil.parseXml(msg.getContent());
|
|
|
|
String encryptusername = document.getDocumentElement().getAttribute("encryptusername");
|
|
|
|
String ticket = document.getDocumentElement().getAttribute("ticket");
|
|
|
|
return HttpSyncUtil.exec(HttpAsyncUtil.Type.通过好友申请, new JsonObject().put("v3", encryptusername).put("v4", ticket).put("permission", "0"));
|
|
|
|
}
|
2023-06-01 09:57:03 +08:00
|
|
|
|
|
|
|
public static JsonObject 确认收款(PrivateChatMsg msg) {
|
2023-05-31 11:20:49 +08:00
|
|
|
try {
|
|
|
|
String content = msg.getContent();
|
|
|
|
Document document = XmlUtil.parseXml(content);
|
|
|
|
Node paysubtype = document.getElementsByTagName("paysubtype").item(0);
|
2023-06-01 09:57:03 +08:00
|
|
|
if ("1".equals(paysubtype.getTextContent().trim())) {
|
2023-05-31 11:20:49 +08:00
|
|
|
// 手机发出去的
|
|
|
|
String textContent = document.getElementsByTagName("receiver_username").item(0).getTextContent();
|
2023-06-01 09:57:03 +08:00
|
|
|
if (!InitWeChat.WXID_MAP.contains(textContent)) {
|
|
|
|
return new JsonObject().put("spick", true);
|
2023-05-31 11:20:49 +08:00
|
|
|
}
|
|
|
|
Node transcationid = document.getDocumentElement().getElementsByTagName("transcationid").item(0);
|
|
|
|
Node transferid = document.getDocumentElement().getElementsByTagName("transferid").item(0);
|
2023-06-01 09:57:03 +08:00
|
|
|
return HttpSyncUtil.exec(HttpAsyncUtil.Type.确认收款, new JsonObject().put("wxid", msg.getFromUser())
|
|
|
|
.put("transcationId", transcationid.getTextContent())
|
|
|
|
.put("transferId", transferid.getTextContent()));
|
2023-05-31 11:20:49 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
// 如果是确认接受收款,则跳过
|
|
|
|
return new JsonObject();
|
|
|
|
|
2023-06-01 09:57:03 +08:00
|
|
|
} catch (Exception e) {
|
2023-05-31 11:20:49 +08:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-01 10:22:56 +08:00
|
|
|
public static JsonObject 发送文本(String wxid, String msg) {
|
2023-06-01 09:57:03 +08:00
|
|
|
return HttpSyncUtil.exec(HttpAsyncUtil.Type.发送文本, JsonObject.mapFrom(new SendMsg().setMsg(msg).setWxid(wxid)));
|
|
|
|
}
|
2023-06-01 10:22:56 +08:00
|
|
|
|
|
|
|
public static JsonObject 发送文本(String msg) {
|
|
|
|
return 发送文本(ArrHandle.getPriMsg().getFromUser(), msg);
|
2023-06-01 09:57:03 +08:00
|
|
|
}
|
2023-06-01 10:22:56 +08:00
|
|
|
|
|
|
|
public static JsonObject 发送at文本(String chatRoomId, String wxids, String msg) {
|
2023-06-01 09:57:03 +08:00
|
|
|
return HttpSyncUtil.exec(HttpAsyncUtil.Type.发送at文本, JsonObject.mapFrom(new SendMsg().setMsg(msg).setWxids(wxids).setChatRoomId(chatRoomId)));
|
|
|
|
}
|
2023-06-01 10:22:56 +08:00
|
|
|
|
|
|
|
public static JsonObject 发送at文本(String wxids, String msg) {
|
|
|
|
return 发送at文本(ArrHandle.getPriMsg().getFromGroup(), wxids, msg);
|
2023-06-01 09:57:03 +08:00
|
|
|
}
|
2023-06-01 10:22:56 +08:00
|
|
|
|
|
|
|
public static JsonObject 发送图片(String wxid, String msg) {
|
2023-06-01 09:57:03 +08:00
|
|
|
return HttpSyncUtil.exec(HttpAsyncUtil.Type.发送图片, JsonObject.mapFrom(new SendMsg().setImagePath(msg).setWxid(wxid)));
|
|
|
|
}
|
2023-06-01 10:22:56 +08:00
|
|
|
|
|
|
|
public static JsonObject 发送图片(String msg) {
|
|
|
|
return 发送图片(ArrHandle.getPriMsg().getFromUser(), msg);
|
2023-06-01 09:57:03 +08:00
|
|
|
}
|
2023-06-01 10:22:56 +08:00
|
|
|
|
|
|
|
public static JsonObject 发送文件(String wxid, String msg) {
|
2023-06-01 09:57:03 +08:00
|
|
|
return HttpSyncUtil.exec(HttpAsyncUtil.Type.发送文件, JsonObject.mapFrom(new SendMsg().setFilePath(msg).setWxid(wxid)));
|
|
|
|
}
|
2023-06-01 10:22:56 +08:00
|
|
|
|
|
|
|
public static JsonObject 发送文件(String msg) {
|
|
|
|
return 发送文件(ArrHandle.getPriMsg().getFromUser(), msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static JsonObject 添加好友(AddFriends p) {
|
|
|
|
return HttpSyncUtil.exec(HttpAsyncUtil.Type.添加好友, p.toJson());
|
2023-06-01 09:57:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static String 获取当前登陆微信id() {
|
2023-05-31 11:20:49 +08:00
|
|
|
JsonObject exec = HttpSyncUtil.exec(HttpAsyncUtil.Type.获取登录信息, new JsonObject());
|
|
|
|
return exec.getJsonObject("data").getString("wxid");
|
|
|
|
}
|
|
|
|
|
2023-06-01 11:13:49 +08:00
|
|
|
public static ContactList 联系人列表(){
|
2023-06-01 10:22:56 +08:00
|
|
|
JsonObject exec = HttpSyncUtil.exec(HttpAsyncUtil.Type.联系人列表, new JsonObject());
|
2023-06-01 11:13:49 +08:00
|
|
|
return exec.mapTo(ContactList.class);
|
2023-06-01 10:22:56 +08:00
|
|
|
}
|
|
|
|
public static JsonObject 开启hook(OpenHook hook){
|
|
|
|
JsonObject exec = HttpSyncUtil.exec(HttpAsyncUtil.Type.开启hook,hook.toJson());
|
2023-06-01 11:13:49 +08:00
|
|
|
return exec;
|
2023-06-01 10:22:56 +08:00
|
|
|
}
|
2023-06-01 11:13:49 +08:00
|
|
|
public static JsonObject 关闭hook(){
|
|
|
|
JsonObject exec = HttpSyncUtil.exec(HttpAsyncUtil.Type.关闭hook,new JsonObject());
|
|
|
|
return exec;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GroupMembers 获取群成员(GetGroupMembers p){
|
|
|
|
return HttpSyncUtil.exec(HttpAsyncUtil.Type.获取群成员, p.toJson()).mapTo(GroupMembers.class);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-06-01 10:22:56 +08:00
|
|
|
|
2023-06-06 16:48:12 +08:00
|
|
|
public static JsonObject 确认收款(ConfirmThePayment payment){
|
|
|
|
return HttpSyncUtil.exec(HttpAsyncUtil.Type.确认收款, payment.toJson());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-01 10:22:56 +08:00
|
|
|
@Deprecated
|
|
|
|
public static com.example.wxhk.infe.SendMsg of(HttpAsyncUtil.Type type) {
|
|
|
|
switch (type) {
|
|
|
|
|
|
|
|
case 检查微信登陆 -> {
|
|
|
|
|
|
|
|
}
|
|
|
|
case 获取登录信息 -> {
|
|
|
|
}
|
|
|
|
case 发送文本 -> {
|
|
|
|
return new SendText();
|
|
|
|
}
|
|
|
|
case 发送at文本 -> {
|
|
|
|
return new SendAtText();
|
|
|
|
}
|
|
|
|
case 发送图片 -> {
|
|
|
|
return new SendImg();
|
|
|
|
}
|
|
|
|
case 发送文件 -> {
|
|
|
|
return new SendFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return new SendText();
|
|
|
|
}
|
|
|
|
|
2023-05-31 11:20:49 +08:00
|
|
|
}
|