java客户端

This commit is contained in:
王涛 committed 2023-05-31 11:20:49 +08:00
1 parent 81ea48b534
commit 3f66d7b6d0
22 files changed
+1344

No files matched your search

@@ -0,0 +1,13 @@
package com.example.wxhk;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class WxhkApplicationTests {
@Test
void contextLoads() {
}
}
@@ -0,0 +1,44 @@
package com.example.wxhk.tcp;
import com.example.wxhk.util.HttpAsyncUtil;
import io.vertx.core.Future;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.client.HttpResponse;
import org.dromara.hutool.core.lang.Console;
import org.dromara.hutool.core.thread.ThreadUtil;
import org.dromara.hutool.log.Log;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class HttpAsyncUtilTest {
protected static final Log log = Log.get();
@Test
void exec() {
Future<HttpResponse<Buffer>> exec = HttpAsyncUtil.exec(HttpAsyncUtil.Type.联系人列表, new JsonObject());
exec.onSuccess(event -> {
Console.log(event.bodyAsJsonObject());
});
}
@Test
void exec1() {
for(int i=0;i<10000;i++){
int finalI = i;
HttpAsyncUtil.exec(HttpAsyncUtil.Type.获取登录信息, new JsonObject(), event -> {
if (event.succeeded()) {
log.info("i:{},{}", finalI,event.result().bodyAsJsonObject());
}else{
event.cause().printStackTrace();
}
});
log.info("发出请求:{}",i);
}
ThreadUtil.sync(this);
}
}
@@ -0,0 +1,72 @@
package com.example.wxhk.tcp;
import com.example.wxhk.model.PrivateChatMsg;
import com.example.wxhk.msg.WxMsgHandle;
import io.vertx.core.json.JsonObject;
import org.dromara.hutool.core.lang.Console;
import org.dromara.hutool.core.util.XmlUtil;
import org.dromara.hutool.http.HttpUtil;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class XmlTest {
@Test
void t(){
String con = "{\"content\":\"<msg fromusername=\\\"wxid_gf1fogt5a0pq22\\\" encryptusername=\\\"v3_020b3826fd030100000000009fd5196d2b7f14000000501ea9a3dba12f95f6b60a0536a1adb6222623e1e7bc2246f8247bfc11cf3782df013caece773e96e9b39159c944356a6b6f5a1eed71f349337abd60ec5ff3f4b3f95c0ede21f9d04e9d0d20@stranger\\\" fromnickname=\\\"时光似水戏流年\\\" content=\\\"我是群聊“最美阿芙”的时光似水戏流年\\\" fullpy=\\\"shiguangshishuihuliunian\\\" shortpy=\\\"SGSSHLN\\\" imagestatus=\\\"3\\\" scene=\\\"14\\\" country=\\\"CN\\\" province=\\\"Guangdong\\\" city=\\\"Shenzhen\\\" sign=\\\"时光似水戏流年\\\" percard=\\\"1\\\" sex=\\\"1\\\" alias=\\\"jys-wt\\\" weibo=\\\"\\\" albumflag=\\\"0\\\" albumstyle=\\\"0\\\" albumbgimgid=\\\"\\\" snsflag=\\\"273\\\" snsbgimgid=\\\"\\\" snsbgobjectid=\\\"0\\\" mhash=\\\"92b16d9f1e8ecdb5de9232c461ba9e21\\\" mfullhash=\\\"92b16d9f1e8ecdb5de9232c461ba9e21\\\" bigheadimgurl=\\\"http://wx.qlogo.cn/mmhead/ver_1/w1mQWocjEnJxthtueLW87La2jhy8qqEDhK24AIL7d3dI27XIIg9y82COhqAtlgbFia3CEHUglmba9SZ1iaMq02Wm8x6hPdpztFe8siaECh2p6Y/0\\\" smallheadimgurl=\\\"http://wx.qlogo.cn/mmhead/ver_1/w1mQWocjEnJxthtueLW87La2jhy8qqEDhK24AIL7d3dI27XIIg9y82COhqAtlgbFia3CEHUglmba9SZ1iaMq02Wm8x6hPdpztFe8siaECh2p6Y/96\\\" ticket=\\\"v4_000b708f0b040000010000000000628616cecca09e7b0612ffcc6e641000000050ded0b020927e3c97896a09d47e6e9ea056679221f16dedb668b49afdb5596faf44ef8c7ff2f5d94850d4f47882de2660f1e88ee7358379d8dabd1452c2f1cc7655666134238d13e9bdbe1c2b839e02ae205033e299324c2daa5e7bf4c6f8557fe159e6d0c652f8cf3e3f6970f80814f973e49ccd653a67@stranger\\\" opcode=\\\"2\\\" googlecontact=\\\"\\\" qrticket=\\\"\\\" chatroomusername=\\\"23793178249@chatroom\\\" sourceusername=\\\"\\\" sourcenickname=\\\"\\\" sharecardusername=\\\"\\\" sharecardnickname=\\\"\\\" cardversion=\\\"\\\" extflag=\\\"0\\\"><brandlist count=\\\"0\\\" ver=\\\"830326267\\\"></brandlist></msg>\",\"fromGroup\":\"fmessage\",\"fromUser\":\"fmessage\",\"isSendMsg\":0,\"msgId\":4949224622157906392,\"pid\":1860,\"sign\":\"ab8277a517ed906cf31a64843d4c61d5\",\"signature\":\"<msgsource>\\n\\t<signature>v1_ZLVKn3eO</signature>\\n\\t<tmp_node>\\n\\t\\t<publisher-id>&lt;![CDATA[]]&gt;</publisher-id>\\n\\t</tmp_node>\\n</msgsource>\\n\",\"time\":\"2023-05-25 10:50:39\",\"timestamp\":1684983039,\"type\":37}";
JsonObject entries = new JsonObject(con);
String content = entries.getString("content");
Document document = XmlUtil.parseXml(content);
String encryptusername = document.getDocumentElement().getAttribute("encryptusername");
String ticket = document.getDocumentElement().getAttribute("ticket");
System.out.println(ticket);
String post = HttpUtil.post("http://127.0.0.1:19088/api/?type=23", new JsonObject().put("v3", encryptusername).put("v4", ticket)
.put("type","8")
.put("permission","5")
.encode());
System.out.println(post);
}
@Test
void 接受转账(){
String smg = "{\"content\":\"<msg>\\n<appmsg appid=\\\"\\\" sdkver=\\\"\\\">\\n<title><![CDATA[微信转账]]></title>\\n<des><![CDATA[收到转账0.01元。如需收钱,请点此升级至最新版本]]></des>\\n<action></action>\\n<type>2000</type>\\n<content><![CDATA[]]></content>\\n<url><![CDATA[https://support.weixin.qq.com/cgi-bin/mmsupport-bin/readtemplate?t=page/common_page__upgrade&text=text001&btn_text=btn_text_0]]></url>\\n<thumburl><![CDATA[https://support.weixin.qq.com/cgi-bin/mmsupport-bin/readtemplate?t=page/common_page__upgrade&text=text001&btn_text=btn_text_0]]></thumburl>\\n<lowurl></lowurl>\\n<extinfo>\\n</extinfo>\\n<wcpayinfo>\\n<paysubtype>1</paysubtype>\\n<feedesc><![CDATA[¥0.01]]></feedesc>\\n<transcationid><![CDATA[100005000123052900050128354179606732]]></transcationid>\\n<transferid><![CDATA[1000050001202305290113322251717]]></transferid>\\n<invalidtime><![CDATA[1685412015]]></invalidtime>\\n<begintransfertime><![CDATA[1685325615]]></begintransfertime>\\n<effectivedate><![CDATA[1]]></effectivedate>\\n<pay_memo><![CDATA[你好]]></pay_memo>\\n<receiver_username><![CDATA[wxid_4yr8erik0uho22]]></receiver_username>\\n<payer_username><![CDATA[]]></payer_username>\\n\\n\\n</wcpayinfo>\\n</appmsg>\\n</msg>\",\"fromGroup\":\"wxid_gf1fogt5a0pq22\",\"fromUser\":\"wxid_gf1fogt5a0pq22\",\"isSendMsg\":0,\"msgId\":3157044781598783480,\"path\":\"wxid_4yr8erik0uho22\\\\FileStorage\\\\Cache\\\\2023-05\\\\324af3cccfe197a57506357bff7c85f7\",\"pid\":14268,\"sign\":\"e588b9632126b915e17c5a960e4ef288\",\"signature\":\"<msgsource>\\n\\t<signature>v1_LzLnadY1</signature>\\n\\t<tmp_node>\\n\\t\\t<publisher-id>&lt;![CDATA[]]&gt;</publisher-id>\\n\\t</tmp_node>\\n</msgsource>\\n\",\"time\":\"2023-05-29 10:00:15\",\"timestamp\":1685325615,\"type\":49}";
JsonObject entries = new JsonObject(smg);
String content = entries.getString("content");
Document document = XmlUtil.parseXml(content);
Element documentElement = document.getDocumentElement();
Node transcationid = documentElement.getElementsByTagName("transcationid").item(0);
Node transferid = documentElement.getElementsByTagName("transferid").item(0);
Console.log(transcationid);
}
@Test
void 扫码支付(){
String smg = "{\"content\":\"<sysmsg type=\\\"paymsg\\\">\\n <paymsg>\\n <PayMsgType>9</PayMsgType>\\n \\n <transid><![CDATA[7v0s7fU7YjoHpKNA9CCED6EpZWAevzdBknlQ__RpLqDL3tI2A0Okt0aEgGe23Z3M_z3u-j6o96aCjRXfE1K--wOwCQ]]></transid>\\n\\t\\t\\n\\t\\t\\n <username><![CDATA[wxid_gf1fogt5a0pq22]]></username>\\n\\t\\t\\n\\t\\t\\n <displayname><![CDATA[时光似水戏流年]]></displayname>\\n\\t\\t\\n <timestamp>1685325848</timestamp>\\n <fee>1</fee>\\n <feetype>1</feetype>\\n <headimgurl></headimgurl>\\n\\n\\n\\n <scene>0</scene>\\n <status>1</status>\\n<outtradeno>10001071012023052901214894726608</outtradeno>\\n \\n </paymsg>\\n</sysmsg>\",\"fromGroup\":\"wxid_4yr8erik0uho22\",\"fromUser\":\"wxid_4yr8erik0uho22\",\"isSendByPhone\":1,\"isSendMsg\":1,\"msgId\":3869459965780413850,\"pid\":14268,\"sign\":\"2285732a2e5b17729e7eeb8e305add15\",\"signature\":\"<msgsource>\\n\\t<tmp_node>\\n\\t\\t<publisher-id>&lt;![CDATA[]]&gt;</publisher-id>\\n\\t</tmp_node>\\n</msgsource>\\n\",\"time\":\"2023-05-29 10:04:08\",\"timestamp\":1685325848,\"type\":10002}";
JsonObject entries = new JsonObject(smg);
String content = entries.getString("content");
Document document = XmlUtil.parseXml(content);
Element documentElement = document.getDocumentElement();
String localName = documentElement.getLocalName();
String type = documentElement.getAttribute("type");
NodeList outtradeno = documentElement.getElementsByTagName("outtradeno");
if (outtradeno.getLength()>0) {
Console.log(outtradeno.item(0).getTextContent());
}
}
@Test
void 扫码支付2duan(){
String smg = "{\"content\":\"<msg> <appmsg appid=\\\"\\\" sdkver=\\\"0\\\"> \\t<title><![CDATA[微信支付收款0.01元(朋友到店)]]></title> \\t<des><![CDATA[收款金额¥0.01\\n付款方备注扫码付款\\n汇总今日第1笔收款,共计¥0.01\\n备注收款成功,已存入零钱。点击可查看详情]]></des> \\t<action></action> \\t<type>5</type> \\t<showtype>1</showtype> <soundtype>0</soundtype> \\t<content><![CDATA[]]></content> \\t<contentattr>0</contentattr> \\t<url><![CDATA[https://payapp.weixin.qq.com/payf2f/jumpf2fbill?timestamp=1685325848&openid=vlHyuSTz0pPfaqS1dK0gSEG36Iuycg9f_JIoq96MqUo=]]></url> \\t<lowurl><![CDATA[]]></lowurl> \\t<appattach> \\t\\t<totallen>0</totallen> \\t\\t<attachid></attachid> \\t\\t<fileext></fileext> \\t\\t<cdnthumburl><![CDATA[]]></cdnthumburl> \\t\\t<cdnthumbaeskey><![CDATA[]]></cdnthumbaeskey> \\t\\t<aeskey><![CDATA[]]></aeskey> \\t</appattach> \\t<extinfo></extinfo> \\t<sourceusername><![CDATA[]]></sourceusername> \\t<sourcedisplayname><![CDATA[]]></sourcedisplayname> \\t<mmreader> \\t\\t<category type=\\\"0\\\" count=\\\"1\\\"> \\t\\t\\t<name><![CDATA[微信收款助手]]></name> \\t\\t\\t<topnew> \\t\\t\\t\\t<cover><![CDATA[]]></cover> \\t\\t\\t\\t<width>0</width> \\t\\t\\t\\t<height>0</height> \\t\\t\\t\\t<digest><![CDATA[收款金额¥0.01\\n付款方备注扫码付款\\n汇总今日第1笔收款,共计¥0.01\\n备注收款成功,已存入零钱。点击可查看详情]]></digest> \\t\\t\\t</topnew> \\t\\t\\t\\t<item> \\t<itemshowtype>4</itemshowtype> \\t<title><![CDATA[微信支付收款0.01元(朋友到店)]]></title> \\t<url><![CDATA[https://payapp.weixin.qq.com/payf2f/jumpf2fbill?timestamp=1685325848&openid=vlHyuSTz0pPfaqS1dK0gSEG36Iuycg9f_JIoq96MqUo=]]></url> \\t<shorturl><![CDATA[]]></shorturl> \\t<longurl><![CDATA[]]></longurl> \\t<pub_time>1685325848</pub_time> \\t<cover><![CDATA[]]></cover> \\t<tweetid></tweetid> \\t<digest><![CDATA[收款金额¥0.01\\n付款方备注扫码付款\\n汇总今日第1笔收款,共计¥0.01\\n备注收款成功,已存入零钱。点击可查看详情]]></digest> \\t<fileid>0</fileid> \\t<sources> \\t<source> \\t<name><![CDATA[微信收款助手]]></name> \\t</source> \\t</sources> \\t<styles><topColor><![CDATA[]]></topColor>\\n<style>\\n<range><![CDATA[{4,5}]]></range>\\n<font><![CDATA[s]]></font>\\n<color><![CDATA[#000000]]></color>\\n</style>\\n<style>\\n<range><![CDATA[{15,4}]]></range>\\n<font><![CDATA[s]]></font>\\n<color><![CDATA[#000000]]></color>\\n</style>\\n<style>\\n<range><![CDATA[{22,15}]]></range>\\n<font><![CDATA[s]]></font>\\n<color><![CDATA[#000000]]></color>\\n</style>\\n<style>\\n<range><![CDATA[{40,18}]]></range>\\n<font><![CDATA[s]]></font>\\n<color><![CDATA[#000000]]></color>\\n</style>\\n</styles>\\t<native_url></native_url> <del_flag>0</del_flag> <contentattr>0</contentattr> <play_length>0</play_length> \\t<play_url><![CDATA[]]></play_url> \\t<player><![CDATA[]]></player> \\t<template_op_type>1</template_op_type> \\t<weapp_username><![CDATA[gh_fac0ad4c321d@app]]></weapp_username> \\t<weapp_path><![CDATA[pages/index/index.html]]></weapp_path> \\t<weapp_version>967</weapp_version> \\t<weapp_state>0</weapp_state> <music_source>0</music_source> <pic_num>0</pic_num> \\t<show_complaint_button>0</show_complaint_button> \\t<vid><![CDATA[]]></vid> \\t<recommendation><![CDATA[]]></recommendation> \\t<pic_urls></pic_urls>\\t<comment_topic_id>0</comment_topic_id>\\t<cover_235_1><![CDATA[]]></cover_235_1> \\t<cover_1_1><![CDATA[]]></cover_1_1> <cover_16_9><![CDATA[]]></cover_16_9> <appmsg_like_type>0</appmsg_like_type> <video_width>0</video_width> <video_height>0</video_height> <is_pay_subscribe>0</is_pay_subscribe> <summary><![CDATA[]]></summary> \\t<general_string><![CDATA[]]></general_string> <finder_feed></finder_feed> <finder_live></finder_live> \\t</item> \\t\\t</category> \\t\\t<publisher> \\t\\t\\t<username><![CDATA[gh_f0a92aa7146c]]></username> \\t\\t\\t<nickname><![CDATA[微信收款助手]]></nickname> \\t\\t</publisher> \\t\\t<template_header><title><![CDATA[收款到账通知]]></title>\\n<title_color><![CDATA[]]></title_color>\\n<pub_time>1685325848</pub_time>\\n<first_data><![CDATA[05月29日 10:04]]></first_data>\\n<first_color><![CDATA[#888888]]></first_color>\\n<hide_title_and_time>1</hide_title_and_time>\\n<show_icon_and_display_name>1</show_icon_and_display_name>\\n<display_name><![CDATA[个人收款服务]]></display_name>\\n<icon_url><![CDATA[https://gtimg.wechatpay.cn/resource/xres/img/202209/11b254da3d3c31cae6ae9c3df3a07c96_132x132.png]]></icon_url>\\n<hide_icon_and_display_name_line>0</hide_icon_and_display_name_line>\\n<header_jump_url><![CDATA[]]></header_jump_url>\\n<shortcut_icon_url><![CDATA[]]></shortcut_icon_url>\\n<ignore_hide_title_and_time>1</ignore_hide_title_and_time>\\n<hide_time>1</hide_time>\\n<pay_style>1</pay_style>\\n<header_jump_type>0</header_jump_type>\\n<display_name_desc><![Line truncated
WxMsgHandle.解析扫码支付第二段(new JsonObject(smg).mapTo(PrivateChatMsg.class));
}
}