Compare commits

...

10 Commits

Author SHA1 Message Date
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
21 changed files with 1951 additions and 634 deletions

37
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>
@@ -77,9 +77,24 @@
<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>
</dependencies>
@@ -124,6 +139,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

@@ -0,0 +1,49 @@
package cn.van333.wxsend.business.controller;
import cn.hutool.core.util.ObjectUtil;
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.SourceForQLUtil;
import cn.van333.wxsend.util.TokenUtil;
import cn.van333.wxsend.util.WxSendUtil;
import cn.van333.wxsend.util.request.MessageRequest;
import com.alibaba.fastjson2.JSON;
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;
import javax.servlet.http.HttpServletRequest;
/**
* @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.sendNotify(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

@@ -15,6 +15,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.rmi.CORBA.Util;
import javax.servlet.http.HttpServletRequest;
/**
@@ -215,5 +216,24 @@ public class WXController {
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,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

@@ -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到手更低";
}
}

File diff suppressed because it is too large Load Diff

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

@@ -16,14 +16,15 @@ public class SourceForQLUtil {
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";
default:
return "未知";
}
}
}

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,7 +34,7 @@ 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";
@@ -107,13 +106,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 +133,7 @@ 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);

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

@@ -8,16 +8,16 @@ spring:
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/flarum_tsayij?characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
username: root
password: LK.807878712
#redis配置
redis:
host: 43.136.29.133
host: 134.175.126.60
port: 36379
database: 3
database: 7
timeout: 1800000
lettuce:
pool:

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

@@ -0,0 +1,24 @@
package cn.van333.wxsend;
import cn.van333.wxsend.business.service.PCService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
/**
* @author Leo
* @version 1.0
* @create 2024/4/29 下午5:06
* @description
*/
@SpringBootTest
public class Test001 {
@Autowired
PCService pcService;
@Test
public void test001() throws InterruptedException {
System.out.println("test001");
pcService.getData();
}
}