This commit is contained in:
Van0313
2025-07-08 21:23:11 +08:00
parent 2fb1a45e5e
commit 58a1b30de9
2 changed files with 88 additions and 1 deletions

View File

@@ -0,0 +1,80 @@
package cn.van.business.util;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.stereotype.Component;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Leo
* @version 1.0
* @create 2025/7/8 21:13
* @description
*/
@Component
public class OtherUtil {
final WXUtil wxUtil;
public OtherUtil(WXUtil wxUtil) {
this.wxUtil = wxUtil;
}
public void tmyk(String msg, String fromWxid) {
// 正则表达式匹配pagepath标签中的tid参数值
// 解释:
// <pagepath><!\[CDATA\[ 匹配pagepath的CDATA开始标签
// [^\]]*?tid= 非贪婪匹配任意字符直到遇到tid=
// (\d+) 捕获一个或多个数字tid的值
// \]\]> 匹配CDATA结束标签
String regex = "<pagepath><!\\[CDATA\\[[^\\]]*?tid=(\\d+)\\]\\]></pagepath>";
// 编译正则表达式,忽略大小写(防止标签大小写不一致)
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(msg);
// 查找匹配项
if (matcher.find()) {
// 返回第一个捕获组即tid的值
String tid = matcher.group(1);
// 构建post请求 url:https://tm.wx.hackp.net/App/zm/getlist参数tid=tid放在body
String url = "https://tm.wx.hackp.net/App/zm/getlist";
String response = HttpRequest.post(url)
.body("tid=" + tid)
.execute().body();
if (Util.isNotEmpty(response)) {
JSONObject jsonObject = JSON.parseObject(response);
/**
* {
* "code": "1",
* "msg": {
* "id": "1987",
* "type": "3",
* "tid": "52",
* "hot": "2",
* "title": "头条号项目玩法,从账号注册,素材获取到视频制作发布和裂变全方位教学 ",
* "picname": "https://tm.wx.hackp.net/data/attachment/temp/202111/07/130031qb5lw95b259ehlnn.jpg_thumb.jpg",
* "content": "<span style=\"color:#555555;font-family:&quot;font-size:large;background-color:#FFFFFF;\">1.项目玩法介绍mp4</span><br />\r\n<br />\r\n<span style=\"color:#555555;font-family:&quot;font-size:large;background-color:#FFFFFF;\">2.账号注册.mp4</span><br />\r\n<br />\r\n<span style=\"color:#555555;font-family:&quot;font-size:large;background-color:#FFFFFF;\">3.素材获取mp4</span><br />\r\n<br />\r\n<span style=\"color:#555555;font-family:&quot;font-size:large;background-color:#FFFFFF;\">4.视频批星制作.mp4</span><br />\r\n<br />\r\n<span style=\"color:#555555;font-family:&quot;font-size:large;background-color:#FFFFFF;\">5.视频发布.mp4</span><br />\r\n<br />\r\n<span style=\"color:#555555;font-family:&quot;font-size:large;background-color:#FFFFFF;\">6.视频裂变.mp4</span>",
* "count": "10122",
* "dizhi": "下载地址:链接: https://pan.baidu.com/s/104YEJVgTx4ZSNVJjw7n9oQ提取码: 92kr",
* "price": "0",
* "addtime": "1636261305",
* "status": "1",
* "hackp_id": "36657",
* "buygoods": null
* }
* }
* */
JSONObject msgResponse = jsonObject.getJSONObject("msg");
// title和dizhi
wxUtil.sendTextMessage(fromWxid, msgResponse.getString("title") + "\n" + msgResponse.getString("dizhi"), 0, null, true);
} else {
wxUtil.sendTextMessage(fromWxid, "请求失败", 0, null, true);
}
} else {
wxUtil.sendTextMessage(fromWxid, "没有匹配到tid", 0, null, true);
}
}
}

View File

@@ -26,9 +26,12 @@ public class WxMessageConsumer {
private final JDUtil jdUtils;
private final OtherUtil otherUtil;
@Autowired
public WxMessageConsumer(@Lazy JDUtil jdUtils) {
public WxMessageConsumer(@Lazy JDUtil jdUtils, OtherUtil otherUtil) {
this.jdUtils = jdUtils;
this.otherUtil = otherUtil;
}
@Async("threadPoolTaskExecutor")
@@ -77,6 +80,10 @@ public class WxMessageConsumer {
jdUtils.sendOrderToWxByOrderD(msg.replace("", ""), fromWxid);
return;
}
if (msg.contains("<sourcedisplayname>唐门云课</sourcedisplayname>")){
logger.info("消息来自唐门云课,处理指令消息" );
otherUtil.tmyk(msg,fromWxid);
}
logger.info("未命中前置指令,开始命中 Default 流程");
jdUtils.sendOrderToWxByOrderDefault(msg, fromWxid);
}