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参数值 // 解释: // 匹配CDATA结束标签 String regex = ""; // 编译正则表达式,忽略大小写(防止标签大小写不一致) 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": "1.项目玩法介绍mp4
\r\n
\r\n2.账号注册.mp4
\r\n
\r\n3.素材获取mp4
\r\n
\r\n4.视频批星制作.mp4
\r\n
\r\n5.视频发布.mp4
\r\n
\r\n6.视频裂变.mp4", * "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); } } }