4 Commits
r4 ... r8

Author SHA1 Message Date
admin
4625fbefed utils 2022-10-14 09:08:47 +08:00
admin
d7e971f32d add 2022-10-13 17:13:54 +08:00
admin
7ab231a76f 修复bug 2022-10-13 16:04:14 +08:00
Administrator
29422d1c04 bug 2022-10-03 16:57:17 +08:00
8 changed files with 16 additions and 369 deletions

View File

@@ -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;
}
}

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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,9 @@ 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.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;
@@ -317,7 +306,8 @@ public class HttpUtils {
} }
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() {
@@ -491,6 +481,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)) {
@@ -548,6 +539,7 @@ public class HttpUtils {
return null; return null;
} }
@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)) {

View File

@@ -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;
}
}

View File

@@ -2,7 +2,6 @@ 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.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map.Entry; import java.util.Map.Entry;

View File

@@ -29,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);
} }
/** /**
@@ -702,12 +701,6 @@ public class Utils {
*/ */
public static long getDatePoor(Date endDate, Date nowDate) { 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 ns = 1000;// 一秒
// 获得两个时间的毫秒时间差异 // 获得两个时间的毫秒时间差异
@@ -718,6 +711,13 @@ public class Utils {
return sec; return sec;
} }
/**获取今天是周几1-7*/
public static long getWeekNum() {
long[] weekDays = {7,1,2,3,4,5,6};
Calendar c = Calendar.getInstance();
return weekDays[c.get(Calendar.DAY_OF_WEEK)-1];
}
/** /**
* 获取用户真实ip * 获取用户真实ip
@@ -1088,7 +1088,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];
} }

View File

@@ -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>