Remove .idea folder
parent
7d1eb060d3
commit
95b2c04a9d
|
@ -1,8 +0,0 @@
|
||||||
# 默认忽略的文件
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# 基于编辑器的 HTTP 客户端请求
|
|
||||||
/httpRequests/
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
|
@ -1,35 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<annotationProcessing>
|
|
||||||
<profile default="true" name="Default" enabled="true" />
|
|
||||||
<profile name="Maven default annotation processors profile" enabled="true">
|
|
||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
|
||||||
<outputRelativeToContentRoot value="true" />
|
|
||||||
<module name="xsnb-gateway" />
|
|
||||||
<module name="xsnb-system" />
|
|
||||||
<module name="xsnb-common" />
|
|
||||||
<module name="xsnb-auth" />
|
|
||||||
</profile>
|
|
||||||
</annotationProcessing>
|
|
||||||
<bytecodeTargetLevel target="17">
|
|
||||||
<module name="zhn-auth" target="1.8" />
|
|
||||||
<module name="zhn-dev" target="1.8" />
|
|
||||||
<module name="zhn-gateway" target="1.8" />
|
|
||||||
<module name="zhn-modules" target="1.8" />
|
|
||||||
<module name="zhn-system" target="1.8" />
|
|
||||||
</bytecodeTargetLevel>
|
|
||||||
</component>
|
|
||||||
<component name="JavacSettings">
|
|
||||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
|
||||||
<module name="xsnb-auth" options="-parameters" />
|
|
||||||
<module name="xsnb-common" options="-parameters" />
|
|
||||||
<module name="xsnb-gateway" options="-parameters" />
|
|
||||||
<module name="xsnb-system" options="-parameters" />
|
|
||||||
<module name="zhn-auth" options="-parameters" />
|
|
||||||
<module name="zhn-gateway" options="-parameters" />
|
|
||||||
<module name="zhn-system" options="-parameters" />
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
|
@ -1,13 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Encoding">
|
|
||||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
|
||||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
|
||||||
<file url="file://$PROJECT_DIR$/xsnb-auth/src/main/java" charset="UTF-8" />
|
|
||||||
<file url="file://$PROJECT_DIR$/xsnb-common/src/main/java" charset="UTF-8" />
|
|
||||||
<file url="file://$PROJECT_DIR$/xsnb-gateway/src/main/java" charset="UTF-8" />
|
|
||||||
<file url="file://$PROJECT_DIR$/xsnb-modules/src/main/java" charset="UTF-8" />
|
|
||||||
<file url="file://$PROJECT_DIR$/xsnb-modules/src/main/resources" charset="UTF-8" />
|
|
||||||
<file url="file://$PROJECT_DIR$/xsnb-modules/xsnb-system/src/main/java" charset="UTF-8" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
|
@ -1,25 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RemoteRepositoriesConfiguration">
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Central Repository" />
|
|
||||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Central Repository" />
|
|
||||||
<option name="url" value="http://maven.aliyun.com/nexus/content/repositories/central/" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Maven Central repository" />
|
|
||||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="jboss.community" />
|
|
||||||
<option name="name" value="JBoss Community repository" />
|
|
||||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
|
||||||
</remote-repository>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
|
@ -1,16 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CodeInsightWorkspaceSettings">
|
|
||||||
<option name="optimizeImportsOnTheFly" value="true" />
|
|
||||||
</component>
|
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
||||||
<component name="MavenProjectsManager">
|
|
||||||
<option name="originalFiles">
|
|
||||||
<list>
|
|
||||||
<option value="$PROJECT_DIR$/pom.xml" />
|
|
||||||
<option value="$PROJECT_DIR$/xsnb-modules/zhn-system/pom.xml" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK" />
|
|
||||||
</project>
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package com.ruoyi.web.controller.gzh.domin;
|
||||||
|
|
||||||
|
public enum EventType {}
|
|
@ -0,0 +1,2 @@
|
||||||
|
package com.xsnb.common.domain;public class XmlData {
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
package com.xsnb.common.exception;public class WechatException {
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
package com.xsnb.common.exception;public class WechatQrCodeException {
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
package com.xsnb.common.utils;public class GyTelSmsUtils {
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.xsnb</groupId>
|
||||||
|
<artifactId>xsnb-dev</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>xsnb-invoiceManager</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,2 @@
|
||||||
|
package com.xsnb.invoiceManager;public class InvoiceManagerMain {
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
package com.xsnb.invoiceManager.config;public class NonoReq {
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
package com.xsnb.invoiceManager.controller;public class IMController {
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
package com.xsnb.invoiceManager.domain;public class InvoiceConstants {
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
server:
|
||||||
|
port: 9002
|
||||||
|
|
||||||
|
spring:
|
||||||
|
mail: # 邮件相关配置
|
||||||
|
username: xingsnbadmin@xingsnb.cn # 你自己的QQ邮箱的用户名,需要填写你的QQ邮箱地址
|
||||||
|
password: drjyrrmzqmjcbhdb # 你自己的QQ邮箱的密钥/密码,需要填写你的QQ邮箱登录密码
|
||||||
|
host: smtp.qq.com # SMTP服务器主机名,这里设置为QQ邮箱的SMTP服务器
|
||||||
|
port: 465 # SMTP服务器端口,通常情况下使用SSL的SMTP协议使用465端口
|
||||||
|
protocol: smtp # 使用SMTP协议发送邮件
|
||||||
|
properties: # 邮件相关的属性配置
|
||||||
|
mail: # 邮件协议属性配置
|
||||||
|
smtp: # SMTP协议属性配置
|
||||||
|
ssl: # SSL/TLS属性配置
|
||||||
|
enable: true # 启用SSL,表示使用加密传输邮件
|
||||||
|
auth: true # 启用SMTP身份验证,需要提供用户名和密码
|
||||||
|
starttls: # STARTTLS属性配置,用于在未加密连接上启用TLS
|
||||||
|
enable: true # 启用STARTTLS
|
||||||
|
required: true # 要求必须使用STARTTLS
|
||||||
|
socketFactory: # Socket工厂属性配置,用于SSL连接
|
||||||
|
port: 465 # SSL连接的端口,与SMTP服务器的端口一致
|
||||||
|
class: javax.net.ssl.SSLSocketFactory # 使用的Socket工厂类,通常用于SSL连接
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
allow-circular-references: true
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: GMT+8
|
||||||
|
application:
|
||||||
|
name: xsnb-system
|
||||||
|
profiles:
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
server-addr: 127.0.0.1:8848
|
||||||
|
config:
|
||||||
|
server-addr: 127.0.0.1:8848
|
||||||
|
file-extension: yml
|
||||||
|
shared-configs:
|
||||||
|
- "application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}"
|
||||||
|
rabbitmq:
|
||||||
|
host: 127.0.0.1
|
||||||
|
port: 5672
|
||||||
|
username: guest
|
||||||
|
password: guest
|
||||||
|
virtualHost: /
|
||||||
|
listener:
|
||||||
|
simple:
|
||||||
|
prefetch: 1
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.xsnb.common.config;
|
||||||
|
|
||||||
|
import io.minio.MinioClient;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "minio")
|
||||||
|
public class MinioConfig {
|
||||||
|
|
||||||
|
private String endpoint;
|
||||||
|
private String accessKey;
|
||||||
|
private String secretKey;
|
||||||
|
private String bucketName;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public MinioClient minioClient() {
|
||||||
|
return MinioClient.builder()
|
||||||
|
.endpoint(endpoint)
|
||||||
|
.credentials(accessKey, secretKey)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.xsnb.common.config;
|
||||||
|
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
|
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
||||||
|
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class WeChatCodeConfig {
|
||||||
|
@Value("${wx.appid}")
|
||||||
|
private String appId;
|
||||||
|
@Value("${wx.appsecret}")
|
||||||
|
private String appSecret;
|
||||||
|
/**
|
||||||
|
* 定义WxMpService bean
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public WxMpService wxMpService() {
|
||||||
|
WxMpService wxMpService = new WxMpServiceImpl();
|
||||||
|
WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
|
||||||
|
config.setAppId(appId);
|
||||||
|
config.setSecret(appSecret);
|
||||||
|
wxMpService.setWxMpConfigStorage(config);
|
||||||
|
return wxMpService;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
package com.xsnb.system.controller;public class FileController {
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
package com.xsnb.auth.controller;
|
||||||
|
|
||||||
|
import com.xsnb.common.result.Result;
|
||||||
|
import com.xsnb.auth.GzhUtiles;
|
||||||
|
import com.xsnb.common.utils.HttpUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/weChat")
|
||||||
|
public class WechatController {
|
||||||
|
@Autowired
|
||||||
|
GzhUtiles gzhUtiles;
|
||||||
|
|
||||||
|
|
||||||
|
private HttpUtil httpUtil;
|
||||||
|
@Autowired
|
||||||
|
public WechatController(HttpUtil httpUtil) {
|
||||||
|
this.httpUtil = httpUtil;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/getLoginQrCode")
|
||||||
|
@ResponseBody
|
||||||
|
public Result getLoginQrCode(){
|
||||||
|
|
||||||
|
return Result.success(getQRCode(),"获取成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getQRCode() {
|
||||||
|
try {
|
||||||
|
// 获取公众号 AccessToken
|
||||||
|
String gzhAccessToken = gzhUtiles.getToken();
|
||||||
|
|
||||||
|
// 构建请求URL
|
||||||
|
String createQRCodeUrl = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + gzhAccessToken;
|
||||||
|
|
||||||
|
// 构建二维码数据
|
||||||
|
String jsonData = "{\"expire_seconds\": 600, \"action_name\": \"QR_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"login\"}}}";
|
||||||
|
|
||||||
|
// 发起POST请求获取二维码 ticket
|
||||||
|
Map<String, Object> ticketMap = httpUtil.doPost(createQRCodeUrl, jsonData, 600);
|
||||||
|
String ticket = String.valueOf(ticketMap.get("ticket"));
|
||||||
|
|
||||||
|
if (ticket != null) {
|
||||||
|
|
||||||
|
// 构建二维码显示URL
|
||||||
|
String codeUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + ticket;
|
||||||
|
HashMap<String, String> wxMap = new HashMap<>();
|
||||||
|
wxMap.put("uuid", ticket);
|
||||||
|
wxMap.put("codeUrl", codeUrl);
|
||||||
|
return wxMap;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 发生异常时抛出自定义异常
|
||||||
|
throw new RuntimeException("公众号获取异常");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 默认返回空 Map
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
package com.xsnb.system.domain;public class WxUserLog {
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.xsnb.system.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@ToString
|
||||||
|
@TableName("attachment_list")
|
||||||
|
public class Attachment {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
package com.xsnb.system.mapper;public interface WxUserLogMapper {
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
package com.xsnb.system.service;public interface WechatService {
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
package com.xsnb.system.service.impl;
|
||||||
|
|
||||||
|
import com.xsnb.system.service.WechatService;
|
||||||
|
|
||||||
|
public class WechatServiceImpl implements WechatService {
|
||||||
|
}
|
|
@ -0,0 +1,209 @@
|
||||||
|
package com.xsnb.auth;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xsnb.common.domain.XmlData;
|
||||||
|
import org.apache.commons.lang3.StringEscapeUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBContext;
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class GzhUtiles {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate<String,String> redisTemplate;
|
||||||
|
private final Environment env;
|
||||||
|
|
||||||
|
private static String AppSecret;
|
||||||
|
private static String appid;
|
||||||
|
private static String TOKEN;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public GzhUtiles(Environment env) {
|
||||||
|
this.env = env;
|
||||||
|
|
||||||
|
AppSecret = env.getProperty("wx.AppSecret");
|
||||||
|
appid = env.getProperty("wx.appid");
|
||||||
|
TOKEN = env.getProperty("wx.gzhTooken");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公众号验证token--验证签名
|
||||||
|
*
|
||||||
|
* @param signature
|
||||||
|
* @param timestamp
|
||||||
|
* @param nonce
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean checkQianMing(String signature, String timestamp, String nonce) {
|
||||||
|
|
||||||
|
|
||||||
|
String[] tmpArr = {TOKEN, timestamp, nonce};
|
||||||
|
Arrays.sort(tmpArr);
|
||||||
|
|
||||||
|
StringBuilder tmpStrBuilder = new StringBuilder();
|
||||||
|
for (String str : tmpArr) {
|
||||||
|
tmpStrBuilder.append(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
String tmpStr = tmpStrBuilder.toString();
|
||||||
|
|
||||||
|
try {
|
||||||
|
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
||||||
|
byte[] digest = md.digest(tmpStr.getBytes());
|
||||||
|
|
||||||
|
StringBuilder hexStrBuilder = new StringBuilder();
|
||||||
|
for (byte b : digest) {
|
||||||
|
hexStrBuilder.append(String.format("%02x", b));
|
||||||
|
}
|
||||||
|
|
||||||
|
String calculatedSignature = hexStrBuilder.toString();
|
||||||
|
|
||||||
|
return calculatedSignature.equals(signature);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取微信公众号的AccessToken
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getToken() {
|
||||||
|
|
||||||
|
|
||||||
|
// 判断数据是否存在
|
||||||
|
Boolean gzhAccessToken = redisTemplate.hasKey("gzh_access_token");
|
||||||
|
|
||||||
|
|
||||||
|
//存入缓存 存在两小时
|
||||||
|
//三秒
|
||||||
|
if (!gzhAccessToken) {
|
||||||
|
// 授予形式
|
||||||
|
System.out.println("第一次进入");
|
||||||
|
String grant_type = "client_credential";
|
||||||
|
// 接口地址拼接参数(appid为微信服务号的appid,secret为服务号的秘钥)
|
||||||
|
String getTokenApi = "https://api.weixin.qq.com/cgi-bin/token?grant_type=" + grant_type + "&appid=" + appid
|
||||||
|
+ "&secret=" + AppSecret;
|
||||||
|
String tokenJsonStr = doGetPost(getTokenApi, "GET", null);
|
||||||
|
JSONObject tokenJson = JSONObject.parseObject(tokenJsonStr);
|
||||||
|
String token = tokenJson.get("access_token").toString();
|
||||||
|
// 存入缓存 120分钟 重新获取
|
||||||
|
|
||||||
|
// 存储数据并设置过期时间为 120 分钟
|
||||||
|
redisTemplate.opsForValue().set("gzh_access_token", token, 2, TimeUnit.HOURS);
|
||||||
|
return token;
|
||||||
|
} else {
|
||||||
|
// 获取数据
|
||||||
|
return redisTemplate.opsForValue().get("gzh_access_token");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用接口 post
|
||||||
|
*
|
||||||
|
* @param apiPath
|
||||||
|
*/
|
||||||
|
public static String doGetPost(String apiPath, String type, Map<String, Object> paramMap) {
|
||||||
|
OutputStreamWriter out = null;
|
||||||
|
InputStream is = null;
|
||||||
|
String result = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
URL url = new URL(apiPath);// 创建连接
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
connection.setDoInput(true);
|
||||||
|
connection.setUseCaches(false);
|
||||||
|
connection.setInstanceFollowRedirects(true);
|
||||||
|
connection.setRequestMethod(type); // 设置请求方式
|
||||||
|
connection.setRequestProperty("Accept", "application/json"); // 设置接收数据的格式
|
||||||
|
connection.setRequestProperty("Content-Type", "application/json"); // 设置发送数据的格式
|
||||||
|
connection.connect();
|
||||||
|
if (type.equals("POST")) {
|
||||||
|
out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); // utf-8编码
|
||||||
|
out.append(JSON.toJSONString(paramMap));
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
// 读取响应
|
||||||
|
is = connection.getInputStream();
|
||||||
|
int length = (int) connection.getContentLength();// 获取长度
|
||||||
|
if (length != -1) {
|
||||||
|
byte[] data = new byte[length];
|
||||||
|
byte[] temp = new byte[512];
|
||||||
|
int readLen = 0;
|
||||||
|
int destPos = 0;
|
||||||
|
while ((readLen = is.read(temp)) > 0) {
|
||||||
|
System.arraycopy(temp, 0, data, destPos, readLen);
|
||||||
|
destPos += readLen;
|
||||||
|
}
|
||||||
|
result = new String(data, "UTF-8"); // utf-8编码
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
is.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析公众号用户触发响应的xml
|
||||||
|
*
|
||||||
|
* @param requestBody
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static XmlData jxXml(String requestBody) {
|
||||||
|
|
||||||
|
String unescapedXml = StringEscapeUtils.unescapeHtml4(requestBody);
|
||||||
|
try {
|
||||||
|
// 为XmlData类创建JAXB上下文
|
||||||
|
JAXBContext jaxbContext = JAXBContext.newInstance(XmlData.class);
|
||||||
|
|
||||||
|
// 创建反序列化器
|
||||||
|
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
||||||
|
|
||||||
|
// 从XML反序列化为Java对象
|
||||||
|
XmlData xmlData = (XmlData) unmarshaller.unmarshal(new StringReader(unescapedXml));
|
||||||
|
|
||||||
|
System.out.println(xmlData.toString());
|
||||||
|
|
||||||
|
return xmlData;
|
||||||
|
} catch (JAXBException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,167 @@
|
||||||
|
package com.xsnb.common.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import org.apache.http.HttpEntity;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.config.RequestConfig;
|
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class HttpUtil {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static final Gson gson = new Gson();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get方法
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static Map<String, Object> doGet(String url) {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||||
|
|
||||||
|
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000) //连接超时
|
||||||
|
.setConnectionRequestTimeout(5000)//请求超时
|
||||||
|
.setSocketTimeout(5000)
|
||||||
|
.setRedirectsEnabled(true) //允许自动重定向
|
||||||
|
.build();
|
||||||
|
HttpGet httpGet = new HttpGet(url);
|
||||||
|
httpGet.setConfig(requestConfig);
|
||||||
|
|
||||||
|
try {
|
||||||
|
HttpResponse httpResponse = httpClient.execute(httpGet);
|
||||||
|
if (httpResponse.getStatusLine().getStatusCode() == 200) {
|
||||||
|
|
||||||
|
String jsonResult = EntityUtils.toString(httpResponse.getEntity());
|
||||||
|
map = gson.fromJson(jsonResult, map.getClass());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
httpClient.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 封装post
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Map<String, Object> doPost(String url, String data, int timeout) {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||||
|
//超时设置
|
||||||
|
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout) //连接超时
|
||||||
|
.setConnectionRequestTimeout(timeout)//请求超时
|
||||||
|
.setSocketTimeout(timeout)
|
||||||
|
.setRedirectsEnabled(true) //允许自动重定向
|
||||||
|
.build();
|
||||||
|
HttpPost httpPost = new HttpPost(url);
|
||||||
|
httpPost.setConfig(requestConfig);
|
||||||
|
httpPost.addHeader("Content-Type", "text/html; chartset=UTF-8");
|
||||||
|
|
||||||
|
if (data != null && data instanceof String) { //使用字符串传参
|
||||||
|
StringEntity stringEntity = new StringEntity(data, "UTF-8");
|
||||||
|
httpPost.setEntity(stringEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
CloseableHttpResponse httpResponse = httpClient.execute(httpPost);
|
||||||
|
HttpEntity httpEntity = httpResponse.getEntity();
|
||||||
|
if (httpResponse.getStatusLine().getStatusCode() == 200) {
|
||||||
|
String result = EntityUtils.toString(httpEntity);
|
||||||
|
map = gson.fromJson(result, map.getClass());
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
httpClient.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用接口 post
|
||||||
|
*
|
||||||
|
* @param apiPath
|
||||||
|
*/
|
||||||
|
public static String doGetPost(String apiPath, String type, Map<String, Object> paramMap) {
|
||||||
|
OutputStreamWriter out = null;
|
||||||
|
InputStream is = null;
|
||||||
|
String result = null;
|
||||||
|
try {
|
||||||
|
URL url = new URL(apiPath);// 创建连接
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
connection.setDoInput(true);
|
||||||
|
connection.setUseCaches(false);
|
||||||
|
connection.setInstanceFollowRedirects(true);
|
||||||
|
connection.setRequestMethod(type); // 设置请求方式
|
||||||
|
connection.setRequestProperty("Accept", "application/json"); // 设置接收数据的格式
|
||||||
|
connection.setRequestProperty("Content-Type", "application/json"); // 设置发送数据的格式
|
||||||
|
connection.connect();
|
||||||
|
if (type.equals("POST")) {
|
||||||
|
out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); // utf-8编码
|
||||||
|
out.append(JSON.toJSONString(paramMap));
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
// 读取响应
|
||||||
|
is = connection.getInputStream();
|
||||||
|
int length = (int) connection.getContentLength();// 获取长度
|
||||||
|
if (length != -1) {
|
||||||
|
byte[] data = new byte[length];
|
||||||
|
byte[] temp = new byte[512];
|
||||||
|
int readLen = 0;
|
||||||
|
int destPos = 0;
|
||||||
|
while ((readLen = is.read(temp)) > 0) {
|
||||||
|
System.arraycopy(temp, 0, data, destPos, readLen);
|
||||||
|
destPos += readLen;
|
||||||
|
}
|
||||||
|
result = new String(data, "UTF-8"); // utf-8编码
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
is.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,220 @@
|
||||||
|
package com.xsnb.common.utils.minio;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.common.utils.UuidUtils;
|
||||||
|
import com.xsnb.common.config.MinioConfig;
|
||||||
|
import com.xsnb.common.utils.StringUtils;
|
||||||
|
import io.minio.*;
|
||||||
|
import io.minio.http.Method;
|
||||||
|
import io.minio.messages.Bucket;
|
||||||
|
import io.minio.messages.Item;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.FastByteArrayOutputStream;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.ServletOutputStream;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
@Configuration
|
||||||
|
public class MinioUtil {
|
||||||
|
@Autowired
|
||||||
|
private MinioConfig prop;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MinioClient minioClient;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看存储bucket是否存在
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public Boolean bucketExists(String bucketName) {
|
||||||
|
Boolean found;
|
||||||
|
try {
|
||||||
|
found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建存储bucket
|
||||||
|
* @return Boolean
|
||||||
|
*/
|
||||||
|
public Boolean makeBucket(String bucketName) {
|
||||||
|
try {
|
||||||
|
minioClient.makeBucket(MakeBucketArgs.builder()
|
||||||
|
.bucket(bucketName)
|
||||||
|
.build());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 删除存储bucket
|
||||||
|
* @return Boolean
|
||||||
|
*/
|
||||||
|
public Boolean removeBucket(String bucketName) {
|
||||||
|
try {
|
||||||
|
minioClient.removeBucket(RemoveBucketArgs.builder()
|
||||||
|
.bucket(bucketName)
|
||||||
|
.build());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取全部bucket
|
||||||
|
*/
|
||||||
|
public List<Bucket> getAllBuckets() {
|
||||||
|
try {
|
||||||
|
List<Bucket> buckets = minioClient.listBuckets();
|
||||||
|
return buckets;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件上传
|
||||||
|
*
|
||||||
|
* @param file 文件
|
||||||
|
* @return Boolean
|
||||||
|
*/
|
||||||
|
public String upload(MultipartFile file) {
|
||||||
|
String originalFilename = file.getOriginalFilename();
|
||||||
|
if (StringUtils.isBlank(originalFilename)){
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
|
String fileName = UuidUtils.generateUuid() + originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||||
|
String objectName = getNowDateLongStr("yyyy-MM/dd") + "/" + fileName;
|
||||||
|
try {
|
||||||
|
PutObjectArgs objectArgs = PutObjectArgs.builder().bucket(prop.getBucketName()).object(objectName)
|
||||||
|
.stream(file.getInputStream(), file.getSize(), -1).contentType(file.getContentType()).build();
|
||||||
|
//文件名称相同会覆盖
|
||||||
|
minioClient.putObject(objectArgs);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return objectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 预览图片
|
||||||
|
* @param fileName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String preview(String fileName){
|
||||||
|
// 查看文件地址
|
||||||
|
GetPresignedObjectUrlArgs build = new GetPresignedObjectUrlArgs()
|
||||||
|
.builder()
|
||||||
|
.bucket(prop.getBucketName())
|
||||||
|
.object(fileName)
|
||||||
|
.method(Method.GET).build();
|
||||||
|
try {
|
||||||
|
String url = minioClient.getPresignedObjectUrl(build);
|
||||||
|
return url;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件下载
|
||||||
|
* @param fileName 文件名称
|
||||||
|
* @param res response
|
||||||
|
* @return Boolean
|
||||||
|
*/
|
||||||
|
public void download(String fileName, HttpServletResponse res) {
|
||||||
|
GetObjectArgs objectArgs = GetObjectArgs.builder().bucket(prop.getBucketName())
|
||||||
|
.object(fileName).build();
|
||||||
|
try (GetObjectResponse response = minioClient.getObject(objectArgs)){
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
int len;
|
||||||
|
try (FastByteArrayOutputStream os = new FastByteArrayOutputStream()){
|
||||||
|
while ((len=response.read(buf))!=-1){
|
||||||
|
os.write(buf,0,len);
|
||||||
|
}
|
||||||
|
os.flush();
|
||||||
|
byte[] bytes = os.toByteArray();
|
||||||
|
res.setCharacterEncoding("utf-8");
|
||||||
|
// 设置强制下载不打开
|
||||||
|
// res.setContentType("application/force-download");
|
||||||
|
res.addHeader("Content-Disposition", "attachment;fileName=" + fileName);
|
||||||
|
try (ServletOutputStream stream = res.getOutputStream()){
|
||||||
|
stream.write(bytes);
|
||||||
|
stream.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看文件对象
|
||||||
|
* @return 存储bucket内文件对象信息
|
||||||
|
*/
|
||||||
|
public List<Item> listObjects() {
|
||||||
|
Iterable<Result<Item>> results = minioClient.listObjects(
|
||||||
|
ListObjectsArgs.builder().bucket(prop.getBucketName()).build());
|
||||||
|
List<Item> items = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
for (Result<Item> result : results) {
|
||||||
|
items.add(result.get());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
* @param fileName
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public boolean remove(String fileName){
|
||||||
|
try {
|
||||||
|
minioClient.removeObject( RemoveObjectArgs.builder().bucket(prop.getBucketName()).object(fileName).build());
|
||||||
|
}catch (Exception e){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//获取现在时间
|
||||||
|
public String getNowDateLongStr(String format) {
|
||||||
|
// 获取当前日期
|
||||||
|
LocalDate currentDate = LocalDate.now();
|
||||||
|
// 根据指定格式进行日期格式化
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
||||||
|
String formattedDate = currentDate.format(formatter);
|
||||||
|
return formattedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue