42 changed files with 481 additions and 78 deletions
@ -0,0 +1,142 @@ |
|||
package com.wmeimob.bjyy.util; |
|||
|
|||
import cn.hutool.core.date.DateUtil; |
|||
import cn.hutool.core.io.FileUtil; |
|||
import cn.hutool.core.util.CharsetUtil; |
|||
import cn.hutool.core.util.IdUtil; |
|||
import cn.hutool.core.util.StrUtil; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
|
|||
import javax.servlet.http.HttpServletResponse; |
|||
import javax.servlet.http.Part; |
|||
import java.io.*; |
|||
import java.net.URLEncoder; |
|||
import java.util.Date; |
|||
|
|||
@Slf4j |
|||
public class UploadFileUtil_Servlet3 { |
|||
/** |
|||
* Servlet3.0文件上传 (生成uuid.txt文件) |
|||
* @param part Servlet3.0 API ---> Part |
|||
* @param allowedExts 允许的后缀名 |
|||
* @param dir 目录 |
|||
* @return 文件名 |
|||
* @throws IOException |
|||
*/ |
|||
public static String uploadFile(Part part, String allowedExts, String dir) |
|||
throws IOException{ |
|||
String extraPath = DateUtil.format(new Date(), "yyyyMMdd"); |
|||
|
|||
//1.判断是否为空
|
|||
if (part == null) { |
|||
return null; |
|||
} |
|||
|
|||
//2.生成文件名 [uuid.ext]
|
|||
String original = getFileNameByPart(part); |
|||
String ext = FileUtil.extName(original); |
|||
if (StrUtil.isEmpty(ext) || !allowedExts.contains(ext)){ |
|||
throw new RuntimeException("不支持的格式类型: " + ext); |
|||
} |
|||
String path = extraPath + File.separator + IdUtil.simpleUUID() + "." + ext; |
|||
//3.创建必要的目录
|
|||
File tmpFile = new File(dir); |
|||
if (!tmpFile.exists()) { |
|||
tmpFile.mkdirs(); |
|||
} |
|||
|
|||
//4.写入磁盘
|
|||
String fullPath = dir + File.separator + path; |
|||
//part.write(path); //需要配置临时路径
|
|||
//saveFileFromInputStream(part.getInputStream(),dir,name);
|
|||
FileUtil.writeFromStream(part.getInputStream(),fullPath); |
|||
|
|||
return path; |
|||
} |
|||
|
|||
public static byte[] uploadFile(Part part) |
|||
throws IOException { |
|||
//1.判断是否为空
|
|||
if (part == null) { |
|||
return null; |
|||
} |
|||
|
|||
//2.读取文件
|
|||
InputStream is = part.getInputStream(); |
|||
byte[] bytes = new byte[is.available()]; |
|||
is.read(bytes); |
|||
|
|||
return bytes; |
|||
} |
|||
|
|||
/** |
|||
* 根据请求头解析出文件名 |
|||
* 请求头的格式:火狐和google浏览器下:form-data; name="file"; filename="snmp4j--api.zip" |
|||
* IE浏览器下:form-data; name="file"; filename="E:\snmp4j--api.zip" |
|||
* @param part 包含请求头 |
|||
* @return 文件名 |
|||
*/ |
|||
public static String getFileNameByPart(Part part) { |
|||
String header = part.getHeader("content-disposition"); |
|||
/** |
|||
* String[] tempArr1 = header.split(";");代码执行完之后,在不同的浏览器下,tempArr1数组里面的内容稍有区别 |
|||
* 火狐或者google浏览器下:tempArr1={form-data,name="file",filename="snmp4j--api.zip"} |
|||
* IE浏览器下:tempArr1={form-data,name="file",filename="E:\snmp4j--api.zip"} |
|||
*/ |
|||
String[] tempArr1 = header.split(";"); |
|||
/** |
|||
*火狐或者google浏览器下:tempArr2={filename,"snmp4j--api.zip"} |
|||
*IE浏览器下:tempArr2={filename,"E:\snmp4j--api.zip"} |
|||
*/ |
|||
String[] tempArr2 = tempArr1[2].split("="); |
|||
//获取文件名,兼容各种浏览器的写法
|
|||
String fileName = tempArr2[1].substring(tempArr2[1].lastIndexOf("\\")+1).replaceAll("\"", ""); |
|||
return fileName; |
|||
} |
|||
|
|||
public static void download(HttpServletResponse response, String path, String fileName) throws Exception{ |
|||
File file = new File(path); |
|||
// 如果文件存在,则进行下载
|
|||
if (!file.exists()) { |
|||
log.info("该路径不存在:{}",path); |
|||
return; |
|||
} |
|||
// 配置文件下载
|
|||
response.setHeader("content-type", "application/octet-stream"); |
|||
response.setContentType("application/octet-stream"); |
|||
// 下载文件能正常显示中文
|
|||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, CharsetUtil.UTF_8)); |
|||
// 实现文件下载
|
|||
byte[] buffer = new byte[1024]; |
|||
FileInputStream fis = null; |
|||
BufferedInputStream bis = null; |
|||
try { |
|||
fis = new FileInputStream(file); |
|||
bis = new BufferedInputStream(fis); |
|||
OutputStream os = response.getOutputStream(); |
|||
int i = bis.read(buffer); |
|||
while (i != -1) { |
|||
os.write(buffer, 0, i); |
|||
i = bis.read(buffer); |
|||
} |
|||
|
|||
} finally { |
|||
if (bis != null) { |
|||
try { |
|||
bis.close(); |
|||
} catch (IOException e) { |
|||
log.error("关闭流异常", e); |
|||
} |
|||
} |
|||
if (fis != null) { |
|||
try { |
|||
fis.close(); |
|||
} catch (IOException e) { |
|||
log.error("关闭流异常", e); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
@ -1,5 +1,4 @@ |
|||
jdbc.driver=com.mysql.jdbc.Driver |
|||
jdbc.url=jdbc:mysql://127.0.0.1:3306/yanyuan?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true |
|||
jdbc.url=jdbc:mysql://test.tall.wiki:3306/yanyuan?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true |
|||
jdbc.username=root |
|||
#jdbc.password=po3OynBO[M3579p6L7)o |
|||
jdbc.password= |
|||
jdbc.password=po3OynBO[M3579p6L7)o |
@ -1,5 +1,5 @@ |
|||
redis.host=127.0.0.1 |
|||
redis.port=6379 |
|||
#redis.password=keepAwayFromGithub&CodeSave |
|||
redis.password=areowqr!@43ef |
|||
redis.index=6 |
|||
redis.password= |
|||
redis.index=1 |
@ -1,5 +1,5 @@ |
|||
redis.host=127.0.0.1 |
|||
redis.port=6379 |
|||
#redis.password=keepAwayFromGithub&CodeSave |
|||
redis.password= |
|||
redis.index=4 |
|||
redis.password=areowqr!@43ef |
|||
redis.index=1 |
@ -1,5 +1,4 @@ |
|||
jdbc.driver=com.mysql.jdbc.Driver |
|||
jdbc.url=jdbc:mysql://test.tall.wiki:3306/yanyuan?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true |
|||
jdbc.url=jdbc:mysql://127.0.0.1:3306/yanyuan?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true |
|||
jdbc.username=root |
|||
jdbc.password=po3OynBO[M3579p6L7)o |
|||
#jdbc.password= |
|||
jdbc.password= |
@ -0,0 +1,32 @@ |
|||
package com.wmeimob.bjyy.controller; |
|||
|
|||
import com.wmeimob.bjyy.common.BaseController; |
|||
import com.wmeimob.bjyy.vo.ResultVO; |
|||
import com.wmeimob.wechat.core.JsSdkComponent; |
|||
import com.wmeimob.wechat.model.basic.WxJsSdkConfig; |
|||
import lombok.extern.log4j.Log4j; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
/** |
|||
* @description: |
|||
* @author: whj |
|||
* @time: 2021/2/8 18:31 |
|||
*/ |
|||
@Log4j |
|||
@RestController |
|||
@RequestMapping("/wx") |
|||
public class WxController extends BaseController { |
|||
@RequestMapping("config") |
|||
public ResultVO config(String url){ |
|||
log.info("获取微信配置:" + url); |
|||
JsSdkComponent jsSdkComponent = WECHAT.jssdk(); |
|||
WxJsSdkConfig config = jsSdkComponent.config(url); |
|||
log.info("微信配置:" + config); |
|||
ResultVO vo = new ResultVO(); |
|||
vo.setCode(0); |
|||
vo.setData(config); |
|||
return vo; |
|||
} |
|||
|
|||
} |
@ -0,0 +1 @@ |
|||
@font-face{font-family:"socialshare";src:url("../fonts/iconfont.eot");src:url("../fonts/iconfont.eot?#iefix") format("embedded-opentype"),url("../fonts/iconfont.woff") format("woff"),url("../fonts/iconfont.ttf") format("truetype"),url("../fonts/iconfont.svg#iconfont") format("svg")}.social-share{font-family:"socialshare" !important;font-size:16px;font-style:normal;-webkit-font-smoothing:antialiased;-webkit-text-stroke-width:0.2px;-moz-osx-font-smoothing:grayscale}.social-share *{font-family:"socialshare" !important}.social-share .icon-tencent:before{content:"\f07a"}.social-share .icon-qq:before{content:"\f11a"}.social-share .icon-weibo:before{content:"\f12a"}.social-share .icon-wechat:before{content:"\f09a"}.social-share .icon-douban:before{content:"\f10a"}.social-share .icon-heart:before{content:"\f20a"}.social-share .icon-like:before{content:"\f00a"}.social-share .icon-qzone:before{content:"\f08a"}.social-share .icon-linkedin:before{content:"\f01a"}.social-share .icon-diandian:before{content:"\f05a"}.social-share .icon-facebook:before{content:"\f03a"}.social-share .icon-google:before{content:"\f04a"}.social-share .icon-twitter:before{content:"\f06a"}.social-share a{position:relative;text-decoration:none;margin:4px;display:inline-block;outline:none}.social-share .social-share-icon{position:relative;display:inline-block;width:32px;height:32px;font-size:20px;border-radius:50%;line-height:32px;border:1px solid #666;color:#666;text-align:center;vertical-align:middle;transition:background 0.6s ease-out 0s}.social-share .social-share-icon:hover{background:#666;color:#fff}.social-share .icon-weibo{color:#ff763b;border-color:#ff763b}.social-share .icon-weibo:hover{background:#ff763b}.social-share .icon-tencent{color:#56b6e7;border-color:#56b6e7}.social-share .icon-tencent:hover{background:#56b6e7}.social-share .icon-qq{color:#56b6e7;border-color:#56b6e7}.social-share .icon-qq:hover{background:#56b6e7}.social-share .icon-qzone{color:#FDBE3D;border-color:#FDBE3D}.social-share .icon-qzone:hover{background:#FDBE3D}.social-share .icon-douban{color:#33b045;border-color:#33b045}.social-share .icon-douban:hover{background:#33b045}.social-share .icon-linkedin{color:#0077B5;border-color:#0077B5}.social-share .icon-linkedin:hover{background:#0077B5}.social-share .icon-facebook{color:#44619D;border-color:#44619D}.social-share .icon-facebook:hover{background:#44619D}.social-share .icon-google{color:#db4437;border-color:#db4437}.social-share .icon-google:hover{background:#db4437}.social-share .icon-twitter{color:#55acee;border-color:#55acee}.social-share .icon-twitter:hover{background:#55acee}.social-share .icon-diandian{color:#307DCA;border-color:#307DCA}.social-share .icon-diandian:hover{background:#307DCA}.social-share .icon-wechat{position:relative;color:#7bc549;border-color:#7bc549}.social-share .icon-wechat:hover{background:#7bc549}.social-share .icon-wechat .wechat-qrcode{display:none;border:1px solid #eee;position:absolute;z-index:9;top:-205px;left:-84px;width:200px;height:192px;color:#666;font-size:12px;text-align:center;background-color:#fff;box-shadow:0 2px 10px #aaa;transition:all 200ms;-webkit-tansition:all 350ms;-moz-transition:all 350ms}.social-share .icon-wechat .wechat-qrcode.bottom{top:40px;left:-84px}.social-share .icon-wechat .wechat-qrcode.bottom:after{display:none}.social-share .icon-wechat .wechat-qrcode h4{font-weight:normal;height:26px;line-height:26px;font-size:12px;background-color:#f3f3f3;margin:0;padding:0;color:#777}.social-share .icon-wechat .wechat-qrcode .qrcode{width:105px;margin:10px auto}.social-share .icon-wechat .wechat-qrcode .qrcode table{margin:0 !important}.social-share .icon-wechat .wechat-qrcode .help p{font-weight:normal;line-height:16px;padding:0;margin:0}.social-share .icon-wechat .wechat-qrcode:after{content:'';position:absolute;left:50%;margin-left:-6px;bottom:-13px;width:0;height:0;border-width:8px 6px 6px 6px;border-style:solid;border-color:#fff transparent transparent transparent}.social-share .icon-wechat:hover .wechat-qrcode{display:block} |
Binary file not shown.
After Width: | Height: | Size: 9.8 KiB |
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue