增加调用go-cqhttp接口

This commit is contained in:
xuthus 2023-11-10 22:57:56 +08:00
parent b3efb6bf9a
commit 17b203adcc
4 changed files with 209 additions and 4 deletions

View File

@ -20,6 +20,8 @@ dependencies {
implementation 'com.github.binarywang:wx-java-mp-spring-boot-starter:4.1.0'
implementation 'io.github.biezhi:oh-my-email:0.0.4'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.5.4'
// json
implementation 'org.json:json:20210307'
}
group = 'cn.xuthus83'
@ -38,3 +40,44 @@ publishing {
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
//Java插件,jar就要用到这里的插件
apply plugin: 'java'
//idea项目
apply plugin: 'idea'
//
group = "com.jiliang"
version = "1.1"
description = "hello, this demo for gradle."
repositories {
mavenCentral()
}
java {
archivesBaseName = "gradle-project"
sourceCompatibility = JavaVersion.VERSION_1_8
}
jar {
String someString = ''
//configurations.runtime拿到所有的运行时的依赖jar包.each遍历他it.name获取到每个的jar包的name
//jar包赋值给变量
configurations.runtimeClasspath.each {someString = someString + " lib\\"+it.name}someString
manifest {
attributes 'Main-Class': 'com.each.dubboMainEnd'
attributes 'Class-Path': someString
}
}
//copyJar jar复制到对应的目录下
task copyJar(type:Copy){
from configurations.runtime
into ('build/libs/lib')
}
//release即是我们打包的时候的执行的函数dependsOn[build,copyJar]relese函数的时候先执行build copyJar
task release(type: Copy,dependsOn: [build,copyJar]) {
// from 'conf'
// into ('build/libs/eachend/conf')
}

View File

@ -1,5 +1,6 @@
#Sat Sep 17 16:58:38 CST 2022
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

37
pom.xml
View File

@ -41,6 +41,11 @@
<artifactId>oh-my-email</artifactId>
<version>0.0.4</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
</dependencies>
<build>
@ -60,6 +65,38 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.9</version>
<executions>
<execution>
<id>tag-latest</id>
<phase>deploy</phase>
<goals>
<goal>build</goal>
<goal>tag</goal>
<goal>push</goal>
</goals>
<configuration>
<tag>latest</tag>
</configuration>
</execution>
<execution>
<id>tag-version</id>
<phase>deploy</phase>
<goals>
<goal>build</goal>
<goal>tag</goal>
<goal>push</goal>
</goals>
<configuration>
<tag>${project.version}</tag>
</configuration>
</execution>
</executions>
</plugin>
<!--在这里修改版本-->
<plugin>

View File

@ -4,20 +4,29 @@ import cn.xuthus83.wx_post.service.ApiService;
import io.github.biezhi.ome.SendMailException;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
@RestController
@RequestMapping("/wx")
@RequestMapping()
@Slf4j
public class ApiController {
@Autowired
private ApiService apiService;
@RequestMapping("sms/{title}/{content}")
@RequestMapping("/wx/sms/{title}/{content}")
public String wxpostsms(@PathVariable String title, @PathVariable String content) throws WxErrorException, SendMailException {
try {
apiService.emailByQQ(title, content);
@ -27,4 +36,119 @@ public class ApiController {
apiService.wxTemplate(title, content);
return title + "/" + content;
}
@RequestMapping("/qq/sms")
public String qqpostsms(@RequestBody(required = false) String content) {
JSONObject jsonObject = new JSONObject(content);
JSONObject data = jsonObject.getJSONObject("data");
JSONObject params = new JSONObject();
if (!data.isNull("item_name")) {
String item_name = data.getString("item_name");
String event = data.getString("event");
params.put("message", item_name + ": " + event);
params.put("user_id", "913651466");
sendPost("http://192.168.123.123:8080/send_msg", params.toString());
}
return "请求成功";
}
/**
* 向指定URL发送GET方法的请求
*
* @param url 发送请求的URL
* @param param 请求参数请求参数应该是 name1=value1&name2=value2 的形式
* @return URL 所代表远程资源的响应结果
*/
public static String sendGet(String url, String param) {
String result = "";
BufferedReader in = null;
try {
String urlNameString = url + "?" + param;
URL realUrl = new URL(urlNameString);
// 打开和URL之间的连接
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();
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送GET请求出现异常" + e);
e.printStackTrace();
}
// 使用finally块来关闭输入流
finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return result;
}
/**
* 向指定 URL 发送POST方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数请求参数应该是 JSONObject.toJSONString(param) 的形式
* @return 所代表远程资源的响应结果
*/
public static String sendPost(String url, String param) {
PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {
URL realUrl = new URL(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("Content-Type", "application/json;charset=UTF-8");
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
out.print(param);
// flush输出流的缓冲
out.flush();
// 定义BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送 POST 请求出现异常!" + e);
e.printStackTrace();
}
//使用finally块来关闭输出流输入流
finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return result;
}
}