增加调用go-cqhttp接口
This commit is contained in:
parent
b3efb6bf9a
commit
17b203adcc
43
build.gradle
43
build.gradle
@ -20,6 +20,8 @@ dependencies {
|
|||||||
implementation 'com.github.binarywang:wx-java-mp-spring-boot-starter:4.1.0'
|
implementation 'com.github.binarywang:wx-java-mp-spring-boot-starter:4.1.0'
|
||||||
implementation 'io.github.biezhi:oh-my-email:0.0.4'
|
implementation 'io.github.biezhi:oh-my-email:0.0.4'
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.5.4'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.5.4'
|
||||||
|
// json 依赖库
|
||||||
|
implementation 'org.json:json:20210307'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'cn.xuthus83'
|
group = 'cn.xuthus83'
|
||||||
@ -38,3 +40,44 @@ publishing {
|
|||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
options.encoding = 'UTF-8'
|
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')
|
||||||
|
}
|
5
gradle/wrapper/gradle-wrapper.properties
vendored
5
gradle/wrapper/gradle-wrapper.properties
vendored
@ -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
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
37
pom.xml
37
pom.xml
@ -41,6 +41,11 @@
|
|||||||
<artifactId>oh-my-email</artifactId>
|
<artifactId>oh-my-email</artifactId>
|
||||||
<version>0.0.4</version>
|
<version>0.0.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.json</groupId>
|
||||||
|
<artifactId>json</artifactId>
|
||||||
|
<version>20210307</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -60,6 +65,38 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</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>
|
<plugin>
|
||||||
|
@ -4,20 +4,29 @@ import cn.xuthus83.wx_post.service.ApiService;
|
|||||||
import io.github.biezhi.ome.SendMailException;
|
import io.github.biezhi.ome.SendMailException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import me.chanjar.weixin.common.error.WxErrorException;
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
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
|
@RestController
|
||||||
@RequestMapping("/wx")
|
@RequestMapping()
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ApiController {
|
public class ApiController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApiService apiService;
|
private ApiService apiService;
|
||||||
|
|
||||||
@RequestMapping("sms/{title}/{content}")
|
@RequestMapping("/wx/sms/{title}/{content}")
|
||||||
public String wxpostsms(@PathVariable String title, @PathVariable String content) throws WxErrorException, SendMailException {
|
public String wxpostsms(@PathVariable String title, @PathVariable String content) throws WxErrorException, SendMailException {
|
||||||
try {
|
try {
|
||||||
apiService.emailByQQ(title, content);
|
apiService.emailByQQ(title, content);
|
||||||
@ -27,4 +36,119 @@ public class ApiController {
|
|||||||
apiService.wxTemplate(title, content);
|
apiService.wxTemplate(title, content);
|
||||||
return 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user