This commit is contained in:
雷欧(林平凡)
2025-02-26 15:02:44 +08:00
parent 5b0ea491a5
commit d8c3450426
2 changed files with 127 additions and 22 deletions

View File

@@ -191,7 +191,7 @@ public class WxMessageConsumer {
//}
private static String getUrlStr(String msg) {
//String urlPattern = "https?://[\\w-\\.]+(\\.[a-z]{2,})?(/[\\w-./?%&=]*)?"
String urlPattern = "https?://[^\\s]+?\\.(html|htm)(\\?[^\\s]*?)?";
String urlPattern = "https?://\\S+?\\.(html|htm)(\\?\\S*?)?";
Pattern pattern = Pattern.compile(urlPattern);
Matcher matcher = pattern.matcher(msg);
@@ -207,7 +207,7 @@ public class WxMessageConsumer {
// 移除最后一个字符(即问号)
finallyUrl = finallyUrl.substring(0, finallyUrl.length() - 1);
}
if (finallyUrl.contains("item.m.jd.com/product")) {
if (finallyUrl != null && finallyUrl.contains("item.m.jd.com/product")) {
finallyUrl = finallyUrl.replace("item.m.jd.com/product", "item.jd.com");
}
return finallyUrl;