Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c843272f03 | ||
|
|
9f6314c9e9 | ||
|
|
27f941768a | ||
|
|
63ae9e7433 | ||
|
|
2d242988e1 | ||
|
|
c976264581 | ||
|
|
b7c068e1ae | ||
|
|
b43a94f006 | ||
|
|
163a0f46df | ||
|
|
4625fbefed | ||
|
|
d7e971f32d | ||
|
|
7ab231a76f | ||
|
|
29422d1c04 | ||
|
|
8b116aec24 | ||
|
|
417de33e3d | ||
|
|
7dd6ec5f22 |
@@ -5,7 +5,7 @@
|
|||||||
<meta charset='UTF-8'>
|
<meta charset='UTF-8'>
|
||||||
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
||||||
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
|
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||||
<title>顺诚百宝箱</title>
|
<title>支付测试- 顺诚百宝箱</title>
|
||||||
<style>
|
<style>
|
||||||
* {
|
* {
|
||||||
margin: 10px auto;
|
margin: 10px auto;
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let response = await fetch('/pay/createOrder?n=' + n + '&t=test');
|
let response = await fetch('/pay/createOrder?n=' + n + '&t=test');
|
||||||
let res = eval("(" + await response.text() + ")");
|
let res = JSON.parse(await response.text());
|
||||||
|
|
||||||
if (res.code == 1) {
|
if (res.code == 1) {
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
alert('获取二维码失败');
|
alert('获取二维码失败');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$('.imgs').html("<img src='data:image/jpg;base64," + img + "'><br><a href='" + code + "'>手机点这里打开支付宝APP</a><br>使用支付宝扫一扫<br><button onclick='selectPay(" + id + ")'>查询支付状态</button> <button onclick='getPayQr()'>刷新二维码</button>");
|
$('.imgs').html("<img src='data:image/jpg;base64," + img + "'><br><a href='alipays://platformapi/startapp?saId=10000007&qrcode=" + code + "'>手机点这里打开支付宝APP</a><br>使用支付宝扫一扫<br><button onclick='selectPay(" + id + ")'>查询支付状态</button> <button onclick='getPayQr()'>刷新二维码</button>");
|
||||||
subscribe(id);
|
subscribe(id);
|
||||||
|
|
||||||
} else alert('遇到错误 ' + res.msg);
|
} else alert('遇到错误 ' + res.msg);
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
await subscribe(id);
|
await subscribe(id);
|
||||||
} else {
|
} else {
|
||||||
// 获取并显示消息
|
// 获取并显示消息
|
||||||
let message = eval("(" + await response.text() + ")");
|
let message = JSON.parse(await response.text());
|
||||||
|
|
||||||
// 再次调用 subscribe() 以获取下一条消息
|
// 再次调用 subscribe() 以获取下一条消息
|
||||||
if (message.msg == "已支付") {
|
if (message.msg == "已支付") {
|
||||||
@@ -94,7 +94,7 @@
|
|||||||
*/
|
*/
|
||||||
async function selectPay(id) {
|
async function selectPay(id) {
|
||||||
let response = await fetch('/pay/queryPay?id=' + id);
|
let response = await fetch('/pay/queryPay?id=' + id);
|
||||||
let res = eval("(" + await response.text() + ")");
|
let res = JSON.parse(await response.text());
|
||||||
|
|
||||||
if (response.status == 200 && res.msg == "已支付") {
|
if (response.status == 200 && res.msg == "已支付") {
|
||||||
return okPay();
|
return okPay();
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
package sc545.pay.interceptor;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.servlet.http.*;
|
|
||||||
|
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
|
||||||
|
|
||||||
import sc545.pay.utils.DBUtil;
|
|
||||||
import sc545.pay.utils.ReadTxt;
|
|
||||||
import sc545.pay.utils.Utils;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class testInterceptor implements HandlerInterceptor{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean preHandle(
|
|
||||||
HttpServletRequest request,
|
|
||||||
HttpServletResponse response,
|
|
||||||
Object handler) throws Exception {
|
|
||||||
|
|
||||||
response.setCharacterEncoding("utf-8");
|
|
||||||
response.setContentType("text/html;charset=utf-8");
|
|
||||||
request.setCharacterEncoding("utf-8");
|
|
||||||
|
|
||||||
/*************************************拉黑高频访问ip******************************************/
|
|
||||||
if(!"".equals(ReadTxt.getSetting(null, "拉黑ip.txt", Utils.getIpAddr(request), ""))){
|
|
||||||
PrintWriter out = response.getWriter();
|
|
||||||
out.print("<meta name='viewport' content='width=device-width, initial-scale=1.0'>系统检测到高频次访问已被拉黑IP<br>若误封请前往微信公众号【顺诚百宝箱】反馈<br>感谢理解!<br>IP:"+Utils.getIpAddr(request));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
String ipdate = ReadTxt.getSetting(null, "访问者IP.txt", Utils.getIpAddr(request), "");//获取此ip上次访问时间和已经访问的次数
|
|
||||||
String[] idt = ipdate.split("_");//分隔
|
|
||||||
long i=0;//已经访问的次数
|
|
||||||
if(!"".equals(ipdate)){
|
|
||||||
if(ipdate.indexOf("_")>0) i=Utils.getNum(idt[1]);
|
|
||||||
//检查此ip第一次访问到现在过了几秒
|
|
||||||
Date ds = Utils.string2Date(idt[0], null);
|
|
||||||
long xc = (new Date().getTime() - ds.getTime())/1000;
|
|
||||||
if(xc<=30){//30秒超过50次
|
|
||||||
if(i>50){//拉黑此ip3天
|
|
||||||
ReadTxt.writeSetting(null,"拉黑ip.txt", Utils.getIpAddr(request), Utils.date2String(new Date(), null));
|
|
||||||
ReadTxt.delSetting(null, "访问者IP.txt", Utils.getIpAddr(request));
|
|
||||||
}else{//正常ip
|
|
||||||
}
|
|
||||||
}else{//正常ip
|
|
||||||
ReadTxt.delSetting(null, "访问者IP.txt", Utils.getIpAddr(request));
|
|
||||||
}
|
|
||||||
ReadTxt.writeSetting(null,"访问者IP.txt", Utils.getIpAddr(request), idt[0]+"_"+(++i));
|
|
||||||
}else
|
|
||||||
ReadTxt.writeSetting(null,"访问者IP.txt", Utils.getIpAddr(request), Utils.date2String(new Date(), "yyyy-MM-dd HH:mm:ss")+"_1");
|
|
||||||
/*******************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DBUtil db = new DBUtil();
|
|
||||||
|
|
||||||
//闭站
|
|
||||||
String cw = ReadTxt.getSetting(null, "setting.ini", "closeweb", "0");
|
|
||||||
if("1".equals(cw)) {
|
|
||||||
String uri = request.getRequestURI();
|
|
||||||
if(uri.indexOf("/admin")<0){
|
|
||||||
Utils.outHtml(response.getWriter(), ReadTxt.getSetting(null, "setting.ini", "closewebtxt", "本站暂停访问"), "/*about:blank*/");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import sc545.pay.utils.DBUtil;
|
import sc545.pay.utils.DBUtil;
|
||||||
import sc545.pay.utils.ImgUtils;
|
import sc545.pay.utils.FileUtils;
|
||||||
import sc545.pay.utils.ReadTxt;
|
import sc545.pay.utils.ReadTxt;
|
||||||
import sc545.pay.utils.Utils;
|
import sc545.pay.utils.Utils;
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ public class core {
|
|||||||
if(i==1){
|
if(i==1){
|
||||||
rs.put("code", "1");
|
rs.put("code", "1");
|
||||||
rs.put("qrcode", response.getQrCode());
|
rs.put("qrcode", response.getQrCode());
|
||||||
rs.put("qrimg", ImgUtils.QrImgB64(response.getQrCode(), 300));
|
rs.put("qrimg", FileUtils.QrImgB64(response.getQrCode(), 300));
|
||||||
rs.put("out_trade_no", response.getOutTradeNo());
|
rs.put("out_trade_no", response.getOutTradeNo());
|
||||||
}else rs.put("errcode", "-1");
|
}else rs.put("errcode", "-1");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -299,7 +299,7 @@ public static String putImg(ServletContext servletContext,MultipartFile file,Str
|
|||||||
//修改:原本存储在项目根路径下的,为了防止删除项目文件丢失
|
//修改:原本存储在项目根路径下的,为了防止删除项目文件丢失
|
||||||
//path = servletContext.getRealPath(lpath);//图片存储在项目根目录下的路径
|
//path = servletContext.getRealPath(lpath);//图片存储在项目根目录下的路径
|
||||||
//现修改为:存储到固定文件夹(子路径保留),读取的时候通过url获取base64格式图片
|
//现修改为:存储到固定文件夹(子路径保留),读取的时候通过url获取base64格式图片
|
||||||
String basePath = ReadTxt.getSetting(null, "setting.ini", "FilePath", "D://webFile");
|
String basePath = ReadTxt.getSetting(null, "setting.ini", "FilePath", "D://scbox_settings/webFile");
|
||||||
if("/".equals(basePath.substring(basePath.length()-1, basePath.length()))) basePath=basePath.substring(0, basePath.length()-1);
|
if("/".equals(basePath.substring(basePath.length()-1, basePath.length()))) basePath=basePath.substring(0, basePath.length()-1);
|
||||||
String np=lpath;
|
String np=lpath;
|
||||||
if(lpath.indexOf(":")>0){
|
if(lpath.indexOf(":")>0){
|
||||||
@@ -359,7 +359,7 @@ public static String putImg(ServletContext servletContext,MultipartFile file,Str
|
|||||||
saveSql(realurl, towhere,fileName);
|
saveSql(realurl, towhere,fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(servletContext != null) return "/getFile/"+rid;
|
if(servletContext != null) return "/getImg/"+rid;
|
||||||
else return realurl;
|
else return realurl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,7 +389,7 @@ public static String putImgAsName(ServletContext servletContext,MultipartFile fi
|
|||||||
//修改:原本存储在项目根路径下的,为了防止删除项目文件丢失
|
//修改:原本存储在项目根路径下的,为了防止删除项目文件丢失
|
||||||
//path = servletContext.getRealPath(lpath);//图片存储在项目根目录下的路径
|
//path = servletContext.getRealPath(lpath);//图片存储在项目根目录下的路径
|
||||||
//现修改为:存储到固定文件夹(子路径保留),读取的时候通过url获取base64格式图片
|
//现修改为:存储到固定文件夹(子路径保留),读取的时候通过url获取base64格式图片
|
||||||
String basePath = ReadTxt.getSetting(null, "setting.ini", "FilePath", "D://webFile");
|
String basePath = ReadTxt.getSetting(null, "setting.ini", "FilePath", "D://scbox_settings/webFile");
|
||||||
if("/".equals(basePath.substring(basePath.length()-1, basePath.length()))) basePath=basePath.substring(0, basePath.length()-1);
|
if("/".equals(basePath.substring(basePath.length()-1, basePath.length()))) basePath=basePath.substring(0, basePath.length()-1);
|
||||||
String np=lpath;
|
String np=lpath;
|
||||||
if(lpath.indexOf(":")>0){
|
if(lpath.indexOf(":")>0){
|
||||||
@@ -452,7 +452,7 @@ public static String putImgAsName(ServletContext servletContext,MultipartFile fi
|
|||||||
saveSql(realurl, towhere,fileName);
|
saveSql(realurl, towhere,fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(servletContext != null) return "/getFile/"+rid;
|
if(servletContext != null) return "/getImg/"+rid;
|
||||||
else return realurl;
|
else return realurl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,7 +487,7 @@ public static String putVideo(ServletContext servletContext,MultipartFile file,S
|
|||||||
//修改:原本存储在项目根路径下的,为了防止删除项目文件丢失
|
//修改:原本存储在项目根路径下的,为了防止删除项目文件丢失
|
||||||
//path = servletContext.getRealPath(lpath);//图片存储在项目根目录下的路径
|
//path = servletContext.getRealPath(lpath);//图片存储在项目根目录下的路径
|
||||||
//现修改为:存储到固定文件夹(子路径保留),读取的时候通过url获取base64格式图片
|
//现修改为:存储到固定文件夹(子路径保留),读取的时候通过url获取base64格式图片
|
||||||
String basePath = ReadTxt.getSetting(null, "setting.ini", "FilePath", "D://webFile");
|
String basePath = ReadTxt.getSetting(null, "setting.ini", "FilePath", "D://scbox_settings/webFile");
|
||||||
if("/".equals(basePath.substring(basePath.length()-1, basePath.length()))) basePath=basePath.substring(0, basePath.length()-1);
|
if("/".equals(basePath.substring(basePath.length()-1, basePath.length()))) basePath=basePath.substring(0, basePath.length()-1);
|
||||||
String np=lpath;
|
String np=lpath;
|
||||||
if(lpath.indexOf(":")>0){
|
if(lpath.indexOf(":")>0){
|
||||||
@@ -548,7 +548,7 @@ public static String putVideo(ServletContext servletContext,MultipartFile file,S
|
|||||||
saveSql(realurl, towhere,fileName);
|
saveSql(realurl, towhere,fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(servletContext != null) return "/getFile/"+rid;
|
if(servletContext != null) return "/getImg/"+rid;
|
||||||
else return realurl;
|
else return realurl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -585,7 +585,7 @@ public static String putFile(ServletContext servletContext,MultipartFile file,St
|
|||||||
//修改:原本存储在项目根路径下的,为了防止删除项目文件丢失
|
//修改:原本存储在项目根路径下的,为了防止删除项目文件丢失
|
||||||
//path = servletContext.getRealPath(lpath);//图片存储在项目根目录下的路径
|
//path = servletContext.getRealPath(lpath);//图片存储在项目根目录下的路径
|
||||||
//现修改为:存储到固定文件夹(子路径保留),读取的时候通过url获取base64格式图片
|
//现修改为:存储到固定文件夹(子路径保留),读取的时候通过url获取base64格式图片
|
||||||
String basePath = ReadTxt.getSetting(null, "setting.ini", "FilePath", "D://webFile");
|
String basePath = ReadTxt.getSetting(null, "setting.ini", "FilePath", "D://scbox_settings/webFile");
|
||||||
if("/".equals(basePath.substring(basePath.length()-1, basePath.length()))) basePath=basePath.substring(0, basePath.length()-1);
|
if("/".equals(basePath.substring(basePath.length()-1, basePath.length()))) basePath=basePath.substring(0, basePath.length()-1);
|
||||||
String np=lpath;
|
String np=lpath;
|
||||||
if(lpath.indexOf(":")>0){
|
if(lpath.indexOf(":")>0){
|
||||||
@@ -669,8 +669,8 @@ public static void saveSql(String realurl, String towhere, String saveName) {
|
|||||||
String msid = towhere.split("#")[1];
|
String msid = towhere.split("#")[1];
|
||||||
String mstag = towhere.split("#")[2];
|
String mstag = towhere.split("#")[2];
|
||||||
|
|
||||||
if(realurl.indexOf("/getFile/")==0) {
|
if(realurl.indexOf("/getImg/")==0) {
|
||||||
realurl=realurl.replace("/getFile/", "");
|
realurl=realurl.replace("/getImg/", "");
|
||||||
if(db.execSql("select * from savefile where id = '"+realurl+"'", null)>0){//已存在
|
if(db.execSql("select * from savefile where id = '"+realurl+"'", null)>0){//已存在
|
||||||
db.execUpdate("update savefile set mstab=?,msid=?,mstag=?,savename=? where id=?", new String[]{mstab.trim(),msid.trim(),mstag.trim(),realurl.trim(),saveName==null?"":saveName.trim()});
|
db.execUpdate("update savefile set mstab=?,msid=?,mstag=?,savename=? where id=?", new String[]{mstab.trim(),msid.trim(),mstag.trim(),realurl.trim(),saveName==null?"":saveName.trim()});
|
||||||
}else{//不存在
|
}else{//不存在
|
||||||
@@ -712,7 +712,7 @@ public static String writeFile(ServletContext servletContext, String path,
|
|||||||
oldfile=oldfile.substring(i+1, oldfile.length());
|
oldfile=oldfile.substring(i+1, oldfile.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
String path1 = "";
|
String path1 = path;
|
||||||
if(path.indexOf("./")==0)
|
if(path.indexOf("./")==0)
|
||||||
path =path.substring(1, path.length());
|
path =path.substring(1, path.length());
|
||||||
|
|
||||||
@@ -724,7 +724,7 @@ public static String writeFile(ServletContext servletContext, String path,
|
|||||||
//修改:原本存储在项目根路径下的,为了防止删除项目文件丢失
|
//修改:原本存储在项目根路径下的,为了防止删除项目文件丢失
|
||||||
//path = servletContext.getRealPath(lpath);//图片存储在项目根目录下的路径
|
//path = servletContext.getRealPath(lpath);//图片存储在项目根目录下的路径
|
||||||
//现修改为:存储到固定文件夹(子路径保留),读取的时候通过url获取base64格式图片
|
//现修改为:存储到固定文件夹(子路径保留),读取的时候通过url获取base64格式图片
|
||||||
String basePath = ReadTxt.getSetting(null, "setting.ini", "FilePath", "D://webFile");
|
String basePath = ReadTxt.getSetting(null, "setting.ini", "FilePath", "D://scbox_settings/webFile");
|
||||||
if("/".equals(basePath.substring(basePath.length()-1, basePath.length()))) basePath=basePath.substring(0, basePath.length()-1);
|
if("/".equals(basePath.substring(basePath.length()-1, basePath.length()))) basePath=basePath.substring(0, basePath.length()-1);
|
||||||
String np=path;
|
String np=path;
|
||||||
if(path.indexOf(":")>0){
|
if(path.indexOf(":")>0){
|
||||||
@@ -775,13 +775,13 @@ public static void delfile(ServletContext servletContext, String path) {
|
|||||||
if(path.indexOf("./")==0)
|
if(path.indexOf("./")==0)
|
||||||
path =path.substring(1, path.length());
|
path =path.substring(1, path.length());
|
||||||
|
|
||||||
String path1 = "";
|
String path1 = path;
|
||||||
if (servletContext == null) {
|
if (servletContext == null) {
|
||||||
if(path.indexOf(":") <= 0)
|
if(path.indexOf(":") <= 0)
|
||||||
path1 = "D:\\" + path;
|
path1 = "D:\\" + path;
|
||||||
} else {
|
} else {
|
||||||
if(path.indexOf("/getFile/")==0){
|
if(path.indexOf("/getImg/")==0){
|
||||||
String rid = path.replace("/getFile/", "");
|
String rid = path.replace("/getImg/", "");
|
||||||
DBUtil db = new DBUtil();
|
DBUtil db = new DBUtil();
|
||||||
List<Map<String, Object>> rs = db.execQuery("select * from savefile where id ="+rid, null);
|
List<Map<String, Object>> rs = db.execQuery("select * from savefile where id ="+rid, null);
|
||||||
if(rs!=null&&rs.size()>0){
|
if(rs!=null&&rs.size()>0){
|
||||||
@@ -804,7 +804,7 @@ public static void delfile(ServletContext servletContext, String path) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除字符串中提取的文件
|
* 删除字符串中提取的图片文件
|
||||||
*
|
*
|
||||||
* @param path
|
* @param path
|
||||||
* 项目根目录下的文件路径(servletContext若null为c盘下的)
|
* 项目根目录下的文件路径(servletContext若null为c盘下的)
|
||||||
@@ -823,13 +823,13 @@ public static void delFileForStr(ServletContext servletContext, String str) {
|
|||||||
|
|
||||||
path=path.replace(ReadTxt.getSetting(null, "setting.ini", "resweb", ""),"");
|
path=path.replace(ReadTxt.getSetting(null, "setting.ini", "resweb", ""),"");
|
||||||
|
|
||||||
String path1 = "";
|
String path1 = path;
|
||||||
if (servletContext == null) {
|
if (servletContext == null) {
|
||||||
if(path.indexOf(":") <= 0)
|
if(path.indexOf(":") <= 0)
|
||||||
path1 = "D:\\" + path;
|
path1 = "D:\\" + path;
|
||||||
} else {
|
} else {
|
||||||
if(path.indexOf("/getFile/")==0){
|
if(path.indexOf("/getImg/")==0){
|
||||||
String rid = path.replace("/getFile/", "");
|
String rid = path.replace("/getImg/", "");
|
||||||
List<Map<String, Object>> rs = db.execQuery("select * from savefile where id ="+rid, null);
|
List<Map<String, Object>> rs = db.execQuery("select * from savefile where id ="+rid, null);
|
||||||
if(rs!=null&&rs.size()>0){
|
if(rs!=null&&rs.size()>0){
|
||||||
oldpath=rs.get(0).get("realurl")+"";
|
oldpath=rs.get(0).get("realurl")+"";
|
||||||
@@ -851,6 +851,12 @@ public static void delFileForStr(ServletContext servletContext, String str) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提取字符串中的图片地址存入数据库
|
||||||
|
* @param str
|
||||||
|
* @param towhere
|
||||||
|
* @param saveName
|
||||||
|
*/
|
||||||
public static void intoSqlForStr(String str,String towhere,String saveName) {
|
public static void intoSqlForStr(String str,String towhere,String saveName) {
|
||||||
ArrayList<String> imgs = Utils.getImgStr(str, true);
|
ArrayList<String> imgs = Utils.getImgStr(str, true);
|
||||||
DBUtil db = new DBUtil();
|
DBUtil db = new DBUtil();
|
||||||
@@ -861,8 +867,8 @@ public static void intoSqlForStr(String str,String towhere,String saveName) {
|
|||||||
mstag = towhere.split("#")[2];
|
mstag = towhere.split("#")[2];
|
||||||
|
|
||||||
for (String path : imgs) {
|
for (String path : imgs) {
|
||||||
if(path.indexOf("/getFile/")==0){
|
if(path.indexOf("/getImg/")==0){
|
||||||
String rid = path.replace("/getFile/", "");
|
String rid = path.replace("/getImg/", "");
|
||||||
List<Map<String, Object>> rs = db.execQuery("select * from savefile where id ="+rid, null);
|
List<Map<String, Object>> rs = db.execQuery("select * from savefile where id ="+rid, null);
|
||||||
if(rs!=null&&rs.size()>0){
|
if(rs!=null&&rs.size()>0){
|
||||||
path=rs.get(0).get("realurl")+"";
|
path=rs.get(0).get("realurl")+"";
|
||||||
@@ -975,7 +981,7 @@ public static ResponseEntity<FileSystemResource> returnFile(File file) {
|
|||||||
* @param localUrl 二维码地址
|
* @param localUrl 二维码地址
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String imgPS(String title,String des,String teacher,String teacherImgUrl,String localUrl) {
|
public static String imgPS(String title,String des,String teacher,String teacherImgUrl,String localUrl) {
|
||||||
String r=null;
|
String r=null;
|
||||||
try {
|
try {
|
||||||
String bjUrl = "file:///C://webimg/bj.jpg";
|
String bjUrl = "file:///C://webimg/bj.jpg";
|
||||||
|
|||||||
@@ -2,10 +2,8 @@ package sc545.pay.utils;
|
|||||||
|
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
|||||||
@@ -1,15 +1,7 @@
|
|||||||
package sc545.pay.utils;
|
package sc545.pay.utils;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
@@ -29,12 +21,8 @@ import javax.net.ssl.TrustManager;
|
|||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.Header;
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpResponse;
|
|
||||||
import org.apache.http.NameValuePair;
|
import org.apache.http.NameValuePair;
|
||||||
import org.apache.http.ParseException;
|
|
||||||
import org.apache.http.client.ClientProtocolException;
|
|
||||||
import org.apache.http.client.CookieStore;
|
import org.apache.http.client.CookieStore;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.config.RequestConfig;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
@@ -60,14 +48,7 @@ import org.apache.http.util.EntityUtils;
|
|||||||
*/
|
*/
|
||||||
public class HttpUtils {
|
public class HttpUtils {
|
||||||
|
|
||||||
private static final CloseableHttpClient httpClient;
|
|
||||||
public static final String CHARSET = "UTF-8";
|
public static final String CHARSET = "UTF-8";
|
||||||
// 采用静态代码块,初始化超时时间配置,再根据配置生成默认httpClient对象
|
|
||||||
static {
|
|
||||||
//10秒相应超时
|
|
||||||
RequestConfig config = RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).setConnectionRequestTimeout(5000).build();
|
|
||||||
httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String doGet(String url, Map<String, String> params) {
|
public static String doGet(String url, Map<String, String> params) {
|
||||||
return doGet(url, params, CHARSET);
|
return doGet(url, params, CHARSET);
|
||||||
@@ -93,7 +74,10 @@ public class HttpUtils {
|
|||||||
if (StringUtils.isBlank(url)) {
|
if (StringUtils.isBlank(url)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
CloseableHttpResponse response = null;
|
||||||
|
HttpGet httpGet = null;
|
||||||
|
RequestConfig config = RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).setConnectionRequestTimeout(5000).build();
|
||||||
|
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
|
||||||
try {
|
try {
|
||||||
if (params != null && !params.isEmpty()) {
|
if (params != null && !params.isEmpty()) {
|
||||||
List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
|
List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
|
||||||
@@ -106,8 +90,8 @@ public class HttpUtils {
|
|||||||
// 将请求参数和url进行拼接
|
// 将请求参数和url进行拼接
|
||||||
url += "?" + EntityUtils.toString(new UrlEncodedFormEntity(pairs, charset));
|
url += "?" + EntityUtils.toString(new UrlEncodedFormEntity(pairs, charset));
|
||||||
}
|
}
|
||||||
HttpGet httpGet = new HttpGet(url);
|
httpGet = new HttpGet(url);
|
||||||
CloseableHttpResponse response = httpClient.execute(httpGet);
|
response = httpClient.execute(httpGet);
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
if (statusCode != 200) {
|
if (statusCode != 200) {
|
||||||
httpGet.abort();
|
httpGet.abort();
|
||||||
@@ -125,7 +109,20 @@ public class HttpUtils {
|
|||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("url错误:::"+e.toString());
|
System.out.println("url错误:::"+e.toString());
|
||||||
|
try {
|
||||||
|
response.close();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
}finally{
|
||||||
|
try {
|
||||||
|
response.close();
|
||||||
|
httpClient.close();
|
||||||
|
httpGet.reset();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -157,6 +154,8 @@ public class HttpUtils {
|
|||||||
}
|
}
|
||||||
HttpPost httpPost = new HttpPost(url);
|
HttpPost httpPost = new HttpPost(url);
|
||||||
CloseableHttpResponse response = null;
|
CloseableHttpResponse response = null;
|
||||||
|
RequestConfig config = RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).setConnectionRequestTimeout(5000).build();
|
||||||
|
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
|
||||||
try {
|
try {
|
||||||
if (pairs != null && pairs.size() > 0) {
|
if (pairs != null && pairs.size() > 0) {
|
||||||
httpPost.setEntity(new UrlEncodedFormEntity(pairs, CHARSET));
|
httpPost.setEntity(new UrlEncodedFormEntity(pairs, CHARSET));
|
||||||
@@ -176,14 +175,19 @@ public class HttpUtils {
|
|||||||
EntityUtils.consume(entity);
|
EntityUtils.consume(entity);
|
||||||
if(!"UTF-8".equals(getEncoding(result))) result=GBKtoUTF8(result);
|
if(!"UTF-8".equals(getEncoding(result))) result=GBKtoUTF8(result);
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
}catch (Exception e) {
|
||||||
return "";
|
System.out.println("url错误:::"+e.toString());
|
||||||
} finally {
|
e.printStackTrace();
|
||||||
if (response != null)
|
}finally{
|
||||||
try {
|
try {
|
||||||
response.close();
|
response.close();
|
||||||
} catch (IOException e) {}
|
httpClient.close();
|
||||||
|
httpPost.reset();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -198,7 +202,9 @@ public class HttpUtils {
|
|||||||
if (StringUtils.isBlank(url)) {
|
if (StringUtils.isBlank(url)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
CloseableHttpResponse response = null;
|
||||||
|
HttpGet httpGet = null;
|
||||||
|
CloseableHttpClient httpsClient = null;
|
||||||
try {
|
try {
|
||||||
if (params != null && !params.isEmpty()) {
|
if (params != null && !params.isEmpty()) {
|
||||||
List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
|
List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
|
||||||
@@ -210,11 +216,11 @@ public class HttpUtils {
|
|||||||
}
|
}
|
||||||
url += "?" + EntityUtils.toString(new UrlEncodedFormEntity(pairs, charset));
|
url += "?" + EntityUtils.toString(new UrlEncodedFormEntity(pairs, charset));
|
||||||
}
|
}
|
||||||
HttpGet httpGet = new HttpGet(url);
|
httpGet = new HttpGet(url);
|
||||||
|
|
||||||
// https 注意这里获取https内容,使用了忽略证书的方式,当然还有其他的方式来获取https内容
|
// https 注意这里获取https内容,使用了忽略证书的方式,当然还有其他的方式来获取https内容
|
||||||
CloseableHttpClient httpsClient = HttpUtils.createSSLClientDefault();
|
httpsClient = HttpUtils.createSSLClientDefault();
|
||||||
CloseableHttpResponse response = httpsClient.execute(httpGet);
|
response = httpsClient.execute(httpGet);
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
if (statusCode != 200) {
|
if (statusCode != 200) {
|
||||||
httpGet.abort();
|
httpGet.abort();
|
||||||
@@ -229,8 +235,17 @@ public class HttpUtils {
|
|||||||
response.close();
|
response.close();
|
||||||
if(!"UTF-8".equals(getEncoding(result))) result=GBKtoUTF8(result);
|
if(!"UTF-8".equals(getEncoding(result))) result=GBKtoUTF8(result);
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
}catch (Exception e) {
|
||||||
|
System.out.println("url错误:::"+e.toString());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
}finally{
|
||||||
|
try {
|
||||||
|
response.close();
|
||||||
|
httpsClient.close();
|
||||||
|
httpGet.reset();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -298,6 +313,7 @@ public class HttpUtils {
|
|||||||
CloseableHttpClient client = httpClientBuilder.build();
|
CloseableHttpClient client = httpClientBuilder.build();
|
||||||
client = (CloseableHttpClient) wrapClient(client);
|
client = (CloseableHttpClient) wrapClient(client);
|
||||||
HttpPost post = new HttpPost(url);
|
HttpPost post = new HttpPost(url);
|
||||||
|
CloseableHttpResponse res = null;
|
||||||
try {
|
try {
|
||||||
StringEntity s = new StringEntity(json, "utf-8");
|
StringEntity s = new StringEntity(json, "utf-8");
|
||||||
if (StringUtils.isBlank(contentType)) {
|
if (StringUtils.isBlank(contentType)) {
|
||||||
@@ -305,19 +321,29 @@ public class HttpUtils {
|
|||||||
}
|
}
|
||||||
s.setContentType(contentType);
|
s.setContentType(contentType);
|
||||||
post.setEntity(s);
|
post.setEntity(s);
|
||||||
HttpResponse res = client.execute(post);
|
res = client.execute(post);
|
||||||
HttpEntity entity = res.getEntity();
|
HttpEntity entity = res.getEntity();
|
||||||
String str = EntityUtils.toString(entity, charset);
|
String str = EntityUtils.toString(entity, charset);
|
||||||
if(!"UTF-8".equals(getEncoding(str))) str=GBKtoUTF8(str);
|
if(!"UTF-8".equals(getEncoding(str))) str=GBKtoUTF8(str);
|
||||||
return str;
|
return str;
|
||||||
} catch (Exception e) {
|
}catch (Exception e) {
|
||||||
e.printStackTrace();
|
System.out.println("url错误:::"+e.toString());
|
||||||
}
|
e.printStackTrace();
|
||||||
|
}finally{
|
||||||
|
try {
|
||||||
|
res.close();
|
||||||
|
client.close();
|
||||||
|
post.reset();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static org.apache.http.client.HttpClient wrapClient(HttpClient base) {
|
@SuppressWarnings("deprecation")
|
||||||
|
private static org.apache.http.client.HttpClient wrapClient(HttpClient base) {
|
||||||
try {
|
try {
|
||||||
SSLContext ctx = SSLContext.getInstance("TLSv1");
|
SSLContext ctx = SSLContext.getInstance("TLSv1");
|
||||||
X509TrustManager tm = new X509TrustManager() {
|
X509TrustManager tm = new X509TrustManager() {
|
||||||
@@ -368,6 +394,8 @@ public class HttpUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
HttpGet httpGet = new HttpGet(url);
|
HttpGet httpGet = new HttpGet(url);
|
||||||
|
RequestConfig config = RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).setConnectionRequestTimeout(5000).build();
|
||||||
|
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
|
||||||
try {
|
try {
|
||||||
CloseableHttpResponse response = httpClient.execute(httpGet);
|
CloseableHttpResponse response = httpClient.execute(httpGet);
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
@@ -491,6 +519,7 @@ public class HttpUtils {
|
|||||||
* @param header
|
* @param header
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public static String doPost2(String url, Map<String, String> params, CookieStore cookie,Map<String, String> header,String charset) {
|
public static String doPost2(String url, Map<String, String> params, CookieStore cookie,Map<String, String> header,String charset) {
|
||||||
if(charset==null||charset.trim().length()<1) charset="UTF-8";
|
if(charset==null||charset.trim().length()<1) charset="UTF-8";
|
||||||
if (StringUtils.isBlank(url)) {
|
if (StringUtils.isBlank(url)) {
|
||||||
@@ -517,12 +546,13 @@ public class HttpUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CloseableHttpResponse response = null;
|
CloseableHttpResponse response = null;
|
||||||
|
CloseableHttpClient httpClientc = null;
|
||||||
try {
|
try {
|
||||||
if (pairs != null && pairs.size() > 0) {
|
if (pairs != null && pairs.size() > 0) {
|
||||||
httpPost.setEntity(new UrlEncodedFormEntity(pairs, CHARSET));
|
httpPost.setEntity(new UrlEncodedFormEntity(pairs, CHARSET));
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseableHttpClient httpClientc = HttpUtils.createSSLClientCookie(cookie);
|
httpClientc = HttpUtils.createSSLClientCookie(cookie);
|
||||||
response = httpClientc.execute(httpPost);
|
response = httpClientc.execute(httpPost);
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
if (statusCode != 200) {
|
if (statusCode != 200) {
|
||||||
@@ -538,22 +568,38 @@ public class HttpUtils {
|
|||||||
if(!"UTF-8".equals(getEncoding(result))) result=GBKtoUTF8(result);
|
if(!"UTF-8".equals(getEncoding(result))) result=GBKtoUTF8(result);
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
System.out.println("url错误:::"+e.toString());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
}finally{
|
||||||
if (response != null)
|
try {
|
||||||
try {
|
response.close();
|
||||||
response.close();
|
httpClientc.close();
|
||||||
} catch (IOException e) {e.printStackTrace();}
|
httpPost.reset();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带有cookie和header 的get请求
|
||||||
|
* @param url
|
||||||
|
* @param params
|
||||||
|
* @param cookie
|
||||||
|
* @param header
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
public static String doGet2(String url, Map<String, String> params, CookieStore cookie,Map<String, String> header,String charset) {
|
public static String doGet2(String url, Map<String, String> params, CookieStore cookie,Map<String, String> header,String charset) {
|
||||||
if(charset==null||charset.trim().length()<1) charset="UTF-8";
|
if(charset==null||charset.trim().length()<1) charset="UTF-8";
|
||||||
if (StringUtils.isBlank(url)) {
|
if (StringUtils.isBlank(url)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HttpGet httpGet = null;
|
||||||
|
CloseableHttpClient httpsClient = null;
|
||||||
|
CloseableHttpResponse response = null;
|
||||||
try {
|
try {
|
||||||
if (params != null && !params.isEmpty()) {
|
if (params != null && !params.isEmpty()) {
|
||||||
List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
|
List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
|
||||||
@@ -565,7 +611,7 @@ public class HttpUtils {
|
|||||||
}
|
}
|
||||||
url += "?" + EntityUtils.toString(new UrlEncodedFormEntity(pairs, charset));
|
url += "?" + EntityUtils.toString(new UrlEncodedFormEntity(pairs, charset));
|
||||||
}
|
}
|
||||||
HttpGet httpGet = new HttpGet(url);
|
httpGet = new HttpGet(url);
|
||||||
|
|
||||||
Set<Entry<String, String>> set = header.entrySet();
|
Set<Entry<String, String>> set = header.entrySet();
|
||||||
Iterator<Entry<String, String>> s = set.iterator();
|
Iterator<Entry<String, String>> s = set.iterator();
|
||||||
@@ -575,8 +621,8 @@ public class HttpUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// https 注意这里获取https内容,使用了忽略证书的方式,当然还有其他的方式来获取https内容
|
// https 注意这里获取https内容,使用了忽略证书的方式,当然还有其他的方式来获取https内容
|
||||||
CloseableHttpClient httpsClient = HttpUtils.createSSLClientCookie(cookie);
|
httpsClient = HttpUtils.createSSLClientCookie(cookie);
|
||||||
CloseableHttpResponse response = httpsClient.execute(httpGet);
|
response = httpsClient.execute(httpGet);
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
if (statusCode != 200) {
|
if (statusCode != 200) {
|
||||||
httpGet.abort();
|
httpGet.abort();
|
||||||
@@ -591,8 +637,17 @@ public class HttpUtils {
|
|||||||
response.close();
|
response.close();
|
||||||
if(!"UTF-8".equals(getEncoding(result))) result=GBKtoUTF8(result);
|
if(!"UTF-8".equals(getEncoding(result))) result=GBKtoUTF8(result);
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
}catch (Exception e) {
|
||||||
|
System.out.println("url错误:::"+e.toString());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
}finally{
|
||||||
|
try {
|
||||||
|
response.close();
|
||||||
|
httpsClient.close();
|
||||||
|
httpGet.reset();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,244 +0,0 @@
|
|||||||
package sc545.pay.utils;
|
|
||||||
|
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
|
|
||||||
import net.coobird.thumbnailator.Thumbnails;
|
|
||||||
import net.coobird.thumbnailator.geometry.Positions;
|
|
||||||
import sun.misc.BASE64Encoder;
|
|
||||||
|
|
||||||
import com.google.zxing.*;
|
|
||||||
import com.google.zxing.common.BitMatrix;
|
|
||||||
|
|
||||||
public class ImgUtils {
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static final int BLACK = 0xFF000000;
|
|
||||||
private static final int WHITE = 0xFFFFFFFF;
|
|
||||||
private static BufferedImage toBufferedImage(BitMatrix matrix) {
|
|
||||||
int width = matrix.getWidth();
|
|
||||||
int height = matrix.getHeight();
|
|
||||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
|
||||||
for (int x = 0; x < width; x++) {
|
|
||||||
for (int y = 0; y < height; y++) {
|
|
||||||
image.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void writeToFile(BitMatrix matrix, String format, File file) throws IOException {
|
|
||||||
BufferedImage image = toBufferedImage(matrix);
|
|
||||||
if (!ImageIO.write(image, format, file)) {
|
|
||||||
throw new IOException("Could not write an image of format " + format + " to " + file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除二维码白边
|
|
||||||
* @param matrix
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static BitMatrix deleteWhite(BitMatrix matrix) {
|
|
||||||
int[] rec = matrix.getEnclosingRectangle();
|
|
||||||
int resWidth = rec[2] + 1;
|
|
||||||
int resHeight = rec[3] + 1;
|
|
||||||
|
|
||||||
BitMatrix resMatrix = new BitMatrix(resWidth, resHeight);
|
|
||||||
resMatrix.clear();
|
|
||||||
for (int i = 0; i < resWidth; i++) {
|
|
||||||
for (int j = 0; j < resHeight; j++) {
|
|
||||||
if (matrix.get(i + rec[0], j + rec[1]))
|
|
||||||
resMatrix.set(i, j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return resMatrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成一张二维码图片文件
|
|
||||||
* @param content 二维码内容
|
|
||||||
* @param widthHeight 宽高度
|
|
||||||
* @param path 图片存储路径(不带文件名)
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String QrImgFile(String content,int widthHeight,String path) {
|
|
||||||
try {
|
|
||||||
String codeName = UUID.randomUUID().toString();// 二维码的图片名
|
|
||||||
String imageType = "jpg";// 图片类型
|
|
||||||
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
|
|
||||||
Map<EncodeHintType, String> hints = new HashMap<EncodeHintType, String>();
|
|
||||||
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
|
|
||||||
BitMatrix bitMatrix= multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, widthHeight, widthHeight, hints);
|
|
||||||
bitMatrix= deleteWhite(bitMatrix);
|
|
||||||
// BufferedImage imgbuf = toBufferedImage(bitMatrix);
|
|
||||||
File file1 = new File(path, codeName + "." + imageType);
|
|
||||||
writeToFile(bitMatrix, imageType, file1);
|
|
||||||
return path+codeName + "." + imageType;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成一张二维码图片(BufferedImage)
|
|
||||||
* @param content 二维码内容
|
|
||||||
* @param widthHeight 宽高度
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static BufferedImage QrImgBuf(String content,int widthHeight) {
|
|
||||||
try {
|
|
||||||
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
|
|
||||||
Map<EncodeHintType, String> hints = new HashMap<EncodeHintType, String>();
|
|
||||||
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
|
|
||||||
BitMatrix bitMatrix= multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, widthHeight, widthHeight, hints);
|
|
||||||
bitMatrix= deleteWhite(bitMatrix);
|
|
||||||
BufferedImage imgbuf = toBufferedImage(bitMatrix);
|
|
||||||
return imgbuf;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成一张二维码图片(base64)<br>
|
|
||||||
* data:image/jpg;base64,base64_code
|
|
||||||
* @param content 二维码内容
|
|
||||||
* @param widthHeight 宽高度
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String QrImgB64(String content,int widthHeight) {
|
|
||||||
try {
|
|
||||||
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
|
|
||||||
Map<EncodeHintType, String> hints = new HashMap<EncodeHintType, String>();
|
|
||||||
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
|
|
||||||
BitMatrix bitMatrix= multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, widthHeight, widthHeight, hints);
|
|
||||||
bitMatrix= deleteWhite(bitMatrix);
|
|
||||||
BufferedImage imgbuf = toBufferedImage(bitMatrix);
|
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();//新建流。
|
|
||||||
ImageIO.write(imgbuf, "jpg", os);//利用ImageIO类提供的write方法,将bi以png图片的数据模式写入流。
|
|
||||||
byte b[] = os.toByteArray();//从流中获取数据数组。
|
|
||||||
String str = new BASE64Encoder().encode(b);
|
|
||||||
return str;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 图片质量压缩
|
|
||||||
* @param img 文件流
|
|
||||||
* @param quality 压缩质量 0~1/1为最高质量
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static BufferedImage rarImgBuf(InputStream img, double quality) {
|
|
||||||
BufferedImage buf =null;
|
|
||||||
try {
|
|
||||||
buf = Thumbnails.of(img).scale(1f).outputQuality(quality).asBufferedImage();
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 图片质量压缩
|
|
||||||
* @param img 文件地址
|
|
||||||
* @param quality 压缩质量 0~1/1为最高质量
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static File rarImgFile(File img, double quality) {
|
|
||||||
File arg0 = img;
|
|
||||||
try {
|
|
||||||
Thumbnails.of(img).scale(1f).outputQuality(quality).toFile(arg0);
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return arg0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 裁剪图片<br>
|
|
||||||
* 从左上角开始裁切<br>
|
|
||||||
* 另存图片保持等比缩放,若填写的高度不符合自动调整为等比例
|
|
||||||
*
|
|
||||||
* @param img 图片文件
|
|
||||||
* @param p 裁切位置 Positions.TOP/BOTTOM_LEFT/RIGHT、CENTER
|
|
||||||
* @param x 裁切x轴范围
|
|
||||||
* @param y 裁切y轴范围
|
|
||||||
* @param width 另存图片的宽度
|
|
||||||
* @param height 另存图片的高度
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static File cutImgFile(File img,Positions p,int x,int y,int width,int height) {
|
|
||||||
File arg0 = img;
|
|
||||||
try {
|
|
||||||
Thumbnails.of(img).sourceRegion(p, x, y).size(width, height).keepAspectRatio(true).toFile(arg0);
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return arg0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 裁剪图片<br>
|
|
||||||
* 从左上角开始裁切<br>
|
|
||||||
* 另存图片保持等比缩放,若填写的高度不符合自动调整为等比例
|
|
||||||
*
|
|
||||||
* @param img 图片流
|
|
||||||
* @param p 裁切位置 Positions.TOP/BOTTOM_LEFT/RIGHT、CENTER
|
|
||||||
* @param x 裁切x轴范围
|
|
||||||
* @param y 裁切y轴范围
|
|
||||||
* @param width 另存图片的宽度
|
|
||||||
* @param height 另存图片的高度
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static BufferedImage cutImgBuf(InputStream img,Positions p,int x,int y,int width,int height) {
|
|
||||||
BufferedImage buf =null;
|
|
||||||
try {
|
|
||||||
buf=Thumbnails.of(img).sourceRegion(p, x, y).size(width, height).keepAspectRatio(true).asBufferedImage();
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,44 +2,22 @@ package sc545.pay.utils;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
public class ReadTxt {
|
public class ReadTxt {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
|
||||||
//上月新增访客
|
|
||||||
Calendar cal = Calendar.getInstance();
|
|
||||||
int month = cal.get(Calendar.MONTH);
|
|
||||||
int year = cal.get(Calendar.YEAR);
|
|
||||||
if(month==0){
|
|
||||||
month=12;
|
|
||||||
year=year-1;
|
|
||||||
}
|
|
||||||
String ms = String.format("%02d", month);
|
|
||||||
String ys = String.format("%04d", year);
|
|
||||||
|
|
||||||
String smm=ys+"-"+ms;
|
|
||||||
String smck= ReadTxt.getSetting(null, "count.ini",smm, "0");
|
|
||||||
|
|
||||||
String a = ReadTxt.getSetting(null, "setting.ini", "pageNullTelTxt","提交需求");
|
|
||||||
System.out.println(a+smm+"\n"+ms+"\n"+ys);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按行读取txt文件
|
* 按行读取txt文件
|
||||||
*
|
*
|
||||||
* @param path
|
* @param path
|
||||||
* 文件地址(默认D:\\开头)
|
* 文件地址(默认D:\\scbox_settings开头)
|
||||||
* @return ArrayList 返回每行数据为一个items的集合
|
* @return ArrayList 返回每行数据为一个items的集合
|
||||||
*/
|
*/
|
||||||
public static ArrayList<String> readFileLine(ServletContext servletContext, String path) {
|
public static ArrayList<String> readFileLine(ServletContext servletContext, String path) {
|
||||||
@@ -49,7 +27,7 @@ public class ReadTxt {
|
|||||||
|
|
||||||
if (servletContext == null) {
|
if (servletContext == null) {
|
||||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||||
path = "D:\\" + path;
|
path = "D:\\scbox_settings\\" + path;
|
||||||
} else {
|
} else {
|
||||||
path = servletContext.getRealPath(path);
|
path = servletContext.getRealPath(path);
|
||||||
}
|
}
|
||||||
@@ -82,55 +60,12 @@ public class ReadTxt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 按行读取文件
|
|
||||||
* debug模式
|
|
||||||
* @param path
|
|
||||||
* 文件地址(默认D:\\开头)
|
|
||||||
* @return ArrayList 返回每行数据为一个items的集合
|
|
||||||
*/
|
|
||||||
public static ArrayList<String> readFileLineDEBUG(String path) {
|
|
||||||
|
|
||||||
if(path.indexOf("./")==0)
|
|
||||||
path =path.substring(1, path.length());
|
|
||||||
|
|
||||||
//debug模式下把所有路径改为tomcat下的真实路径
|
|
||||||
if(path.indexOf("/")==0){
|
|
||||||
String tomcat_path = "D:/java/Tomcat_8.5.23/webapps/ROOT";
|
|
||||||
path =tomcat_path+path;
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayList<String> strarr = null;
|
|
||||||
try {
|
|
||||||
File file = new File(path);
|
|
||||||
if (file.isFile() && file.exists()) { // 判断文件是否存在
|
|
||||||
InputStreamReader read = new InputStreamReader(
|
|
||||||
new FileInputStream(file), "UTF-8");
|
|
||||||
BufferedReader bufferedReader = new BufferedReader(read);
|
|
||||||
String lineTxt = null;
|
|
||||||
strarr = new ArrayList<String>();
|
|
||||||
while ((lineTxt = bufferedReader.readLine()) != null) {
|
|
||||||
|
|
||||||
strarr.add(lineTxt);
|
|
||||||
}
|
|
||||||
|
|
||||||
read.close();
|
|
||||||
} else {
|
|
||||||
strarr = null;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return strarr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 写入txt文档,已存在就修改,否则写入末尾,自动加换行 (文件格式:key=value,换行分隔)
|
* 写入txt文档,已存在就修改,否则写入末尾,自动加换行 (文件格式:key=value,换行分隔)
|
||||||
*
|
*
|
||||||
* @param path
|
* @param path
|
||||||
* 文件地址(默认D:\\开头)
|
* 文件地址(默认D:\\scbox_settings开头)
|
||||||
* @param keyname
|
* @param keyname
|
||||||
* 要修改的参数名
|
* 要修改的参数名
|
||||||
* @param content
|
* @param content
|
||||||
@@ -145,7 +80,7 @@ public class ReadTxt {
|
|||||||
|
|
||||||
if (servletContext == null) {
|
if (servletContext == null) {
|
||||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||||
path = "D:\\" + path;
|
path = "D:\\scbox_settings\\" + path;
|
||||||
} else {
|
} else {
|
||||||
path = servletContext.getRealPath(path);
|
path = servletContext.getRealPath(path);
|
||||||
}
|
}
|
||||||
@@ -213,7 +148,7 @@ public class ReadTxt {
|
|||||||
* 读取txt配置,返回map集合(文件格式:key=value,换行分隔)
|
* 读取txt配置,返回map集合(文件格式:key=value,换行分隔)
|
||||||
*
|
*
|
||||||
* @param path
|
* @param path
|
||||||
* 文件地址(默认D:\\开头)
|
* 文件地址(默认D:\\scbox_settings开头)
|
||||||
* @return hashmap
|
* @return hashmap
|
||||||
*/
|
*/
|
||||||
public static HashMap<String, String> readSetting(ServletContext servletContext, String path) {
|
public static HashMap<String, String> readSetting(ServletContext servletContext, String path) {
|
||||||
@@ -222,7 +157,7 @@ public class ReadTxt {
|
|||||||
|
|
||||||
if (servletContext == null) {
|
if (servletContext == null) {
|
||||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||||
path = "D:\\" + path;
|
path = "D:\\scbox_settings\\" + path;
|
||||||
} else {
|
} else {
|
||||||
path = servletContext.getRealPath(path);
|
path = servletContext.getRealPath(path);
|
||||||
}
|
}
|
||||||
@@ -268,7 +203,7 @@ public class ReadTxt {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param path
|
* @param path
|
||||||
* 文件地址(默认D:\\开头)
|
* 文件地址(默认D:\\scbox_settings开头)
|
||||||
*
|
*
|
||||||
* @param t 只取以此字符开头的,不限制填null
|
* @param t 只取以此字符开头的,不限制填null
|
||||||
* @param st 从以此字符开头的行开始读取,不限制填null
|
* @param st 从以此字符开头的行开始读取,不限制填null
|
||||||
@@ -284,7 +219,7 @@ public class ReadTxt {
|
|||||||
|
|
||||||
if (servletContext == null) {
|
if (servletContext == null) {
|
||||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||||
path = "D:\\" + path;
|
path = "D:\\scbox_settings\\" + path;
|
||||||
} else {
|
} else {
|
||||||
path = servletContext.getRealPath(path);
|
path = servletContext.getRealPath(path);
|
||||||
}
|
}
|
||||||
@@ -389,7 +324,7 @@ public class ReadTxt {
|
|||||||
|
|
||||||
if (servletContext == null) {
|
if (servletContext == null) {
|
||||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||||
path = "D:\\" + path;
|
path = "D:\\scbox_settings\\" + path;
|
||||||
} else {
|
} else {
|
||||||
path = servletContext.getRealPath(path);
|
path = servletContext.getRealPath(path);
|
||||||
}
|
}
|
||||||
@@ -458,7 +393,7 @@ public class ReadTxt {
|
|||||||
|
|
||||||
if (servletContext == null) {
|
if (servletContext == null) {
|
||||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||||
path = "D:\\" + path;
|
path = "D:\\scbox_settings\\" + path;
|
||||||
} else {
|
} else {
|
||||||
path = servletContext.getRealPath(path);
|
path = servletContext.getRealPath(path);
|
||||||
}
|
}
|
||||||
@@ -528,7 +463,7 @@ public class ReadTxt {
|
|||||||
|
|
||||||
if (servletContext == null) {
|
if (servletContext == null) {
|
||||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||||
path = "D:\\" + path;
|
path = "D:\\scbox_settings\\" + path;
|
||||||
} else {
|
} else {
|
||||||
path = servletContext.getRealPath(path);
|
path = servletContext.getRealPath(path);
|
||||||
}
|
}
|
||||||
@@ -615,7 +550,7 @@ public class ReadTxt {
|
|||||||
|
|
||||||
if (servletContext == null) {
|
if (servletContext == null) {
|
||||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||||
path = "D:\\" + path;
|
path = "D:\\scbox_settings\\" + path;
|
||||||
} else {
|
} else {
|
||||||
path = servletContext.getRealPath(path);
|
path = servletContext.getRealPath(path);
|
||||||
}
|
}
|
||||||
@@ -682,6 +617,65 @@ public class ReadTxt {
|
|||||||
/**************/
|
/**************/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除全部内容
|
||||||
|
*
|
||||||
|
* @param path
|
||||||
|
* 文件地址
|
||||||
|
* @param nullString
|
||||||
|
* 设置值为空时默认返回的内容
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static void delAll(ServletContext servletContext, String path) {
|
||||||
|
|
||||||
|
|
||||||
|
/**************/
|
||||||
|
// 如果存在,则追加内容;如果文件不存在,则创建文件
|
||||||
|
if(path.indexOf("./")==0)
|
||||||
|
path =path.substring(1, path.length());
|
||||||
|
|
||||||
|
if (servletContext == null) {
|
||||||
|
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||||
|
path = "D:\\scbox_settings\\" + path;
|
||||||
|
} else {
|
||||||
|
path = servletContext.getRealPath(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
File file = new File(path);
|
||||||
|
if (file.isFile() && file.exists()) { // 判断文件是否存在
|
||||||
|
|
||||||
|
// 把新内容覆盖写入文件
|
||||||
|
PrintWriter out = new PrintWriter(new BufferedWriter(
|
||||||
|
new OutputStreamWriter(new FileOutputStream(path),
|
||||||
|
"UTF-8")));
|
||||||
|
out.write("".toString());
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
|
||||||
|
} else {// 不存在,创建
|
||||||
|
String path2 = path.substring(0, path.replace("\\", "/").lastIndexOf("/"));
|
||||||
|
File file1 = new File(path2);
|
||||||
|
// 如果文件夹不存在则创建
|
||||||
|
if (!file1.exists() && !file1.isDirectory()) {
|
||||||
|
file1.mkdirs();
|
||||||
|
}
|
||||||
|
File file2 = new File(path);
|
||||||
|
if (!file2.exists()) {
|
||||||
|
file2.createNewFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
/**************/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package sc545.pay.utils;
|
package sc545.pay.utils;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@@ -16,6 +19,7 @@ import java.util.Random;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import javax.servlet.http.Cookie;
|
import javax.servlet.http.Cookie;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
@@ -25,8 +29,7 @@ import org.apache.commons.lang.time.DateUtils;
|
|||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String s = floatToString(0.01235788889f, 3,false);
|
getWeekNum();
|
||||||
System.out.println(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,6 +162,79 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断某个时间是否过期。传进来一个旧时间,和有效天数,判断今天这个旧时间是否过期
|
||||||
|
*
|
||||||
|
* @param d
|
||||||
|
* 旧时间 "2019-8-5"
|
||||||
|
* @param day
|
||||||
|
* 有效天数
|
||||||
|
* @return true:没有过期;false:过期了
|
||||||
|
*/
|
||||||
|
public static boolean dateout(String d, int day) {
|
||||||
|
if (d == null || "".equals(d) || "null".equals(d))
|
||||||
|
return false;
|
||||||
|
Date date = Utils.dateadd(Utils.string2Date(d), day);
|
||||||
|
Date newdate = new Date();
|
||||||
|
int i = date.compareTo(newdate);
|
||||||
|
if (i >= 0) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算两个时间相差的秒数
|
||||||
|
*
|
||||||
|
* @param endDate
|
||||||
|
* 结束时间 null为当前
|
||||||
|
* @param nowDate
|
||||||
|
* 开始时间
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static long datePoor(Date endDate, Date nowDate) {
|
||||||
|
|
||||||
|
if(endDate==null) endDate = new Date();
|
||||||
|
|
||||||
|
long ns = 1000;// 一秒
|
||||||
|
|
||||||
|
// 获得两个时间的毫秒时间差异
|
||||||
|
|
||||||
|
long diff = endDate.getTime() - nowDate.getTime();
|
||||||
|
|
||||||
|
long sec = diff / ns;// 计算差多少秒
|
||||||
|
return sec;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算两个时间相差的秒数
|
||||||
|
*
|
||||||
|
* @param endDate
|
||||||
|
* 结束时间 null为当前
|
||||||
|
* @param nowDate
|
||||||
|
* 开始时间
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static long datePoor(String endDates, String nowDates) {
|
||||||
|
if(endDates==null) endDates=Utils.date2String(null, null);
|
||||||
|
Date endDate = Utils.string2Date(endDates, null);
|
||||||
|
Date nowDate = Utils.string2Date(nowDates, null);
|
||||||
|
|
||||||
|
long ns = 1000;// 一秒
|
||||||
|
|
||||||
|
// 获得两个时间的毫秒时间差异
|
||||||
|
|
||||||
|
long diff = endDate.getTime() - nowDate.getTime();
|
||||||
|
|
||||||
|
long sec = diff / ns;// 计算差多少秒
|
||||||
|
return sec;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置定时器启动时间
|
* 设置定时器启动时间
|
||||||
* @param format 格式 yyyy-MM-dd 07:30:00
|
* @param format 格式 yyyy-MM-dd 07:30:00
|
||||||
@@ -234,28 +310,6 @@ public class Utils {
|
|||||||
return s2;
|
return s2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断某个时间是否过期。传进来一个旧时间,和有效天数,判断今天这个旧时间是否过期
|
|
||||||
*
|
|
||||||
* @param d
|
|
||||||
* 旧时间 "2019-8-5"
|
|
||||||
* @param day
|
|
||||||
* 有效天数
|
|
||||||
* @return true:没有过期;false:过期了
|
|
||||||
*/
|
|
||||||
public static boolean dateout(String d, int day) {
|
|
||||||
if (d == null || "".equals(d) || "null".equals(d))
|
|
||||||
return false;
|
|
||||||
Date date = Utils.dateadd(Utils.string2Date(d), day);
|
|
||||||
Date newdate = new Date();
|
|
||||||
int i = date.compareTo(newdate);
|
|
||||||
if (i >= 0) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL解析与转义
|
* URL解析与转义
|
||||||
*
|
*
|
||||||
@@ -687,32 +741,11 @@ public class Utils {
|
|||||||
return Long.valueOf(str2);
|
return Long.valueOf(str2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**获取今天是周几,1-7*/
|
||||||
* 计算两个时间相差的秒数
|
public static long getWeekNum() {
|
||||||
*
|
long[] weekDays = {7,1,2,3,4,5,6};
|
||||||
* @param endDate
|
Calendar c = Calendar.getInstance();
|
||||||
* 结束时间
|
return weekDays[c.get(Calendar.DAY_OF_WEEK)-1];
|
||||||
* @param nowDate
|
|
||||||
* 开始时间
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static long getDatePoor(Date endDate, Date nowDate) {
|
|
||||||
|
|
||||||
long nd = 1000 * 24 * 60 * 60;// 一天
|
|
||||||
|
|
||||||
long nh = 1000 * 60 * 60;// 一小时
|
|
||||||
|
|
||||||
long nm = 1000 * 60;// 一分钟
|
|
||||||
|
|
||||||
long ns = 1000;// 一秒
|
|
||||||
|
|
||||||
// 获得两个时间的毫秒时间差异
|
|
||||||
|
|
||||||
long diff = endDate.getTime() - nowDate.getTime();
|
|
||||||
|
|
||||||
long sec = diff / ns;// 计算差多少秒
|
|
||||||
return sec;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1084,7 +1117,8 @@ public class Utils {
|
|||||||
DecimalFormat decimalFormat=new DecimalFormat(f);//构造方法的字符格式这里如果小数不足2位,会以0补足.
|
DecimalFormat decimalFormat=new DecimalFormat(f);//构造方法的字符格式这里如果小数不足2位,会以0补足.
|
||||||
String p=decimalFormat.format(d);//format 返回的是字符串
|
String p=decimalFormat.format(d);//format 返回的是字符串
|
||||||
if(p.split("\\.")[0].length()<1) p="0"+p;
|
if(p.split("\\.")[0].length()<1) p="0"+p;
|
||||||
String nn = p.split("\\.")[1];
|
String nn ="0";
|
||||||
|
if(p.split("\\.").length>1) nn = p.split("\\.")[1];
|
||||||
if(!x){
|
if(!x){
|
||||||
if(nn.replaceAll("0", "").length()<1) p=p.split("\\.")[0];
|
if(nn.replaceAll("0", "").length()<1) p=p.split("\\.")[0];
|
||||||
}
|
}
|
||||||
@@ -1171,6 +1205,31 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
return pics;
|
return pics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取图片的宽高
|
||||||
|
* @param url
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int[] getImgWH(String url){
|
||||||
|
int srcWidth = 0; // 源图宽度
|
||||||
|
int srcHeight = 0; // 源图高度
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
URL url1 = new URL(url);
|
||||||
|
URLConnection connection = url1.openConnection();
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
BufferedImage image = ImageIO.read(connection.getInputStream());
|
||||||
|
if(image==null) return new int[]{0,0};
|
||||||
|
srcWidth = image .getWidth(); // 源图宽度
|
||||||
|
srcHeight = image .getHeight(); // 源图高度
|
||||||
|
|
||||||
|
}catch(Exception e){e.printStackTrace();}
|
||||||
|
|
||||||
|
return new int[]{srcWidth,srcHeight};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Map<String, Object> urlParamToMaps(String q) {
|
public static Map<String, Object> urlParamToMaps(String q) {
|
||||||
|
|
||||||
|
|||||||
@@ -37,21 +37,4 @@
|
|||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- 配置静态资源 -->
|
|
||||||
<mvc:resources location="/" mapping="/**/*.js" />
|
|
||||||
<mvc:resources location="/" mapping="/**/*.css" />
|
|
||||||
<mvc:resources location="/assets/" mapping="/assets/**/*" />
|
|
||||||
<mvc:resources location="/images/" mapping="/images/*"
|
|
||||||
cache-period="360000" />
|
|
||||||
|
|
||||||
<mvc:interceptors>
|
|
||||||
<mvc:interceptor>
|
|
||||||
<mvc:mapping path="/**" />
|
|
||||||
<bean class="sc545.pay.interceptor.testInterceptor" />
|
|
||||||
</mvc:interceptor>
|
|
||||||
|
|
||||||
</mvc:interceptors>
|
|
||||||
|
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|||||||
Reference in New Issue
Block a user