Compare commits

...

36 Commits

Author SHA1 Message Date
Leo
316cc7ea48 1 2025-12-02 17:39:35 +08:00
Leo
33d70cf266 1 2025-12-02 01:44:27 +08:00
Leo
ed1f241d9a 1 2025-12-02 01:34:30 +08:00
Leo
2a77188468 1 2025-11-05 16:50:24 +08:00
Leo
fb72e5284d 1 2025-11-05 16:36:54 +08:00
雷欧(林平凡)
3cc419dc17 1 2025-09-04 18:03:42 +08:00
雷欧(林平凡)
c488e94534 1 2025-09-04 17:54:18 +08:00
雷欧(林平凡)
204dae5860 1 2025-09-04 17:38:27 +08:00
d606d4a9d3 1 2025-08-31 02:14:53 +08:00
0cfa0b9bbf 1 2025-08-31 02:08:17 +08:00
3960baa105 1 2025-08-31 00:50:01 +08:00
ec9416e390 1 2025-08-31 00:24:44 +08:00
07c2ee659b 1 2025-08-30 23:55:11 +08:00
雷欧(林平凡)
78e32fbbf1 1 2025-07-29 16:28:29 +08:00
雷欧(林平凡)
3edd22705e 1 2025-07-29 16:04:54 +08:00
雷欧(林平凡)
5a412dc22e 1 2025-02-11 16:01:56 +08:00
雷欧(林平凡)
fd399c53b5 1 2025-02-05 09:54:27 +08:00
雷欧(林平凡)
2e5f5fdf88 1 2025-01-22 10:06:14 +08:00
雷欧(林平凡)
8279b4d8b2 1 2025-01-22 09:54:59 +08:00
雷欧(林平凡)
eb1a18f7a3 1 2025-01-22 09:52:12 +08:00
雷欧(林平凡)
687adfe3f8 1 2025-01-22 09:49:42 +08:00
雷欧(林平凡)
351c37ee2f 1 2025-01-22 09:44:31 +08:00
雷欧(林平凡)
f549846e1e 1 2025-01-21 14:31:39 +08:00
雷欧(林平凡)
f95035345d 1 2025-01-21 14:09:34 +08:00
雷欧(林平凡)
482aa645ab Merge remote-tracking branch '群晖/master' 2025-01-21 14:06:56 +08:00
雷欧(林平凡)
b6d1dbadc3 1 2025-01-21 14:05:40 +08:00
Leo
e6cda34b73 1 2025-01-20 17:36:03 +08:00
Leo
082ddc5c0d 爬虫写到论坛网站 2024-04-29 17:52:20 +08:00
Leo
0f73cd01d0 pdd 2024-04-28 11:27:02 +08:00
Leo
ed28a27057 精简 2024-02-21 15:25:56 +08:00
Leo
2fd73c9fd1 精简 2024-01-16 15:46:35 +08:00
Leo
7f206d1a8f 精简 2024-01-11 14:33:59 +08:00
Leo
586d9b75c1 1 2024-01-11 14:08:12 +08:00
Leo
43e9f6112d 去掉换行\n 替换成<br/> 2023-12-25 13:50:41 +08:00
Leo
f739a6653a 去掉换行\n 替换成<br/> 2023-12-25 11:39:20 +08:00
Leo
c089add752 jekins 推送测试 2023-12-20 10:50:01 +08:00
41 changed files with 3258 additions and 708 deletions

70
pom.xml
View File

@@ -13,7 +13,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.6.13</spring-boot.version>
<fastjson.version>2.0.14</fastjson.version>
<hutool.version>5.8.8</hutool.version>
<hutool.version>5.8.24</hutool.version>
<jwt.version>0.9.1</jwt.version>
</properties>
<dependencies>
@@ -31,6 +31,19 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--
降级Java的版本降级到Java 8或者更低版本这些版本包含了这些包。
添加缺失的依赖如果你不希望降级Java的版本你可以通过添加缺失的依赖来解决这个问题。
如果缺少的是javax.rmi.CORBA包添加以下依赖
-->
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>jakarta.activation</artifactId>
<version>1.2.1</version>
</dependency>
<!-- redis 缓存操作 -->
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -77,11 +90,46 @@
<artifactId>UserAgentUtils</artifactId>
<version>1.21</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<!-- 京东依赖-->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.2</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
@@ -124,6 +172,26 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>1.6.10</version>
<executions>
<execution>
<id>compile</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/main/java</source>
<source>target/generated-sources/annotations</source>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@@ -1,11 +1,13 @@
package cn.van333.wxsend;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@SpringBootApplication
@EnableWebMvc
@MapperScan("cn.van333.wxsend.business.mapper")
public class WxSendApplication {
public static void main(String[] args) {

View File

@@ -3,7 +3,10 @@ package cn.van333.wxsend.aop.annotation;
import cn.van333.wxsend.constant.CacheConstants;
import cn.van333.wxsend.enums.LimitType;
import java.lang.annotation.*;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author Leo

View File

@@ -1,9 +1,5 @@
package cn.van333.wxsend.aop.aspectj;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
import cn.van333.wxsend.aop.annotation.RateLimiter;
import cn.van333.wxsend.enums.LimitType;
import cn.van333.wxsend.exception.ServiceException;
@@ -20,6 +16,10 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.script.RedisScript;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
/**
* 限流处理

View File

@@ -0,0 +1,44 @@
package cn.van333.wxsend.business.controller;
import cn.hutool.core.util.StrUtil;
import cn.van333.wxsend.aop.annotation.RateLimiter;
import cn.van333.wxsend.business.model.R;
import cn.van333.wxsend.business.service.LogService;
import cn.van333.wxsend.enums.WXMessageType;
import cn.van333.wxsend.util.TokenUtil;
import cn.van333.wxsend.util.WxSendUtil;
import cn.van333.wxsend.util.request.MessageRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Leo
* @version 1.0
* @create 2023/10/07 0007 下午 02:25
* @description
*/
@RestController
@RequestMapping("/dc")
public class DCController {
private static final Logger logger = LoggerFactory.getLogger(LogService.class);
@RequestMapping(value = "/send/ty")
@ResponseBody
@RateLimiter(time = 10, count = 60)
public R sendToTY(@RequestBody MessageRequest message) throws Exception {
logger.info(message.toString());
if (!TokenUtil.checkToken(message.getVanToken())) {
return R.error("vanToken无效");
}
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
return R.error("缺少标题和内容");
}
String result = WxSendUtil.sendNotifyForMpnews(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.TY);
return R.ok(result);
}
}

View File

@@ -0,0 +1,29 @@
package cn.van333.wxsend.business.controller;
import cn.van333.wxsend.aop.annotation.RateLimiter;
import cn.van333.wxsend.business.model.R;
import cn.van333.wxsend.business.service.LogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Leo
* @version 1.0
* @create 2023/10/07 0007 下午 02:25
* @description
*/
@RestController
@RequestMapping("/pdd")
public class PddController {
private static final Logger logger = LoggerFactory.getLogger(LogService.class);
@RequestMapping(value = "/callback")
@ResponseBody
@RateLimiter(time = 1, count = 60)
public R send() {
return R.ok();
}
}

View File

@@ -5,15 +5,18 @@ import cn.hutool.core.util.StrUtil;
import cn.van333.wxsend.aop.annotation.RateLimiter;
import cn.van333.wxsend.business.model.R;
import cn.van333.wxsend.business.service.LogService;
import cn.van333.wxsend.util.TokenUtil;
import cn.van333.wxsend.enums.WXMessageType;
import cn.van333.wxsend.util.SourceForQLUtil;
import cn.van333.wxsend.util.TokenUtil;
import cn.van333.wxsend.util.WxSendUtil;
import cn.van333.wxsend.util.request.MessageRequest;
import cn.van333.wxsend.util.SourceForQLUtil;
import com.alibaba.fastjson2.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@@ -46,7 +49,7 @@ public class WXController {
if (ObjectUtil.isEmpty(WXMessageType.valueOf(message.getMessageType()))) {
return R.error("消息类型不存在");
}
String result = WxSendUtil.sendNotify(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.valueOf(message.getMessageType()));
String result = WxSendUtil.sendNotifyForMpnews(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.valueOf(message.getMessageType()));
return R.ok(result);
}
@@ -81,10 +84,11 @@ public class WXController {
logger.info("vanToken 打印---{}",vanToken);
logger.info("source 打印---{}",source);
String sourceForQL = SourceForQLUtil.transferSource(source);
String a = "";
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
return R.error("缺少标题和内容");
}
String result = WxSendUtil.sendNotify("("+sourceForQL+") "+message.getTitle(), message.getText(), message.getTouser(), WXMessageType.QL);
String result = WxSendUtil.sendNotifyForMpnews("("+sourceForQL+") "+message.getTitle(), message.getText(), message.getTouser(), WXMessageType.QL);
logger.info("result 打印---{}",result);
return R.ok(result);
@@ -102,7 +106,7 @@ public class WXController {
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
return R.error("缺少标题和内容");
}
String result = WxSendUtil.sendNotify(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.QH);
String result = WxSendUtil.sendNotifyForMpnews(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.QH);
return R.ok(result);
}
@@ -118,25 +122,11 @@ public class WXController {
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
return R.error("缺少标题和内容");
}
String result = WxSendUtil.sendNotify(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.MT);
String result = WxSendUtil.sendNotifyForMpnews(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.MT);
return R.ok(result);
}
@RequestMapping(value = "/send/imt")
@ResponseBody
@RateLimiter(time = 1, count = 60)
public R sendToIMT(@RequestBody MessageRequest message) throws Exception {
logger.info(message.toString());
if (!TokenUtil.checkToken(message.getVanToken())) {
return R.error("vanToken无效");
}
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
return R.error("缺少标题和内容");
}
String result = WxSendUtil.sendNotify(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.IMT);
return R.ok(result);
}
@RequestMapping(value = "/send/ty")
@ResponseBody
@@ -150,11 +140,11 @@ public class WXController {
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
return R.error("缺少标题和内容");
}
String result = WxSendUtil.sendNotify(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.TY);
String result = WxSendUtil.sendNotifyForMpnews(message.getTitle(), message.getText(), message.getTouser(), WXMessageType.TY);
return R.ok(result);
}
@RequestMapping(value = "/send/lf")
@RequestMapping(value = "/send/jenkins")
@ResponseBody
@RateLimiter(time = 5, count = 60)
public R sendToLF(HttpServletRequest request, @RequestBody MessageRequest message) throws Exception {
@@ -179,7 +169,7 @@ public class WXController {
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
return R.error("缺少标题和内容");
}
String result = WxSendUtil.sendNotify("("+sourceForQL+") "+message.getTitle(), message.getText(), message.getTouser(), WXMessageType.LF);
String result = WxSendUtil.sendNotifyForMpnews("("+sourceForQL+") "+message.getTitle(), message.getText(), message.getTouser(), WXMessageType.JENKINS);
logger.info("result 打印---{}",result);
return R.ok(result);
@@ -187,7 +177,7 @@ public class WXController {
@RequestMapping(value = "/send/jd")
@ResponseBody
@RateLimiter(time = 5, count = 60)
@RateLimiter(time = 2, count = 1)
public R sendToJD(HttpServletRequest request, @RequestBody MessageRequest message) throws Exception {
logger.info("message 打印---{}",JSON.toJSONString(message));
String vanToken = request.getHeader("vanToken");
@@ -197,23 +187,46 @@ public class WXController {
if (!TokenUtil.checkToken(vanToken)) {
return R.error("vanToken无效");
}
String source = request.getHeader("source");
if (StrUtil.isEmpty(source)) {
return R.error("来源为空");
}
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
return R.error("缺少标题和内容");
}
logger.info("vanToken 打印---{}",vanToken);
logger.info("source 打印---{}",source);
String sourceForQL = SourceForQLUtil.transferSource(source);
if (!StrUtil.isAllNotEmpty(message.getTitle(), message.getText())) {
return R.error("缺少标题和内容");
}
String result = WxSendUtil.sendNotify("("+sourceForQL+") "+message.getTitle(), message.getText(), message.getTouser(), WXMessageType.JD);
String result = WxSendUtil.sendNotifyForText(message.getText(), message.getTouser(), WXMessageType.JD);
logger.info("result 打印---{}",result);
return R.ok(result);
}
@RequestMapping(value = "/send/pdd")
@ResponseBody
@RateLimiter(time = 2, count = 1)
public R sendToPDD(HttpServletRequest request, @RequestBody MessageRequest message) throws Exception {
logger.info("message 打印---{}",JSON.toJSONString(message));
String vanToken = request.getHeader("vanToken");
if (StrUtil.isEmpty(vanToken)) {
return R.error("vanToken为空");
}
if (!TokenUtil.checkToken(vanToken)) {
return R.error("vanToken无效");
}
String result = WxSendUtil.sendNotifyForText(message.getText(), message.getTouser(), WXMessageType.PDD);
logger.info("result 打印---{}",result);
return R.ok(result);
}
//@RequestMapping("/ok")
//@RateLimiter(time = 5, count = 60)
//public R ok(HttpServletRequest request,String content) throws Exception {
// String vanToken = request.getHeader("vanToken");
// if (StrUtil.isEmpty(vanToken)) {
// return R.error("vanToken为空");
// }
// if (!TokenUtil.checkToken(vanToken)) {
// return R.error("vanToken无效");
// }
// if (StrUtil.isEmpty(content)){
//
// content = "【京东账号1\uD83C\uDD94】jd_4b607f3e4a512\\n【水果名称】赣南脐橙3斤装\\n【已兑换水果】7次\\n【助力您的好友】知吃滚水,jd_966018311\\n【今日共浇水】12次\\n【剩余水滴】75g\uD83D\uDCA7\\n【水果进度】66.00%已浇水396次,还需204次\\n【预测】17天之后(2024-01-11日)可兑换水果\uD83C\uDF49\\n\\n\\n【京东账号2\uD83C\uDD94】525024727_m\\n【水果名称】赣南脐橙3斤装\\n【已兑换水果】9次\\n【助力您的好友】Van_333,jd_966018311\\n【今日共浇水】12次\\n【剩余水滴】85g\uD83D\uDCA7\\n【水果进度】78.17%已浇水469次,还需131次\\n【预测】11天之后(2024-01-05日)可兑换水果\uD83C\uDF49\\n\\n\\n【京东账号3\uD83C\uDD94】jd_5945b09c30ffd\\n【水果名称】赣南脐橙3斤装\\n【已兑换水果】1次\\n【助力您的好友】Van_333,知吃滚水\\n【今日共浇水】12次\\n【剩余水滴】76g\uD83D\uDCA7\\n【水果进度】53.00%已浇水212次,还需188次\\n【预测】16天之后(2024-01-10日)可兑换水果\uD83C\uDF49\\n\\n\\n恭喜发财";
// }
// String result = WxSendUtil.sendNotify("测试", content,"", WXMessageType.JD);
//
// return R.ok(result);
//}
}

View File

@@ -0,0 +1,170 @@
package cn.van333.wxsend.business.controller;
import cn.hutool.core.util.StrUtil;
import cn.van333.wxsend.business.model.R;
import cn.van333.wxsend.business.service.LogService;
import cn.van333.wxsend.util.QywxWebhookUtil;
import cn.van333.wxsend.util.TokenUtil;
import cn.van333.wxsend.util.request.WebhookMessageRequest;
import cn.van333.wxsend.util.response.SendRespones;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/wx/webhook")
public class WXWebhookController {
private static final Logger logger = LoggerFactory.getLogger(LogService.class);
@Value("${qywx.webhook.key:}")
private String defaultKey;
@Value("${qywx.webhook.secret:}")
private String defaultSecret;
@RequestMapping("/send")
@ResponseBody
public R send(@RequestBody WebhookMessageRequest req) {
logger.info("webhook send req: {}", req);
if (!TokenUtil.checkToken(req.getVanToken())) {
return R.error("vanToken无效");
}
String key = StrUtil.isNotBlank(req.getKey()) ? req.getKey() : defaultKey;
String secret = StrUtil.isNotBlank(req.getSecret()) ? req.getSecret() : defaultSecret;
if (StrUtil.isBlank(key)) {
return R.error("缺少webhook key");
}
if (StrUtil.isBlank(req.getMsgtype())) {
return R.error("缺少msgtype");
}
SendRespones resp;
switch (req.getMsgtype().toLowerCase()) {
case "text":
resp = QywxWebhookUtil.sendText(key, secret, req.getContent(), req.getMentionedList(), req.getMentionedMobileList());
break;
case "markdown":
resp = QywxWebhookUtil.sendMarkdown(key, secret, req.getContent());
break;
case "image":
if (StrUtil.isNotBlank(req.getImageBase64()) && StrUtil.isNotBlank(req.getImageMd5())) {
resp = QywxWebhookUtil.sendImageByBase64(key, secret, req.getImageBase64(), req.getImageMd5());
} else if (StrUtil.isNotBlank(req.getImageUrl())) {
resp = QywxWebhookUtil.sendImageByUrl(key, secret, req.getImageUrl());
} else {
return R.error("image需要imageBase64+imageMd5或imageUrl");
}
break;
case "news":
if (req.getNewsArticles() == null || req.getNewsArticles().isEmpty()) {
return R.error("news需要articles");
}
java.util.List<java.util.Map<String, String>> arts = new java.util.ArrayList<>();
for (cn.van333.wxsend.util.request.NewsArticle a : req.getNewsArticles()) {
java.util.Map<String, String> m = new java.util.HashMap<>();
if (StrUtil.isNotBlank(a.getTitle())) m.put("title", a.getTitle());
if (StrUtil.isNotBlank(a.getDescription())) m.put("description", a.getDescription());
if (StrUtil.isNotBlank(a.getUrl())) m.put("url", a.getUrl());
if (StrUtil.isNotBlank(a.getPicurl())) m.put("picurl", a.getPicurl());
arts.add(m);
}
resp = QywxWebhookUtil.sendNews(key, secret, arts);
break;
case "file":
if (StrUtil.isNotBlank(req.getFileBase64()) && StrUtil.isNotBlank(req.getFileName())) {
byte[] bytes = java.util.Base64.getDecoder().decode(req.getFileBase64());
resp = QywxWebhookUtil.sendFile(key, secret, bytes, req.getFileName());
} else if (StrUtil.isNotBlank(req.getFileUrl())) {
try {
cn.hutool.http.HttpResponse r = cn.hutool.http.HttpRequest.get(req.getFileUrl()).execute();
String disp = r.header("Content-Disposition");
String name = req.getFileName();
if (StrUtil.isBlank(name)) {
name = "file";
}
resp = QywxWebhookUtil.sendFile(key, secret, r.bodyBytes(), name);
} catch (Exception e) {
return R.error("下载文件失败:" + e.getMessage());
}
} else {
return R.error("file需要fileBase64+fileName或fileUrl");
}
break;
case "template_card":
if (StrUtil.isBlank(req.getCardType())) {
return R.error("template_card需要cardType");
}
java.util.Map<String, Object> card = new java.util.HashMap<>();
card.put("card_type", req.getCardType());
if (StrUtil.isNotBlank(req.getCardSourceIconUrl()) || StrUtil.isNotBlank(req.getCardSourceDesc())) {
java.util.Map<String, Object> source = new java.util.HashMap<>();
if (StrUtil.isNotBlank(req.getCardSourceIconUrl())) source.put("icon_url", req.getCardSourceIconUrl());
if (StrUtil.isNotBlank(req.getCardSourceDesc())) source.put("desc", req.getCardSourceDesc());
card.put("source", source);
}
if (StrUtil.isNotBlank(req.getCardMainTitle()) || StrUtil.isNotBlank(req.getCardMainTitleDesc())) {
java.util.Map<String, Object> mainTitle = new java.util.HashMap<>();
if (StrUtil.isNotBlank(req.getCardMainTitle())) mainTitle.put("title", req.getCardMainTitle());
if (StrUtil.isNotBlank(req.getCardMainTitleDesc())) mainTitle.put("desc", req.getCardMainTitleDesc());
card.put("main_title", mainTitle);
}
if (StrUtil.isNotBlank(req.getCardEmphasisContentTitle()) || StrUtil.isNotBlank(req.getCardEmphasisContentDesc())) {
java.util.Map<String, Object> emphasis = new java.util.HashMap<>();
if (StrUtil.isNotBlank(req.getCardEmphasisContentTitle())) emphasis.put("title", req.getCardEmphasisContentTitle());
if (StrUtil.isNotBlank(req.getCardEmphasisContentDesc())) emphasis.put("desc", req.getCardEmphasisContentDesc());
card.put("emphasis_content", emphasis);
}
if (StrUtil.isNotBlank(req.getCardQuoteAreaType()) || StrUtil.isNotBlank(req.getCardQuoteAreaText())) {
java.util.Map<String, Object> quote = new java.util.HashMap<>();
if (StrUtil.isNotBlank(req.getCardQuoteAreaType())) quote.put("type", Integer.parseInt(req.getCardQuoteAreaType()));
if (StrUtil.isNotBlank(req.getCardQuoteAreaText())) quote.put("quote_text", req.getCardQuoteAreaText());
card.put("quote_area", quote);
}
if (StrUtil.isNotBlank(req.getCardJumpUrl())) {
card.put("card_action", new java.util.HashMap<String, Object>() {{ put("type", 1); put("url", req.getCardJumpUrl()); }});
}
if (req.getCardHorizontalContents() != null && !req.getCardHorizontalContents().isEmpty()) {
java.util.List<java.util.Map<String, Object>> list = new java.util.ArrayList<>();
for (cn.van333.wxsend.util.request.TemplateCardHorizontalContent hc : req.getCardHorizontalContents()) {
java.util.Map<String, Object> m = new java.util.HashMap<>();
if (StrUtil.isNotBlank(hc.getKeyname())) m.put("keyname", hc.getKeyname());
java.util.Map<String, Object> val = new java.util.HashMap<>();
val.put("type", 0);
if (StrUtil.isNotBlank(hc.getValue())) val.put("content", hc.getValue());
if (StrUtil.isNotBlank(hc.getUrl())) val.put("url", hc.getUrl());
m.put("value", val);
list.add(m);
}
card.put("horizontal_content_list", list);
}
if (req.getCardJumps() != null && !req.getCardJumps().isEmpty()) {
java.util.List<java.util.Map<String, Object>> list = new java.util.ArrayList<>();
for (cn.van333.wxsend.util.request.TemplateCardJump j : req.getCardJumps()) {
java.util.Map<String, Object> m = new java.util.HashMap<>();
if (StrUtil.isNotBlank(j.getType())) m.put("type", Integer.parseInt(j.getType()));
if (StrUtil.isNotBlank(j.getUrl())) m.put("url", j.getUrl());
if (StrUtil.isNotBlank(j.getTitle())) m.put("title", j.getTitle());
list.add(m);
}
card.put("jump_list", list);
}
resp = QywxWebhookUtil.sendTemplateCard(key, secret, card);
break;
default:
return R.error("不支持的msgtype");
}
if (resp.getErrcode() != null && resp.getErrcode().equals(0)) {
return R.ok("Webhook消息发送成功");
}
return R.error(resp.getErrmsg() == null ? "发送失败" : resp.getErrmsg());
}
}

View File

@@ -0,0 +1,91 @@
package cn.van333.wxsend.business.controller;
import cn.hutool.core.util.StrUtil;
import cn.van333.wxsend.business.model.R;
import cn.van333.wxsend.util.WeComCallbackCrypto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/wecom/callback")
public class WeComCallbackController {
private static final Logger logger = LoggerFactory.getLogger(WeComCallbackController.class);
@Value("${qywx.app.corpId:}")
private String corpId;
@Value("${qywx.app.token:}")
private String token;
@Value("${qywx.app.encodingAESKey:}")
private String encodingAESKey;
@GetMapping(produces = MediaType.TEXT_PLAIN_VALUE)
public String verify(@RequestParam("msg_signature") String msgSignature,
@RequestParam("timestamp") String timestamp,
@RequestParam("nonce") String nonce,
@RequestParam("echostr") String echostr) {
logger.info("WeCom callback verify: ts={}, nonce={}", timestamp, nonce);
WeComCallbackCrypto crypto = new WeComCallbackCrypto(token, encodingAESKey, corpId);
String plain = crypto.verifyURL(msgSignature, timestamp, nonce, echostr);
return plain;
}
@PostMapping(consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_PLAIN_VALUE)
public String receiveXml(@RequestParam("msg_signature") String msgSignature,
@RequestParam("timestamp") String timestamp,
@RequestParam("nonce") String nonce,
HttpServletRequest request) throws IOException {
String xml = readBody(request);
logger.info("WeCom callback received xml: {}", xml);
String encrypt = parseEncrypt(xml);
WeComCallbackCrypto crypto = new WeComCallbackCrypto(token, encodingAESKey, corpId);
String plainXml = crypto.decryptMsg(msgSignature, timestamp, nonce, encrypt);
logger.info("WeCom callback plain xml: {}", plainXml);
// TODO: 在此解析 plainXml 的 MsgType/Event/Content 等,进行业务处理
return "success";
}
private static String readBody(HttpServletRequest request) throws IOException {
StringBuilder sb = new StringBuilder();
try (BufferedReader reader = request.getReader()) {
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
}
return sb.toString();
}
private static String parseEncrypt(String xml) {
// 简单提取 <Encrypt><![CDATA[...]]></Encrypt>
String start = "<Encrypt><![CDATA[";
String end = "]]></Encrypt>";
int i = xml.indexOf(start);
int j = xml.indexOf(end);
if (i >= 0 && j > i) {
return xml.substring(i + start.length(), j);
}
// 兼容无 CDATA 的情况
start = "<Encrypt>";
end = "</Encrypt>";
i = xml.indexOf(start);
j = xml.indexOf(end);
if (i >= 0 && j > i) {
return xml.substring(i + start.length(), j);
}
throw new RuntimeException("Encrypt not found");
}
}

View File

@@ -0,0 +1,39 @@
package cn.van333.wxsend.business.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.annotation.Resource;
import java.util.Date;
/**
* @author Leo
* @version 1.0
* @create 2024/4/29 下午3:05
* @description
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Resource
public class FlarumDiscussion {
private Integer id;
private String title;
private int commentCount;
private int participantCount;
private int postNumberIndex;
private Date createdAt;
private Integer userId;
private Integer firstPostId;
private Date lastPostedAt;
private Integer lastPostedUserId;
private Integer lastPostId;
private Integer lastPostNumber;
private Date hiddenAt;
private Integer hiddenUserId;
private String slug;
private boolean isPrivate;
}

View File

@@ -0,0 +1,28 @@
package cn.van333.wxsend.business.model;
import lombok.Data;
import java.util.Date;
/**
* @author Leo
* @version 1.0
* @create 2024/4/29 下午3:08
* @description
*/
@Data
public class FlarumPost {
private int id;
private int discussionId;
private Integer number;
private Date createdAt;
private Integer userId;
private String type;
private String content;
private Date editedAt;
private Integer editedUserId;
private Date hiddenAt;
private Integer hiddenUserId;
private String ipAddress;
private boolean isPrivate;
}

View File

@@ -1,4 +1,4 @@
package cn.van333.wxsend.util.xcx;
package cn.van333.wxsend.business.model;
import lombok.Data;

View File

@@ -1,6 +1,8 @@
package cn.van333.wxsend.util.xcx;
package cn.van333.wxsend.business.model;
@lombok.Data
import lombok.Data;
@Data
public class respoenseModel {
private String code;
private Msg msg;

View File

@@ -0,0 +1,96 @@
package cn.van333.wxsend.business.service;
import cn.van333.wxsend.business.model.Msg;
import cn.van333.wxsend.business.model.respoenseModel;
import cn.van333.wxsend.util.QCUtil;
import com.alibaba.fastjson2.JSON;
import okhttp3.*;
import org.springframework.stereotype.Service;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import static java.lang.Thread.sleep;
/**
* @author Leo
* @version 1.0
* @create 2024/4/29 下午5:12
* @description
*/
@Service
public class PCService {
public static String content = "";
public void getData() throws InterruptedException {
// 6988
for (int i = 7200; i > 7000; i--) {
System.out.println("" + i + "次执行");
try {
MediaType mediaType = MediaType.parse("text/plain");
OkHttpClient client = new OkHttpClient().newBuilder().build();
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("tid", String.valueOf(i)).build();
Request request = new Request.Builder().url("https://tm.wx.hackp.net/App/zm/getlist").method("POST", body).addHeader("User-Agent", "Apifox/1.0.0 ").build();
Response response = client.newCall(request).execute();
if (response.body() != null) {
String result = response.body().string();
System.out.println(result);
respoenseModel respoenseModel = JSON.parseObject(result, respoenseModel.class);
Msg msg = respoenseModel.getMsg();
if (QCUtil.isNotAnyEmpty(msg.getTitle(), msg.getContent(), msg.getDizhi())) {
//content = content + appendHtml(msg.getTitle(), msg.getContent(), msg.getDizhi(), i);
insertToDb(msg.getTitle(), msg.getContent(), msg.getDizhi());
//youshuju++;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
sleep(100);
}
//// 有50条数据再写入文件
//if (youshuju % 100 == 0 && youshuju != 0) {
// //System.out.println(youshuju);
// j++;
// //System.out.println(content);
// String fileName = "爬取的第" + j + "页 ,最后的为" + i + "条";
// long l = System.currentTimeMillis() - start;
// System.out.println("用时:" + l + "ms," + l / 1000 + "s" + "," + l / 60000 + "min");
// createHtml(fileName, content);
// //sleep(200);
// content = "";
// youshuju = 0;
//}
}
}
public String insertToDb(String title, String content, String downloadUrl) {
content = content.replace("\\r\\n", "");
content = content.replace("<\\/span>", "");
return null;
}
public static String appendHtml(String title, String content, String downloadUrl, Integer i) {
content = content.replace("\\r\\n", "");
content = content.replace("<\\/span>", "");
content = "<span>\n" + " <h1>第" + i + " 条,标题:" + title + "</h1>\n" + "</span>" + content + "<span>\n" + " <h1>下载链接:" + downloadUrl + "</h1>\n" + "</span>";
return content;
}
public static void createHtml(String fileName, String content) {
String finallyFileName = "D:\\pacong\\xiaochengxu2\\" + fileName + ".html";
//System.out.println("finallyFileName ******** " + finallyFileName);
try (BufferedWriter writer = new BufferedWriter(new FileWriter(finallyFileName))) {
writer.write(content);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -1,59 +0,0 @@
//package cn.van333.wxsend.business;
//
///**
// * @author Leo
// * @version 1.0
// * @create 2023/11/22 0022 下午 01:49
// * @description
// */
///**
// * https://www.hxm5.com/t/2065908 线报抓取
// *
// * @param url
// * @return Quartet<String, String, List < String>,List<String>> 标题 内容 图片 超链接
// */
//public static Quartet<String, String, List<String>, List<String>> getShoppingTipInfo(String url) {
// String title = null;
// StringBuilder content = new StringBuilder();
// ArrayList<String> imageUrl = Lists.newArrayList();
// ArrayList<String> hrefUrl = Lists.newArrayList();
// try {
// URI host = URLUtil.getHost(new URL(url));
// Document jsoupDocument = getJsoupDocument(HttpUtil.get(url));
// Element elementById = jsoupDocument.body().getElementById("topic-desc");
// title = elementById.children().select("h1").text();
// // content in <p> element
// Elements elementsContents = elementById.children().select("p");
// for (Element elementsContent : elementsContents) {
// for (Node pChild : elementsContent.childNodes()) {
// if (pChild instanceof TextNode) {
// content.append(((TextNode) pChild).text());
// Node preNode = pChild.previousSibling();
// if (!(preNode instanceof TextNode)) {
// content.append(StringUtils.LF);
// }
// }
// if (pChild instanceof Element) {
// if (((Element) pChild).is("a")) { // a href url
// String href = host + pChild.attr("href");
// Request.Builder request = getRequestBuilder(href);
// request.removeHeader("Host");
// String resultJSJson = getOkHttp().newCall(request.build()).execute().request().url().toString();// Direct url
// content.append(resultJSJson);
// hrefUrl.add(href);
// content.append(StringUtils.LF);
// }
// if (((Element) pChild).is("img")) { // image url
// String imageHref = pChild.attr("data-original");
// content.append(imageHref);
// imageUrl.add(imageHref);
// content.append(StringUtils.LF);
// }
// }
// }
// }
// } catch (Exception e) {
// log.error(e.getMessage());
// }
// return Quartet.with(title, content.toString(), imageUrl, hrefUrl);
// }

View File

@@ -21,6 +21,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
http.authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN") // 设置admin/**路径需要ADMIN角色
.antMatchers("/wx/**").permitAll()
.antMatchers("/wecom/**").permitAll()
.anyRequest().authenticated() // 其他请求需要认证
.and()
.formLogin() // 启用默认登录页

View File

@@ -14,12 +14,12 @@ public enum WXMessageType {
QH("QH","1000003","ww929e7d6493c6336e","lHW1JT3tLB6WZXO_4ww0SdjhMoXtSPX7LBl_zqvY46g"),
// 美团
MT("MT","1000004","ww929e7d6493c6336e","kdViRoqUFJZcGQ2dAoJZwPTktQ-fovQPeTnloAbn7bg"),
// 爱茅台
IMT("IMT","1000005","ww929e7d6493c6336e","SpYfWAA4lougQECoQ3WNvZnJ31Po77NU-XSnuC8syGs"),
// 拼多多
PDD("PDD","1000005","ww929e7d6493c6336e","SpYfWAA4lougQECoQ3WNvZnJ31Po77NU-XSnuC8syGs"),
// TY
TY("TY","1000006","ww929e7d6493c6336e","sGrNc8uBd_Wp6hmme2oP_Rh37scmgGulPuCHiQ9PYcc"),
JD("JD","1000008","ww929e7d6493c6336e","neXT6KJ8FYVLR-LN455MAcFaeUYkVaTsAkIOqXx3wLA"),
LF("LF","1000009","ww929e7d6493c6336e","msWg3ugSSRFIXeWZuoGKN2MI2Kg9AJVAG6pCWFEeH5E"),;
JENKINS("JENKINS","1000009","ww929e7d6493c6336e","msWg3ugSSRFIXeWZuoGKN2MI2Kg9AJVAG6pCWFEeH5E"),;

View File

@@ -1,8 +1,6 @@
package cn.van333.wxsend.exception;
import cn.van333.wxsend.business.model.R;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

View File

@@ -0,0 +1,27 @@
package cn.van333.wxsend.util;
import org.springframework.stereotype.Component;
/**
* 最基础的工具类
*/
@Component
public class JDUtil {
public String generatePromotionText(String model, String price, String shopCouponLink, String orderLink, String subsidyLink) {
return "型号 " + model + " -- 到手价 " + price + "\n" +
"最高效的办法:\n" +
"复制去v兴操作找个人发一下点击领券加购物车\n" +
"转跳到去狗东领布贴,提交订单,价格就会直接成立\n" +
"不要自己去找,很多时候都是缺券或者走错店铺\n" +
"需要plus满减没有可以哞宝买 50左右\n" +
"✅PLUS独享立减\n" +
"✅40家居卡https://u.jd.com/KDyJKX3\n" +
"✅PLUS超级补贴 https://u.jd.com/KDyNOOZ\n" +
"✅100店铺券" + shopCouponLink + "\n" +
"✅以旧换新国补20%发全国\n" +
"补贴领取资格入口\n" + subsidyLink + "\n\n" +
"🛍下单:" + orderLink + "\n" +
"可以凑单3类9.4折或者5000-400到手更低";
}
}

View File

@@ -0,0 +1,61 @@
//package cn.van333.wxsend.util;
//
//import com.alibaba.fastjson2.JSON;
//import com.jd.open.api.sdk.DefaultJdClient;
//import com.jd.open.api.sdk.JdClient;
//import com.jd.open.api.sdk.domain.kplunion.OrderService.request.query.OrderRowReq;
//import com.jd.open.api.sdk.domain.kplunion.OrderService.response.query.OrderRowResp;
//import com.jd.open.api.sdk.request.JdRequest;
//import com.jd.open.api.sdk.request.kplunion.UnionOpenOrderRowQueryRequest;
//import com.jd.open.api.sdk.response.AbstractResponse;
//import com.jd.open.api.sdk.response.kplunion.UnionOpenOrderRowQueryResponse;
//
//import java.text.SimpleDateFormat;
//import java.util.Date;
//
///**
// * @author Leo
// * @version 1.0
// * @create 2024/11/5 17:40
// * @description
// */
//public class JDUtils {
// private static final String SERVER_URL =
// "https://api.jd.com/routerjson";
// private static final String APP_KEY =
// "98e21c89ae5610240ec3f5f575f86a59";
// private static final String SECRET_KEY =
// "3dcb6b23a1104639ac433fd07adb6dfb";
//
//
// public static void main(String[] args) throws Exception {
// String accessToken = "";
// JdClient client = new DefaultJdClient(SERVER_URL, accessToken, APP_KEY, SECRET_KEY);
// UnionOpenOrderRowQueryRequest request = new UnionOpenOrderRowQueryRequest();
// OrderRowReq orderReq = new OrderRowReq();
// orderReq.setPageIndex(1);
// orderReq.setPageSize(20);
// orderReq.setStartTime("2024-11-01 00:00:00");
// orderReq.setEndTime("2024-11-05 23:59:59");
// orderReq.setType(1);
//
//
// request.setOrderReq(orderReq);
// request.setVersion("1.0");
// request.setSignmethod("md5");
// // 时间戳格式为yyyy-MM-dd HH:mm:ss时区为GMT+8。API服务端允许客户端请求最大时间误差为10分钟
// Date date = new Date();
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// request.setTimestamp(simpleDateFormat.format(date));
//
//
// UnionOpenOrderRowQueryResponse response = client.execute(request);
// System.out.println("响应码:" + response.getQueryResult().getCode());
// System.out.println(JSON.toJSONString(response));
// OrderRowResp[] orderRowResps = response.getQueryResult().getData();
// //for (OrderRowResp orderRowResp : orderRowResps) {
// // System.out.println(orderRowResp.getOrderId());
// //}
// }
//
//}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,183 @@
package cn.van333.wxsend.util;
import cn.van333.wxsend.business.service.LogService;
import cn.van333.wxsend.util.response.SendRespones;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson2.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.hutool.http.HttpRequest.post;
/**
* 企业微信群机器人 Webhook 工具
* 参考文档https://developer.work.weixin.qq.com/document/path/99110
*/
public class QywxWebhookUtil {
private static final Logger logger = LoggerFactory.getLogger(LogService.class);
private static final String QYWX_ORIGIN = "https://qyapi.weixin.qq.com";
private static final String WEBHOOK_SEND = QYWX_ORIGIN + "/cgi-bin/webhook/send";
public static String buildUrl(String key) {
return WEBHOOK_SEND + "?key=" + key;
}
public static String buildSignedUrl(String key, String secret) {
if (secret == null || secret.isEmpty()) {
return buildUrl(key);
}
long timestamp = System.currentTimeMillis() / 1000;
String stringToSign = timestamp + "\n" + secret;
String sign = hmacSha256Base64(secret, stringToSign);
String encodedSign = URLEncoder.encode(sign, StandardCharsets.UTF_8);
return buildUrl(key) + "&timestamp=" + timestamp + "&sign=" + encodedSign;
}
public static SendRespones sendText(String key, String secret, String content,
List<String> mentionedList, List<String> mentionedMobileList) {
Map<String, Object> body = new HashMap<>();
body.put("msgtype", "text");
Map<String, Object> text = new HashMap<>();
text.put("content", content);
if (mentionedList != null && !mentionedList.isEmpty()) {
text.put("mentioned_list", mentionedList);
}
if (mentionedMobileList != null && !mentionedMobileList.isEmpty()) {
text.put("mentioned_mobile_list", mentionedMobileList);
}
body.put("text", text);
return doSend(buildSignedUrl(key, secret), body);
}
public static SendRespones sendMarkdown(String key, String secret, String content) {
Map<String, Object> body = new HashMap<>();
body.put("msgtype", "markdown");
Map<String, Object> markdown = new HashMap<>();
markdown.put("content", content);
body.put("markdown", markdown);
return doSend(buildSignedUrl(key, secret), body);
}
public static SendRespones sendImageByBase64(String key, String secret, String base64, String md5) {
Map<String, Object> body = new HashMap<>();
body.put("msgtype", "image");
Map<String, Object> image = new HashMap<>();
image.put("base64", base64);
image.put("md5", md5);
body.put("image", image);
return doSend(buildSignedUrl(key, secret), body);
}
public static SendRespones sendImageByUrl(String key, String secret, String imageUrl) {
try {
HttpResponse resp = HttpRequest.get(imageUrl).execute();
byte[] bytes = resp.bodyBytes();
String base64 = java.util.Base64.getEncoder().encodeToString(bytes);
String md5 = DigestUtil.md5Hex(bytes);
return sendImageByBase64(key, secret, base64, md5);
} catch (Exception e) {
return new SendRespones(500, e.getMessage());
}
}
public static SendRespones sendNews(String key, String secret, java.util.List<Map<String, String>> articles) {
Map<String, Object> body = new HashMap<>();
body.put("msgtype", "news");
Map<String, Object> news = new HashMap<>();
news.put("articles", articles);
body.put("news", news);
return doSend(buildSignedUrl(key, secret), body);
}
public static SendRespones sendFile(String key, String secret, byte[] fileBytes, String fileName) {
try {
String uploadUrl = QYWX_ORIGIN + "/cgi-bin/webhook/upload_media?key=" + key + "&type=file";
String boundary = "----WebKitFormBoundary" + System.currentTimeMillis();
String contentType = "multipart/form-data; boundary=" + boundary;
StringBuilder sb = new StringBuilder();
sb.append("--").append(boundary).append("\r\n");
sb.append("Content-Disposition: form-data; name=\"media\"; filename=\"")
.append(fileName).append("\"\r\n");
sb.append("Content-Type: application/octet-stream\r\n\r\n");
byte[] prefix = sb.toString().getBytes(StandardCharsets.UTF_8);
byte[] suffix = ("\r\n--" + boundary + "--\r\n").getBytes(StandardCharsets.UTF_8);
byte[] body = new byte[prefix.length + fileBytes.length + suffix.length];
System.arraycopy(prefix, 0, body, 0, prefix.length);
System.arraycopy(fileBytes, 0, body, prefix.length, fileBytes.length);
System.arraycopy(suffix, 0, body, prefix.length + fileBytes.length, suffix.length);
String responseStr = HttpRequest.post(uploadUrl)
.header("Content-Type", contentType)
.body(body)
.execute().body();
logger.info("文件上传响应: {}", responseStr);
com.alibaba.fastjson2.JSONObject obj = JSON.parseObject(responseStr);
String mediaId = obj.getString("media_id");
if (mediaId == null) {
return new SendRespones(500, obj.getString("errmsg"));
}
Map<String, Object> sendBody = new HashMap<>();
sendBody.put("msgtype", "file");
Map<String, Object> file = new HashMap<>();
file.put("media_id", mediaId);
sendBody.put("file", file);
return doSend(buildSignedUrl(key, secret), sendBody);
} catch (Exception e) {
return new SendRespones(500, e.getMessage());
}
}
public static SendRespones sendTemplateCard(String key, String secret, Map<String, Object> card) {
Map<String, Object> body = new HashMap<>();
body.put("msgtype", "template_card");
body.put("template_card", card);
return doSend(buildSignedUrl(key, secret), body);
}
private static SendRespones doSend(String url, Map<String, Object> body) {
String json = JSON.toJSONString(body);
logger.info("企业微信 Webhook 请求: url={}, body={}", url, json);
String responseStr = post(url).body(json).execute().body();
logger.info("企业微信 Webhook 响应: {}", responseStr);
try {
SendRespones resp = JSON.parseObject(responseStr, SendRespones.class);
if (resp == null) {
return new SendRespones(500, "empty response");
}
return resp;
} catch (Exception e) {
return new SendRespones(500, e.getMessage());
}
}
private static String hmacSha256Base64(String secret, String data) {
try {
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
byte[] signData = mac.doFinal(data.getBytes(StandardCharsets.UTF_8));
return java.util.Base64.getEncoder().encodeToString(signData);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -1,221 +0,0 @@
package cn.van333.wxsend.util;
import cn.van333.wxsend.util.str.Constants;
import cn.van333.wxsend.util.str.Convert;
import cn.van333.wxsend.util.str.StringUtils;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* 客户端工具类
*
* @author ruoyi
*/
public class ServletUtils
{
/**
* 获取String参数
*/
public static String getParameter(String name)
{
return getRequest().getParameter(name);
}
/**
* 获取String参数
*/
public static String getParameter(String name, String defaultValue)
{
return Convert.toStr(getRequest().getParameter(name), defaultValue);
}
/**
* 获取Integer参数
*/
public static Integer getParameterToInt(String name)
{
return Convert.toInt(getRequest().getParameter(name));
}
/**
* 获取Integer参数
*/
public static Integer getParameterToInt(String name, Integer defaultValue)
{
return Convert.toInt(getRequest().getParameter(name), defaultValue);
}
/**
* 获取Boolean参数
*/
public static Boolean getParameterToBool(String name)
{
return Convert.toBool(getRequest().getParameter(name));
}
/**
* 获取Boolean参数
*/
public static Boolean getParameterToBool(String name, Boolean defaultValue)
{
return Convert.toBool(getRequest().getParameter(name), defaultValue);
}
/**
* 获得所有请求参数
*
* @param request 请求对象{@link ServletRequest}
* @return Map
*/
public static Map<String, String[]> getParams(ServletRequest request)
{
final Map<String, String[]> map = request.getParameterMap();
return Collections.unmodifiableMap(map);
}
/**
* 获得所有请求参数
*
* @param request 请求对象{@link ServletRequest}
* @return Map
*/
public static Map<String, String> getParamMap(ServletRequest request)
{
Map<String, String> params = new HashMap<>();
for (Map.Entry<String, String[]> entry : getParams(request).entrySet())
{
params.put(entry.getKey(), StringUtils.join(entry.getValue(), ","));
}
return params;
}
/**
* 获取request
*/
public static HttpServletRequest getRequest()
{
return getRequestAttributes().getRequest();
}
/**
* 获取response
*/
public static HttpServletResponse getResponse()
{
return getRequestAttributes().getResponse();
}
/**
* 获取session
*/
public static HttpSession getSession()
{
return getRequest().getSession();
}
public static ServletRequestAttributes getRequestAttributes()
{
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
return (ServletRequestAttributes) attributes;
}
/**
* 将字符串渲染到客户端
*
* @param response 渲染对象
* @param string 待渲染的字符串
*/
public static void renderString(HttpServletResponse response, String string)
{
try
{
response.setStatus(200);
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
response.getWriter().print(string);
}
catch (IOException e)
{
e.printStackTrace();
}
}
/**
* 是否是Ajax异步请求
*
* @param request
*/
public static boolean isAjaxRequest(HttpServletRequest request)
{
String accept = request.getHeader("accept");
if (accept != null && accept.contains("application/json"))
{
return true;
}
String xRequestedWith = request.getHeader("X-Requested-With");
if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest"))
{
return true;
}
String uri = request.getRequestURI();
if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml"))
{
return true;
}
String ajax = request.getParameter("__ajax");
return StringUtils.inStringIgnoreCase(ajax, "json", "xml");
}
/**
* 内容编码
*
* @param str 内容
* @return 编码后的内容
*/
public static String urlEncode(String str)
{
try
{
return URLEncoder.encode(str, Constants.UTF8);
}
catch (UnsupportedEncodingException e)
{
return StringUtils.EMPTY;
}
}
/**
* 内容解码
*
* @param str 内容
* @return 解码后的内容
*/
public static String urlDecode(String str)
{
try
{
return URLDecoder.decode(str, Constants.UTF8);
}
catch (UnsupportedEncodingException e)
{
return StringUtils.EMPTY;
}
}
}

View File

@@ -13,17 +13,22 @@ public class SourceForQLUtil {
private static final String QH_UBUNTU = "QH_UBUNTU";
public static final String XZJ_UBUNTU = "XZJ_UBUNTU";
public static final String PVE_UBUNTU = "PVE_UBUNTU";
public static String transferSource(String source){
if (source.equals(QH)){
return "群晖";
}else if (source.equals(QH_UBUNTU)){
return "群晖-Ubuntu";
}else if (source.equals(XZJ_UBUNTU)){
return "小主机-Ubuntu";
}else {
return "未知";
switch (source) {
case QH:
return "群晖";
case QH_UBUNTU:
return "群晖-Ubuntu";
case XZJ_UBUNTU:
return "小主机-Ubuntu";
case PVE_UBUNTU:
return "PVE-Ubuntu";
default:
return "未知";
}
}
}

View File

@@ -0,0 +1,164 @@
package cn.van333.wxsend.util;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.Base64;
import java.util.Comparator;
/**
* 企业微信回调加解密工具(等价于官方 WXBizMsgCrypt 的精简实现)。
* 参考https://developer.work.weixin.qq.com/document/path/90238
*/
public class WeComCallbackCrypto {
private static final String AES_ALGORITHM = "AES/CBC/NoPadding";
private final String token;
private final byte[] aesKey; // 32字节
private final String corpId;
private final byte[] iv;
public WeComCallbackCrypto(String token, String encodingAESKey, String corpId) {
this.token = token;
this.aesKey = Base64.getDecoder().decode(encodingAESKey + "=");
this.corpId = corpId;
this.iv = Arrays.copyOfRange(aesKey, 0, 16);
}
public String verifyURL(String msgSignature, String timestamp, String nonce, String echoStr) {
String sign = sha1(token, timestamp, nonce, echoStr);
if (!sign.equals(msgSignature)) {
throw new RuntimeException("signature not match");
}
String plain = decrypt(echoStr);
return plain;
}
public String decryptMsg(String msgSignature, String timestamp, String nonce, String encrypt) {
String sign = sha1(token, timestamp, nonce, encrypt);
if (!sign.equals(msgSignature)) {
throw new RuntimeException("signature not match");
}
return decrypt(encrypt);
}
public String encryptMsg(String reply, String timestamp, String nonce) {
String encrypt = encrypt(reply);
String sign = sha1(token, timestamp, nonce, encrypt);
// 返回 XML与官方结构一致
return "<xml>" +
"<Encrypt><![CDATA[" + encrypt + "]]></Encrypt>" +
"<MsgSignature><![CDATA[" + sign + "]]></MsgSignature>" +
"<TimeStamp>" + timestamp + "</TimeStamp>" +
"<Nonce><![CDATA[" + nonce + "]]></Nonce>" +
"</xml>";
}
private String decrypt(String base64CipherText) {
try {
byte[] cipherData = Base64.getDecoder().decode(base64CipherText);
Cipher cipher = Cipher.getInstance(AES_ALGORITHM);
SecretKeySpec keySpec = new SecretKeySpec(aesKey, "AES");
cipher.init(Cipher.DECRYPT_MODE, keySpec, new IvParameterSpec(iv));
byte[] plainPadded = cipher.doFinal(cipherData);
byte[] plain = PKCS7Encoder.decode(plainPadded);
// 结构16字节随机 + 4字节网络序正文长度 + 正文 + corpId
byte[] networkOrder = Arrays.copyOfRange(plain, 16, 20);
int xmlLength = ByteBuffer.wrap(networkOrder).order(ByteOrder.BIG_ENDIAN).getInt();
byte[] xmlBytes = Arrays.copyOfRange(plain, 20, 20 + xmlLength);
String fromCorpId = new String(Arrays.copyOfRange(plain, 20 + xmlLength, plain.length), StandardCharsets.UTF_8);
if (!fromCorpId.equals(corpId)) {
throw new RuntimeException("corpId mismatch");
}
return new String(xmlBytes, StandardCharsets.UTF_8);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private String encrypt(String plainText) {
try {
byte[] random16 = randomBytes(16);
byte[] xmlBytes = plainText.getBytes(StandardCharsets.UTF_8);
ByteBuffer lenBuf = ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN).putInt(xmlBytes.length);
byte[] corpBytes = corpId.getBytes(StandardCharsets.UTF_8);
byte[] raw = concat(random16, lenBuf.array(), xmlBytes, corpBytes);
byte[] padded = PKCS7Encoder.encode(raw);
Cipher cipher = Cipher.getInstance(AES_ALGORITHM);
SecretKeySpec keySpec = new SecretKeySpec(aesKey, "AES");
cipher.init(Cipher.ENCRYPT_MODE, keySpec, new IvParameterSpec(iv));
byte[] cipherData = cipher.doFinal(padded);
return Base64.getEncoder().encodeToString(cipherData);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static String sha1(String token, String timestamp, String nonce, String encrypt) {
try {
String[] arr = new String[]{token, timestamp, nonce, encrypt};
Arrays.sort(arr, Comparator.naturalOrder());
String joined = String.join("", arr);
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] digest = md.digest(joined.getBytes(StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
for (byte b : digest) {
String hex = Integer.toHexString(b & 0xff);
if (hex.length() < 2) sb.append('0');
sb.append(hex);
}
return sb.toString();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static byte[] randomBytes(int n) {
byte[] b = new byte[n];
// 简易随机即可满足要求
new java.security.SecureRandom().nextBytes(b);
return b;
}
private static byte[] concat(byte[]... parts) {
int len = 0;
for (byte[] p : parts) len += p.length;
byte[] all = new byte[len];
int pos = 0;
for (byte[] p : parts) {
System.arraycopy(p, 0, all, pos, p.length);
pos += p.length;
}
return all;
}
private static class PKCS7Encoder {
private static final int BLOCK_SIZE = 32;
static byte[] encode(byte[] src) {
int amountToPad = BLOCK_SIZE - (src.length % BLOCK_SIZE);
if (amountToPad == 0) amountToPad = BLOCK_SIZE;
byte padChr = (byte) (amountToPad & 0xFF);
byte[] padding = new byte[amountToPad];
Arrays.fill(padding, padChr);
return concat(src, padding);
}
static byte[] decode(byte[] decrypted) {
int pad = decrypted[decrypted.length - 1] & 0xFF;
if (pad < 1 || pad > BLOCK_SIZE) pad = 0;
return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad);
}
}
}

View File

@@ -15,7 +15,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
@@ -35,13 +34,13 @@ public class WxSendUtil {
private static final String GET_TOKEN = QYWX_ORIGIN + "/cgi-bin/gettoken";
private static final String SEND = QYWX_ORIGIN + "/cgi-bin/message/send?access_token=";
private static final String WX_ACCESS_TOKEN = "WX_ACCESS_TOKEN:";
private static RedisCache redisCache = SpringUtil.getBean(RedisCache.class);
private static final RedisCache redisCache = SpringUtil.getBean(RedisCache.class);
//"ww929e7d6493c6336e,DyzVBt7bKbDtGDwr8BADdHeiDPNNhfc2rzUSvvpwqn0,LinPingFan,1000002";
public static String getToken(String corpid, String corpsecret) {
String token = redisCache.getCacheObject(WX_ACCESS_TOKEN+corpsecret);
String token = redisCache.getCacheObject(WX_ACCESS_TOKEN + corpsecret);
if (StrUtil.isNotEmpty(token)) {
return token;
} else {
@@ -57,7 +56,7 @@ public class WxSendUtil {
if (ObjectUtil.isNotEmpty(responseStr)) {
GetTokenResponse response = JSON.parseObject(responseStr, GetTokenResponse.class);
if (response.getErrcode() == 0) {
redisCache.setCacheObject(WX_ACCESS_TOKEN+corpsecret, response.getAccess_token(), 7200, TimeUnit.SECONDS);
redisCache.setCacheObject(WX_ACCESS_TOKEN + corpsecret, response.getAccess_token(), 7200, TimeUnit.SECONDS);
return response.getAccess_token();
}
}
@@ -67,7 +66,7 @@ public class WxSendUtil {
}
}
public static String sendNotify(String title, String text, String touser, WXMessageType wxMessageType) throws Exception {
public static String sendNotifyForMpnews(String title, String text, String touser, WXMessageType wxMessageType) throws Exception {
if (!StrUtil.isAllNotEmpty(title, text)) {
return "title,text不能为空";
}
@@ -76,10 +75,10 @@ public class WxSendUtil {
String[] split = touser.split(",");
touserList.addAll(Arrays.asList(split));
}
return sendNotify(title, text, touserList, wxMessageType);
return sendNotifyForMpnews(title, text, touserList, wxMessageType);
}
public static String sendNotify(String title, String text, List<String> touser, WXMessageType wxMessageType) throws Exception {
public static String sendNotifyForMpnews(String title, String text, List<String> touser, WXMessageType wxMessageType) throws Exception {
if (!StrUtil.isAllNotEmpty(title, text)) {
return "title,text不能为空";
@@ -87,14 +86,16 @@ public class WxSendUtil {
HashMap<String, Object> jsonMap = new HashMap<>();
StringBuilder touserStringBuilder = new StringBuilder();
String touserStr = "@all";
String touserStr = "LinPingFan";
if (ObjectUtil.isNotEmpty(touser)) {
if (touser.size() > 1) {
touser.forEach(t ->
touserStringBuilder.append(t).append("|")
);
touserStr = touserStringBuilder.substring(0, touser.size() - 1);
// 修复bug: 应该使用 touserStringBuilder.length() - 1而不是 touser.size() - 1
// 因为要删除最后一个 "|" 字符,应该基于字符串长度而不是列表大小
touserStr = touserStringBuilder.substring(0, touserStringBuilder.length() - 1);
} else {
touserStr = touserStringBuilder.append(touser.get(0)).toString();
}
@@ -107,13 +108,26 @@ public class WxSendUtil {
ArrayList<Map<String, String>> articlesList = new ArrayList<>();
HashMap<String, String> articles = new HashMap<>();
articles.put("title", title);
articles.put("thumb_media_id", "258F4sbTUwwHLRtKDDr4yqH2PzfYPlHPbOLCazHou_3JCgq7Dh1f9PMvrIaIv2oHk");
articles.put("content",text.replaceAll("\n", System.getProperty("line.separator")));
// 刘亦菲
//articles.put("thumb_media_id", "258F4sbTUwwHLRtKDDr4yqH2PzfYPlHPbOLCazHou_3JCgq7Dh1f9PMvrIaIv2oHk");
// 李星云
articles.put("thumb_media_id", "2ES5cuBiuNKcbFp7RKsjebNM3joCIloIr1QWYwGS86SQzgG_7uxGrJpFlmuHXZl75");
String content = text.replaceAll("\\\\n", "<br/>");
if (content.contains("\n")) {
content = text.replaceAll("\\n", "<br/>");
}
articles.put("content", content);
//articles.put("content",text.replaceAll("\n", System.getProperty("line.separator")));
articlesList.add(articles);
HashMap<Object, Object> mpnews = new HashMap<>();
mpnews.put("articles", articlesList);
jsonMap.put("mpnews", mpnews);
logger.info("发送的消息内容: \n" + JSON.toJSONString(jsonMap));
// 表示是否开启id转译0表示否1表示是默认0
jsonMap.put("enable id trans", 1);
String finalSendStr = JSON.toJSONString(jsonMap);
//finalSendStr = finalSendStr.replaceAll("\\\\n", "<p></p>");
logger.info("发送的消息内容: \n" + finalSendStr);
String token = getToken(wxMessageType.getCorpid(), wxMessageType.getCorpsecret());
//logger.info("获取的token"+token);
@@ -121,7 +135,77 @@ public class WxSendUtil {
throw new Exception();
}
String responseStr = HttpRequest.post(SEND + getToken(wxMessageType.getCorpid(), wxMessageType.getCorpsecret()))
.body(JSON.toJSONString(jsonMap))//头信息,多个头信息多次调用此方法即可
.body(finalSendStr)//头信息,多个头信息多次调用此方法即可
.execute().body();
logger.info("发送消息的响应: \n" + responseStr);
SendRespones sendRespones = JSON.parseObject(responseStr, SendRespones.class);
if (sendRespones.getErrcode().equals(0)) {
return "企业微信应用消息发送通知消息成功\uD83C\uDF89。";
} else {
return sendRespones.getErrmsg();
}
}
public static String sendNotifyForText(String content, String touser, WXMessageType wxMessageType) throws Exception {
ArrayList<String> touserList = new ArrayList<>();
if (StringUtils.isNotEmpty(touser)) {
String[] split = touser.split(",");
touserList.addAll(Arrays.asList(split));
}
return sendNotifyForText(content, touserList, wxMessageType);
}
public static String sendNotifyForText(String content, List<String> touser, WXMessageType wxMessageType) throws Exception {
HashMap<String, Object> jsonMap = new HashMap<>();
StringBuilder touserStringBuilder = new StringBuilder();
String touserStr = "LinPingFan";
if (ObjectUtil.isNotEmpty(touser)) {
if (touser.size() > 1) {
touser.forEach(t ->
touserStringBuilder.append(t).append("|")
);
// 修复bug: 应该使用 touserStringBuilder.length() - 1而不是 touser.size() - 1
// 因为要删除最后一个 "|" 字符,应该基于字符串长度而不是列表大小
touserStr = touserStringBuilder.substring(0, touserStringBuilder.length() - 1);
} else {
touserStr = touserStringBuilder.append(touser.get(0)).toString();
}
}
jsonMap.put("touser", touserStr);
jsonMap.put("agentid", wxMessageType.getAgentid());
jsonMap.put("safe", "0");
jsonMap.put("msgtype", "text");
HashMap<String, String> text = new HashMap<>();
// 刘亦菲
//articles.put("thumb_media_id", "258F4sbTUwwHLRtKDDr4yqH2PzfYPlHPbOLCazHou_3JCgq7Dh1f9PMvrIaIv2oHk");
// 李星云
//articles.put("thumb_media_id", "2ES5cuBiuNKcbFp7RKsjebNM3joCIloIr1QWYwGS86SQzgG_7uxGrJpFlmuHXZl75");
text.put("content", content);
jsonMap.put("text", text);
// 表示是否开启id转译0表示否1表示是默认0
jsonMap.put("enable id trans", 1);
String finalSendStr = JSON.toJSONString(jsonMap);
//finalSendStr = finalSendStr.replaceAll("\\\\n", "<p></p>");
logger.info("发送的消息内容: \n" + finalSendStr);
String token = getToken(wxMessageType.getCorpid(), wxMessageType.getCorpsecret());
//logger.info("获取的token"+token);
if (StrUtil.isEmptyIfStr(token)) {
throw new Exception();
}
String responseStr = HttpRequest.post(SEND + getToken(wxMessageType.getCorpid(), wxMessageType.getCorpsecret()))
.body(finalSendStr)//头信息,多个头信息多次调用此方法即可
.execute().body();
logger.info("发送消息的响应: \n" + responseStr);

View File

@@ -1,59 +0,0 @@
package cn.van333.wxsend.util.ip;
import cn.van333.wxsend.util.str.Constants;
import cn.van333.wxsend.util.str.StringUtils;
import com.alibaba.fastjson2.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author van
* @version 1.0
* msg获取地址类
* @date 2022/3/29 14:45
*/
public class AddressUtils
{
private static final Logger log = LoggerFactory.getLogger(AddressUtils.class);
// IP地址查询
public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp";
// 未知地址
public static final String UNKNOWN = "XX XX";
public static String getRealAddressByIP(String ip)
{
// 内网不查询
if (IpUtils.internalIp(ip))
{
return "内网IP";
}
try
{
String rspStr = HttpUtils.sendGet(IP_URL, "ip=" + ip + "&json=true", Constants.GBK);
if (StringUtils.isEmpty(rspStr))
{
log.error("获取地理位置异常 {}", ip);
return UNKNOWN;
}
JSONObject obj = JSONObject.parseObject(rspStr);
String region = obj.getString("pro");
String city = obj.getString("city");
return String.format("%s %s", region, city);
}
catch (Exception e)
{
log.error("获取地理位置异常 {}", ip);
}
return UNKNOWN;
}
}

View File

@@ -1,269 +0,0 @@
package cn.van333.wxsend.util.ip;
import cn.van333.wxsend.util.str.Constants;
import cn.van333.wxsend.util.str.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.*;
import java.io.*;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.security.cert.X509Certificate;
/**
* @author van
* @version 1.0
* msg通用http发送方法
* @date 2022/3/29 14:48
*/
public class HttpUtils
{
private static final Logger log = LoggerFactory.getLogger(HttpUtils.class);
/**
* 向指定 URL 发送GET方法的请求
*
* @param url 发送请求的 URL
* @return 所代表远程资源的响应结果
*/
public static String sendGet(String url)
{
return sendGet(url, StringUtils.EMPTY);
}
/**
* 向指定 URL 发送GET方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return 所代表远程资源的响应结果
*/
public static String sendGet(String url, String param)
{
return sendGet(url, param, Constants.UTF8);
}
/**
* 向指定 URL 发送GET方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @param contentType 编码类型
* @return 所代表远程资源的响应结果
*/
public static String sendGet(String url, String param, String contentType)
{
StringBuilder result = new StringBuilder();
BufferedReader in = null;
try
{
String urlNameString = StringUtils.isNotBlank(param) ? url + "?" + param : url;
log.info("sendGet - {}", urlNameString);
URL realUrl = new URL(urlNameString);
URLConnection connection = realUrl.openConnection();
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
connection.connect();
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), contentType));
String line;
while ((line = in.readLine()) != null)
{
result.append(line);
}
log.info("recv - {}", result);
}
catch (ConnectException e)
{
log.error("调用HttpUtils.sendGet ConnectException, url=" + url + ",param=" + param, e);
}
catch (SocketTimeoutException e)
{
log.error("调用HttpUtils.sendGet SocketTimeoutException, url=" + url + ",param=" + param, e);
}
catch (IOException e)
{
log.error("调用HttpUtils.sendGet IOException, url=" + url + ",param=" + param, e);
}
catch (Exception e)
{
log.error("调用HttpsUtil.sendGet Exception, url=" + url + ",param=" + param, e);
}
finally
{
try
{
if (in != null)
{
in.close();
}
}
catch (Exception ex)
{
log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
}
}
return result.toString();
}
/**
* 向指定 URL 发送POST方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return 所代表远程资源的响应结果
*/
public static String sendPost(String url, String param)
{
PrintWriter out = null;
BufferedReader in = null;
StringBuilder result = new StringBuilder();
try
{
log.info("sendPost - {}", url);
URL realUrl = new URL(url);
URLConnection conn = realUrl.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("contentType", "utf-8");
conn.setDoOutput(true);
conn.setDoInput(true);
out = new PrintWriter(conn.getOutputStream());
out.print(param);
out.flush();
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
String line;
while ((line = in.readLine()) != null)
{
result.append(line);
}
log.info("recv - {}", result);
}
catch (ConnectException e)
{
log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e);
}
catch (SocketTimeoutException e)
{
log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e);
}
catch (IOException e)
{
log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e);
}
catch (Exception e)
{
log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e);
}
finally
{
try
{
if (out != null)
{
out.close();
}
if (in != null)
{
in.close();
}
}
catch (IOException ex)
{
log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
}
}
return result.toString();
}
public static String sendSSLPost(String url, String param)
{
StringBuilder result = new StringBuilder();
String urlNameString = url + "?" + param;
try
{
log.info("sendSSLPost - {}", urlNameString);
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom());
URL console = new URL(urlNameString);
HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("contentType", "utf-8");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setSSLSocketFactory(sc.getSocketFactory());
conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
conn.connect();
InputStream is = conn.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String ret = "";
while ((ret = br.readLine()) != null)
{
if (ret != null && !"".equals(ret.trim()))
{
result.append(new String(ret.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
}
}
log.info("recv - {}", result);
conn.disconnect();
br.close();
}
catch (ConnectException e)
{
log.error("调用HttpUtils.sendSSLPost ConnectException, url=" + url + ",param=" + param, e);
}
catch (SocketTimeoutException e)
{
log.error("调用HttpUtils.sendSSLPost SocketTimeoutException, url=" + url + ",param=" + param, e);
}
catch (IOException e)
{
log.error("调用HttpUtils.sendSSLPost IOException, url=" + url + ",param=" + param, e);
}
catch (Exception e)
{
log.error("调用HttpsUtil.sendSSLPost Exception, url=" + url + ",param=" + param, e);
}
return result.toString();
}
private static class TrustAnyTrustManager implements X509TrustManager
{
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType)
{
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType)
{
}
@Override
public X509Certificate[] getAcceptedIssuers()
{
return new X509Certificate[] {};
}
}
private static class TrustAnyHostnameVerifier implements HostnameVerifier
{
@Override
public boolean verify(String hostname, SSLSession session)
{
return true;
}
}
}

View File

@@ -0,0 +1,42 @@
package cn.van333.wxsend.util.request;
public class NewsArticle {
private String title;
private String description;
private String url;
private String picurl;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getPicurl() {
return picurl;
}
public void setPicurl(String picurl) {
this.picurl = picurl;
}
}

View File

@@ -0,0 +1,33 @@
package cn.van333.wxsend.util.request;
public class TemplateCardHorizontalContent {
private String keyname;
private String value;
private String url;
public String getKeyname() {
return keyname;
}
public void setKeyname(String keyname) {
this.keyname = keyname;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}

View File

@@ -0,0 +1,33 @@
package cn.van333.wxsend.util.request;
public class TemplateCardJump {
private String type; // 0: URL 跳转
private String url;
private String title;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}

View File

@@ -0,0 +1,251 @@
package cn.van333.wxsend.util.request;
import java.util.List;
public class WebhookMessageRequest {
private String vanToken;
private String key;
private String secret; // 可选加签 secret
private String msgtype; // text 或 markdown
private String content; // 文本/markdown 内容
private List<String> mentionedList;
private List<String> mentionedMobileList;
// image 专用字段(任选其一):
private String imageBase64; // 图片base64不含 data: 前缀)
private String imageMd5; // 图片md532位小写十六进制
private String imageUrl; // 图片直链若提供则后端下载计算base64+md5
// file 专用字段(任选其一):
private String fileUrl; // 文件直链
private String fileBase64; // 文件base64
private String fileName; // 文件名当使用base64时需要
// news 专用字段:
private List<NewsArticle> newsArticles;
// template_card 专用字段(简化版,涵盖常用字段)
private String cardType; // text_notice 或 news_notice
private String cardSourceIconUrl;
private String cardSourceDesc;
private String cardMainTitle;
private String cardMainTitleDesc;
private String cardEmphasisContentTitle;
private String cardEmphasisContentDesc;
private String cardQuoteAreaType;
private String cardQuoteAreaText;
private String cardJumpUrl; // 整卡跳转
private List<TemplateCardHorizontalContent> cardHorizontalContents;
private List<TemplateCardJump> cardJumps;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
public String getMsgtype() {
return msgtype;
}
public void setMsgtype(String msgtype) {
this.msgtype = msgtype;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public List<String> getMentionedList() {
return mentionedList;
}
public void setMentionedList(List<String> mentionedList) {
this.mentionedList = mentionedList;
}
public List<String> getMentionedMobileList() {
return mentionedMobileList;
}
public void setMentionedMobileList(List<String> mentionedMobileList) {
this.mentionedMobileList = mentionedMobileList;
}
public String getVanToken() {
return vanToken;
}
public void setVanToken(String vanToken) {
this.vanToken = vanToken;
}
public String getImageBase64() {
return imageBase64;
}
public void setImageBase64(String imageBase64) {
this.imageBase64 = imageBase64;
}
public String getImageMd5() {
return imageMd5;
}
public void setImageMd5(String imageMd5) {
this.imageMd5 = imageMd5;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public String getFileUrl() {
return fileUrl;
}
public void setFileUrl(String fileUrl) {
this.fileUrl = fileUrl;
}
public String getFileBase64() {
return fileBase64;
}
public void setFileBase64(String fileBase64) {
this.fileBase64 = fileBase64;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public List<NewsArticle> getNewsArticles() {
return newsArticles;
}
public void setNewsArticles(List<NewsArticle> newsArticles) {
this.newsArticles = newsArticles;
}
public String getCardType() {
return cardType;
}
public void setCardType(String cardType) {
this.cardType = cardType;
}
public String getCardSourceIconUrl() {
return cardSourceIconUrl;
}
public void setCardSourceIconUrl(String cardSourceIconUrl) {
this.cardSourceIconUrl = cardSourceIconUrl;
}
public String getCardSourceDesc() {
return cardSourceDesc;
}
public void setCardSourceDesc(String cardSourceDesc) {
this.cardSourceDesc = cardSourceDesc;
}
public String getCardMainTitle() {
return cardMainTitle;
}
public void setCardMainTitle(String cardMainTitle) {
this.cardMainTitle = cardMainTitle;
}
public String getCardMainTitleDesc() {
return cardMainTitleDesc;
}
public void setCardMainTitleDesc(String cardMainTitleDesc) {
this.cardMainTitleDesc = cardMainTitleDesc;
}
public String getCardEmphasisContentTitle() {
return cardEmphasisContentTitle;
}
public void setCardEmphasisContentTitle(String cardEmphasisContentTitle) {
this.cardEmphasisContentTitle = cardEmphasisContentTitle;
}
public String getCardEmphasisContentDesc() {
return cardEmphasisContentDesc;
}
public void setCardEmphasisContentDesc(String cardEmphasisContentDesc) {
this.cardEmphasisContentDesc = cardEmphasisContentDesc;
}
public String getCardQuoteAreaType() {
return cardQuoteAreaType;
}
public void setCardQuoteAreaType(String cardQuoteAreaType) {
this.cardQuoteAreaType = cardQuoteAreaType;
}
public String getCardQuoteAreaText() {
return cardQuoteAreaText;
}
public void setCardQuoteAreaText(String cardQuoteAreaText) {
this.cardQuoteAreaText = cardQuoteAreaText;
}
public String getCardJumpUrl() {
return cardJumpUrl;
}
public void setCardJumpUrl(String cardJumpUrl) {
this.cardJumpUrl = cardJumpUrl;
}
public List<TemplateCardHorizontalContent> getCardHorizontalContents() {
return cardHorizontalContents;
}
public void setCardHorizontalContents(List<TemplateCardHorizontalContent> cardHorizontalContents) {
this.cardHorizontalContents = cardHorizontalContents;
}
public List<TemplateCardJump> getCardJumps() {
return cardJumps;
}
public void setCardJumps(List<TemplateCardJump> cardJumps) {
this.cardJumps = cardJumps;
}
}

View File

@@ -1,7 +1,5 @@
package cn.van333.wxsend.util.str;
import cn.van333.wxsend.util.str.StringUtils;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

View File

@@ -0,0 +1,65 @@
server:
port: 36699
spring:
application:
name: wxSend
#数据源配置
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://134.175.126.60:33306/wxts?characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
username: root
password: mysql_7sjTXH
#redis配置
redis:
host: 134.175.126.60
port: 36379
database: 7
timeout: 1800000
lettuce:
pool:
max-active: 20
#最大阻塞等待时间(负数表示没限制)
max-wait: -1
max-idle: 5
min-idle: 0
password: redis_6PZ52S # 文件上传
servlet:
multipart:
# 单个文件大小
max-file-size: 20MB
# 设置总上传的文件大小
max-request-size: 20MB
#MyWebMvcConfig中开启@EnableWebMvc则失效
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
# # 对象字段为null不显示
# default-property-inclusion: non_null
# 资源信息
messages:
# 国际化资源文件路径
basename: i18n/messages
# token配置
token:
# 令牌自定义标识
header: Authorization
# 令牌密钥
secret: 5c6649a39f184678af3580795a7307d9
# 令牌有效期(单位分钟)
expireTime: 1440
# 用户配置
user:
password:
# 密码最大错误次数
maxRetryCount: 5
# 密码锁定时间默认10分钟
lockTime: 10
# 日志配置
logging:
level:
cn.van333: debug
org.springframework: warn

View File

@@ -0,0 +1,65 @@
server:
port: 36699
spring:
application:
name: wxSend
#数据源配置
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://134.175.126.60:33306/wxts?characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
username: root
password: mysql_7sjTXH
#redis配置
redis:
host: 134.175.126.60
port: 36379
database: 7
timeout: 1800000
lettuce:
pool:
max-active: 20
#最大阻塞等待时间(负数表示没限制)
max-wait: -1
max-idle: 5
min-idle: 0
password: redis_6PZ52S # 文件上传
servlet:
multipart:
# 单个文件大小
max-file-size: 20MB
# 设置总上传的文件大小
max-request-size: 20MB
#MyWebMvcConfig中开启@EnableWebMvc则失效
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
# # 对象字段为null不显示
# default-property-inclusion: non_null
# 资源信息
messages:
# 国际化资源文件路径
basename: i18n/messages
# token配置
token:
# 令牌自定义标识
header: Authorization
# 令牌密钥
secret: 5c6649a39f184678af3580795a7307d9
# 令牌有效期(单位分钟)
expireTime: 1440
# 用户配置
user:
password:
# 密码最大错误次数
maxRetryCount: 5
# 密码锁定时间默认10分钟
lockTime: 10
# 日志配置
logging:
level:
cn.van333: debug
org.springframework: warn

View File

@@ -1,23 +1,21 @@
server:
port: 36699
spring:
application:
name: wxSend
profiles:
active: dev
#数据源配置
# datasource:
# driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://43.136.29.133:33306/imaotai?characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
# username: root
# password: LK.807878712
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://134.175.126.60:33306/wxts?characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
username: root
password: LK.807878712
#redis配置
redis:
host: 43.136.29.133
host:
port: 36379
database: 3
database: 7
timeout: 1800000
lettuce:
pool:
@@ -26,7 +24,7 @@ spring:
max-wait: -1
max-idle: 5
min-idle: 0
password: LK.807878712 # 文件上传
password: redis_6PZ52S # 文件上传
servlet:
multipart:
# 单个文件大小
@@ -67,3 +65,15 @@ logging:
level:
cn.van333: debug
org.springframework: warn
qywx:
webhook:
# 默认 webhook key可在请求体中显式传入key覆盖https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=ea1737ff-f906-426d-b39c-2cdace31c3af
key: "ea1737ff-f906-426d-b39c-2cdace31c3af"
# 机器人安全设置中的加签secret可选。若不开启加签可留空
secret: ""
app:
corpId: "ww4f2e72baba7d07ea"
agentId: "1000002"
token: "7UV4cedJT5gx2kCQXmz7PH5"
encodingAESKey: "nHxBmJYFn9dAjwltyIdLi9YvxmHDGNRsX1MgBIPsog9"

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 日志存放路径 -->
<property name="log.path" value="/www/wwwroot/wx/logs"/>
<property name="log.path" value="/root/project/wxSend/logs"/>
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>

View File

@@ -1,13 +0,0 @@
package cn.van333.wxsend;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class WxSendApplicationTests {
@Test
void contextLoads() {
}
}

0
~/logs/sys-error.log Normal file
View File

12
~/logs/sys-info.log Normal file
View File

@@ -0,0 +1,12 @@
14:56:51.623 [main] INFO c.v.w.WxSendApplication - [logStarting,55] - Starting WxSendApplication using Java 1.8.0_381 on Van with PID 307388 (D:\Code\wxSend\target\classes started by 80787 in D:\Code\wxSend)
14:56:51.625 [main] INFO c.v.w.WxSendApplication - [logStartupProfileInfo,645] - No active profile set, falling back to 1 default profile: "default"
14:56:52.168 [main] INFO o.s.b.w.e.t.TomcatWebServer - [initialize,108] - Tomcat initialized with port(s): 8080 (http)
14:56:52.173 [main] INFO o.a.c.h.Http11NioProtocol - [log,173] - Initializing ProtocolHandler ["http-nio-8080"]
14:56:52.174 [main] INFO o.a.c.c.StandardService - [log,173] - Starting service [Tomcat]
14:56:52.174 [main] INFO o.a.c.c.StandardEngine - [log,173] - Starting Servlet engine: [Apache Tomcat/9.0.68]
14:56:52.272 [main] INFO o.a.c.c.C.[.[.[/] - [log,173] - Initializing Spring embedded WebApplicationContext
14:56:52.272 [main] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - [prepareWebApplicationContext,290] - Root WebApplicationContext: initialization completed in 618 ms
14:56:52.523 [main] INFO o.s.s.w.DefaultSecurityFilterChain - [<init>,55] - Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@74abbb, org.springframework.security.web.context.SecurityContextPersistenceFilter@b10a26d, org.springframework.security.web.header.HeaderWriterFilter@252f626c, org.springframework.security.web.csrf.CsrfFilter@6972c30a, org.springframework.security.web.authentication.logout.LogoutFilter@15ac59c2, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@b965857, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter@6d9fb2d1, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter@64a4dd8d, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@4cb0a000, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@7e4d2287, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@31464a43, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@2dddc1b9, org.springframework.security.web.session.SessionManagementFilter@48284d0e, org.springframework.security.web.access.ExceptionTranslationFilter@7cf283e1, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@4ba380c7]
14:56:52.555 [main] INFO o.a.c.h.Http11NioProtocol - [log,173] - Starting ProtocolHandler ["http-nio-8080"]
14:56:52.564 [main] INFO o.s.b.w.e.t.TomcatWebServer - [start,220] - Tomcat started on port(s): 8080 (http) with context path ''
14:56:52.572 [main] INFO c.v.w.WxSendApplication - [logStarted,61] - Started WxSendApplication in 1.283 seconds (JVM running for 1.809)

0
~/logs/sys-user.log Normal file
View File