mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
2019-11-18更新
This commit is contained in:
@@ -9,6 +9,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.servlet.MultipartConfigFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
@@ -56,7 +56,9 @@ public class ClientController {
|
||||
|
||||
@PostMapping(value = "/clientupimg")
|
||||
@ResponseBody
|
||||
public ResultBean clientupimg(@RequestParam("file") List<MultipartFile> file, String email, String pass) throws Exception {
|
||||
public ResultBean clientupimg(HttpServletRequest request,@RequestParam("file") List<MultipartFile> file, String email, String pass) throws Exception {
|
||||
String userip = GetIPS.getIpAddr(request);
|
||||
Print.Normal("上传者ip:"+userip);
|
||||
ResultBean resultBean = null;
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
UploadConfig uploadConfig = uploadConfigService.getUpdateConfig();
|
||||
@@ -165,12 +167,7 @@ public class ClientController {
|
||||
}
|
||||
img.setSizes((entry.getValue()));
|
||||
img.setImgname(SetText.getSubString(entry.getKey().getImgurl(), key.getRequestAddress() + "/", ""));
|
||||
//img.setAbnormal(Sentence.getIPs());
|
||||
//多线程插入ip值
|
||||
GetIPS getIPS = new GetIPS();
|
||||
getIPS.setImgname(SetText.getSubString(entry.getKey().getImgurl(), key.getRequestAddress() + "/", ""));
|
||||
Thread thread = new Thread(getIPS);
|
||||
thread.start();
|
||||
img.setAbnormal(userip);
|
||||
img.setImgtype(0);
|
||||
//-1证明超出大小,
|
||||
if (entry.getValue() != -1) {
|
||||
@@ -205,12 +202,7 @@ public class ClientController {
|
||||
}
|
||||
img.setSizes((entry.getValue())/1024);
|
||||
img.setImgname(SetText.getSubString(entry.getKey().getImgurl(), key.getRequestAddress() + "/", ""));
|
||||
//img.setAbnormal(Sentence.getIPs());
|
||||
//多线程插入ip值
|
||||
GetIPS getIPS = new GetIPS();
|
||||
getIPS.setImgname(SetText.getSubString(entry.getKey().getImgurl(), key.getRequestAddress() + "/", ""));
|
||||
Thread thread = new Thread(getIPS);
|
||||
thread.start();
|
||||
img.setAbnormal(userip);
|
||||
img.setImgtype(0);
|
||||
//-1证明超出大小,
|
||||
if (entry.getValue() != -1) {
|
||||
@@ -237,6 +229,8 @@ public class ClientController {
|
||||
@ResponseBody
|
||||
public ResultBean clientupurlimg( String imgurl, HttpServletRequest request, Integer setday,
|
||||
String email,String pass) throws Exception {
|
||||
String userip = GetIPS.getIpAddr(request);
|
||||
Print.Normal("上传者ip:"+userip);
|
||||
ResultBean resultBean = null;
|
||||
UploadConfig uploadConfig = uploadConfigService.getUpdateConfig();
|
||||
if (uploadConfig.getApi() == 1) {
|
||||
@@ -359,12 +353,7 @@ public class ClientController {
|
||||
}
|
||||
img.setSizes((entry.getValue()));
|
||||
img.setImgname(SetText.getSubString(entry.getKey().getImgurl(), key.getRequestAddress() + "/", ""));
|
||||
//img.setAbnormal(Sentence.getIPs());
|
||||
//多线程插入ip值
|
||||
GetIPS getIPS = new GetIPS();
|
||||
getIPS.setImgname(SetText.getSubString(entry.getKey().getImgurl(), key.getRequestAddress() + "/", ""));
|
||||
Thread thread = new Thread(getIPS);
|
||||
thread.start();
|
||||
img.setAbnormal(userip);
|
||||
img.setImgtype(0);
|
||||
userService.insertimg(img);
|
||||
long etime = System.currentTimeMillis();
|
||||
@@ -450,12 +439,7 @@ public class ClientController {
|
||||
}
|
||||
img.setSizes((entry.getValue()));
|
||||
img.setImgname(SetText.getSubString(entry.getKey().getImgurl(), key.getRequestAddress() + "/", ""));
|
||||
//img.setAbnormal(Sentence.getIPs());
|
||||
//多线程插入ip值
|
||||
GetIPS getIPS = new GetIPS();
|
||||
getIPS.setImgname(SetText.getSubString(entry.getKey().getImgurl(), key.getRequestAddress() + "/", ""));
|
||||
Thread thread = new Thread(getIPS);
|
||||
thread.start();
|
||||
img.setAbnormal(userip);
|
||||
img.setImgtype(0);
|
||||
userService.insertimg(img);
|
||||
long etime = System.currentTimeMillis();
|
||||
|
||||
@@ -51,10 +51,10 @@ public class UpdateImgController {
|
||||
@Autowired
|
||||
private ImgService imgService;
|
||||
|
||||
private Integer updatekey;
|
||||
//private Integer updatekey;
|
||||
|
||||
@RequestMapping({"/", "/index"})
|
||||
public String indexImg(Model model, HttpSession httpSession) {
|
||||
public String indexImg(Model model, HttpSession httpSession,HttpServletRequest request) {
|
||||
//boolean b = VerificationDomain.verification();
|
||||
boolean b = true;
|
||||
if(b){
|
||||
@@ -106,16 +106,18 @@ public class UpdateImgController {
|
||||
return "index";
|
||||
}
|
||||
Random random = new Random();
|
||||
updatekey = random.nextInt(10000);
|
||||
model.addAttribute("updatekey", updatekey);
|
||||
//updatekey = random.nextInt(10000);
|
||||
//model.addAttribute("updatekey", updatekey);
|
||||
return "index";
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/upimg")
|
||||
@ResponseBody
|
||||
public String upimg( HttpSession session
|
||||
public String upimg( HttpSession session,HttpServletRequest request
|
||||
, @RequestParam(value = "file", required = false) MultipartFile multipartFile,Integer setday,String upurlk) throws Exception {
|
||||
String userip = GetIPS.getIpAddr(request);
|
||||
Print.Normal("上传者ip:"+userip);
|
||||
java.text.DateFormat dateFormat = new java.text.SimpleDateFormat("yyyy/MM/dd");
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
@@ -129,7 +131,7 @@ public class UpdateImgController {
|
||||
String userpath = "tourist";
|
||||
Boolean b =false;
|
||||
|
||||
if(Integer.parseInt(Base64Encryption.decryptBASE64(upurlk))!=updatekey){
|
||||
if(Integer.parseInt(Base64Encryption.decryptBASE64(upurlk))!=yzupdate()){
|
||||
jsonObject.put("imgurls",403);//非法调用
|
||||
return jsonObject.toString();
|
||||
}
|
||||
@@ -208,14 +210,10 @@ public class UpdateImgController {
|
||||
img.setSizes((entry.getValue()) / 1024);
|
||||
img.setImgname(SetText.getSubString(entry.getKey().getImgurl(), key.getRequestAddress() + "/", ""));
|
||||
img.setImgtype(setday>0?1:0);
|
||||
img.setAbnormal(userip);
|
||||
userService.insertimg(img);
|
||||
long etime = System.currentTimeMillis();
|
||||
Print.Normal("上传图片所用时长:" + String.valueOf(etime - stime) + "ms");
|
||||
//多线程插入ip值
|
||||
GetIPS getIPS = new GetIPS();
|
||||
getIPS.setImgname(SetText.getSubString(entry.getKey().getImgurl(), key.getRequestAddress() + "/", ""));
|
||||
Thread thread = new Thread(getIPS);
|
||||
thread.start();
|
||||
}
|
||||
return jsonObject.toString();
|
||||
}
|
||||
@@ -249,7 +247,7 @@ public class UpdateImgController {
|
||||
}
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
//判断非法调用
|
||||
if(Integer.parseInt(Base64Encryption.decryptBASE64(upurlk))!=updatekey){
|
||||
if(Integer.parseInt(Base64Encryption.decryptBASE64(upurlk))!=yzupdate()){
|
||||
jsonArray.add(-403);//非法调用
|
||||
return jsonArray.toString();
|
||||
}
|
||||
@@ -266,141 +264,134 @@ public class UpdateImgController {
|
||||
}
|
||||
//先判断对象存储key是不是null
|
||||
Print.warning("上传地址是:"+request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/");
|
||||
if(usermemory/1024>=memory) {
|
||||
jsonArray.add(-5);
|
||||
return jsonArray.toString();
|
||||
}
|
||||
long stime = System.currentTimeMillis();
|
||||
//判断是会员还是游客
|
||||
if(u!=null){
|
||||
//判断文件大小
|
||||
if(imgsize>0 && imgsize>=(yonghu*1024*1024)) {
|
||||
//文件过大
|
||||
jsonArray.add(-2);
|
||||
String userip = GetIPS.getIpAddr(request);
|
||||
Print.Normal("上传者ip:"+userip);
|
||||
if(usermemory/1024>=memory) {
|
||||
jsonArray.add(-5);
|
||||
return jsonArray.toString();
|
||||
}
|
||||
long stime = System.currentTimeMillis();
|
||||
//判断是会员还是游客
|
||||
if(u!=null){
|
||||
//判断文件大小
|
||||
if(imgsize>0 && imgsize>=(yonghu*1024*1024)) {
|
||||
//文件过大
|
||||
jsonArray.add(-2);
|
||||
return jsonArray.toString();
|
||||
}
|
||||
try{
|
||||
boolean bl =ImgUrlUtil.downLoadFromUrl(imgurl,
|
||||
uuid, request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/");
|
||||
if(bl==true){
|
||||
FileInputStream is = new FileInputStream(request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/"+uuid);
|
||||
byte[] b = new byte[3];
|
||||
is.read(b, 0, b.length);
|
||||
String xxx = ImgUrlUtil.bytesToHexString(b);
|
||||
xxx = xxx.toUpperCase();
|
||||
if(is!=null){is.close();}
|
||||
//判断文件头是否是图片
|
||||
if(TypeDict.checkType(xxx).equals("0000")) {
|
||||
jsonArray.add(-3);//不是图片格式
|
||||
return jsonArray.toString();
|
||||
}
|
||||
try{
|
||||
boolean bl =ImgUrlUtil.downLoadFromUrl(imgurl,
|
||||
uuid, request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/");
|
||||
if(bl==true){
|
||||
FileInputStream is = new FileInputStream(request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/"+uuid);
|
||||
byte[] b = new byte[3];
|
||||
is.read(b, 0, b.length);
|
||||
String xxx = ImgUrlUtil.bytesToHexString(b);
|
||||
xxx = xxx.toUpperCase();
|
||||
if(is!=null){is.close();}
|
||||
//判断文件头是否是图片
|
||||
if(TypeDict.checkType(xxx).equals("0000")) {
|
||||
jsonArray.add(-3);//不是图片格式
|
||||
return jsonArray.toString();
|
||||
}
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put(TypeDict.checkType(xxx), request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/"+uuid);
|
||||
Map<ReturnImage, Integer> m = null;
|
||||
m = GetSource.storageSource(key.getStorageType(), null, userpath,map,setday);
|
||||
Images img = new Images();
|
||||
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
|
||||
String times = df.format(new Date());
|
||||
System.out.println("上传图片的时间是:"+times);
|
||||
for (Map.Entry<ReturnImage, Integer> entry : m.entrySet()) {
|
||||
if(key.getStorageType()==5){
|
||||
if(config.getDomain()!=null){
|
||||
jsonArray.add(config.getDomain()+"/links/"+entry.getKey().getImgurl());
|
||||
img.setImgurl(config.getDomain()+"/links/"+entry.getKey().getImgurl());//图片链接
|
||||
}else{
|
||||
jsonArray.add(config.getDomain()+"/links/"+entry.getKey().getImgurl());
|
||||
img.setImgurl("http://"+IPPortUtil.getLocalIP()+":"+IPPortUtil.getLocalPort()+"/links/"+entry.getKey().getImgurl());//图片链接
|
||||
}
|
||||
}else{
|
||||
jsonArray.add(entry.getKey().getImgurl());
|
||||
img.setImgurl(entry.getKey().getImgurl());
|
||||
}
|
||||
img.setUpdatetime(times);
|
||||
img.setSource(key.getStorageType());
|
||||
img.setUserid(u == null?0:u.getId());
|
||||
img.setSizes((entry.getValue()));
|
||||
img.setImgname(SetText.getSubString(entry.getKey().getImgurl(), key.getRequestAddress() + "/", ""));
|
||||
//img.setAbnormal(Sentence.getIPs());
|
||||
//多线程插入ip值
|
||||
GetIPS getIPS = new GetIPS();
|
||||
getIPS.setImgname(SetText.getSubString(entry.getKey().getImgurl(), key.getRequestAddress() + "/", ""));
|
||||
Thread thread = new Thread(getIPS);
|
||||
thread.start();
|
||||
if(setday>0){img.setImgtype(1);}
|
||||
else{img.setImgtype(0);}
|
||||
userService.insertimg(img);
|
||||
long etime = System.currentTimeMillis();
|
||||
System.out.println("上传图片所用时长:" + String.valueOf(etime - stime) + "ms");
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put(TypeDict.checkType(xxx), request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/"+uuid);
|
||||
Map<ReturnImage, Integer> m = null;
|
||||
m = GetSource.storageSource(key.getStorageType(), null, userpath,map,setday);
|
||||
Images img = new Images();
|
||||
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
|
||||
String times = df.format(new Date());
|
||||
System.out.println("上传图片的时间是:"+times);
|
||||
for (Map.Entry<ReturnImage, Integer> entry : m.entrySet()) {
|
||||
if(key.getStorageType()==5){
|
||||
if(config.getDomain()!=null){
|
||||
jsonArray.add(config.getDomain()+"/links/"+entry.getKey().getImgurl());
|
||||
img.setImgurl(config.getDomain()+"/links/"+entry.getKey().getImgurl());//图片链接
|
||||
}else{
|
||||
jsonArray.add(config.getDomain()+"/links/"+entry.getKey().getImgurl());
|
||||
img.setImgurl("http://"+IPPortUtil.getLocalIP()+":"+IPPortUtil.getLocalPort()+"/links/"+entry.getKey().getImgurl());//图片链接
|
||||
}
|
||||
}else{
|
||||
jsonArray.add(entry.getKey().getImgurl());
|
||||
img.setImgurl(entry.getKey().getImgurl());
|
||||
}
|
||||
}catch (Exception e) {
|
||||
Print.warning(e.toString());
|
||||
jsonArray.add(-4);
|
||||
img.setUpdatetime(times);
|
||||
img.setSource(key.getStorageType());
|
||||
img.setUserid(u == null?0:u.getId());
|
||||
img.setSizes((entry.getValue()));
|
||||
img.setImgname(SetText.getSubString(entry.getKey().getImgurl(), key.getRequestAddress() + "/", ""));
|
||||
img.setAbnormal(userip);
|
||||
if(setday>0){img.setImgtype(1);}
|
||||
else{img.setImgtype(0);}
|
||||
userService.insertimg(img);
|
||||
long etime = System.currentTimeMillis();
|
||||
System.out.println("上传图片所用时长:" + String.valueOf(etime - stime) + "ms");
|
||||
}
|
||||
}else{
|
||||
if(imgsize>0 && imgsize>=(youke*1024*1024)){
|
||||
//文件过大
|
||||
jsonArray.add(-2);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
Print.warning(e.toString());
|
||||
jsonArray.add(-4);
|
||||
}
|
||||
}else{
|
||||
if(imgsize>0 && imgsize>=(youke*1024*1024)){
|
||||
//文件过大
|
||||
jsonArray.add(-2);
|
||||
return jsonArray.toString();
|
||||
}
|
||||
try{
|
||||
boolean bl = ImgUrlUtil.downLoadFromUrl(imgurl,
|
||||
uuid, request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/");
|
||||
if(bl==true){
|
||||
FileInputStream is = new FileInputStream(request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/"+uuid);
|
||||
byte[] b = new byte[3];
|
||||
is.read(b, 0, b.length);
|
||||
String xxx = ImgUrlUtil.bytesToHexString(b);
|
||||
xxx = xxx.toUpperCase();
|
||||
if(is!=null){is.close(); }
|
||||
//判断文件头是否是图片
|
||||
if(xxx.equals("0000")) {
|
||||
jsonArray.add(-3);
|
||||
return jsonArray.toString();
|
||||
}
|
||||
try{
|
||||
boolean bl = ImgUrlUtil.downLoadFromUrl(imgurl,
|
||||
uuid, request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/");
|
||||
if(bl==true){
|
||||
FileInputStream is = new FileInputStream(request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/"+uuid);
|
||||
byte[] b = new byte[3];
|
||||
is.read(b, 0, b.length);
|
||||
String xxx = ImgUrlUtil.bytesToHexString(b);
|
||||
xxx = xxx.toUpperCase();
|
||||
if(is!=null){is.close(); }
|
||||
//判断文件头是否是图片
|
||||
if(xxx.equals("0000")) {
|
||||
jsonArray.add(-3);
|
||||
return jsonArray.toString();
|
||||
}
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put(TypeDict.checkType(xxx), request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/"+uuid);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put(TypeDict.checkType(xxx), request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/"+uuid);
|
||||
|
||||
Map<ReturnImage, Integer> m = null;
|
||||
m = GetSource.storageSource(key.getStorageType(), null, userpath,map,setday);
|
||||
Images img = new Images();
|
||||
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
|
||||
String times = df.format(new Date());
|
||||
System.out.println("上传图片的时间是:"+times);
|
||||
for (Map.Entry<ReturnImage, Integer> entry : m.entrySet()) {
|
||||
if(key.getStorageType()==5){
|
||||
if(config.getDomain()!=null){
|
||||
jsonArray.add(config.getDomain()+"/links/"+entry.getKey().getImgurl());
|
||||
img.setImgurl(config.getDomain()+"/links/"+entry.getKey().getImgurl());//图片链接
|
||||
}else{
|
||||
jsonArray.add(config.getDomain()+"/links/"+entry.getKey().getImgurl());
|
||||
img.setImgurl("http://"+IPPortUtil.getLocalIP()+":"+IPPortUtil.getLocalPort()+"/links/"+entry.getKey().getImgurl());//图片链接
|
||||
}
|
||||
}else{
|
||||
jsonArray.add(entry.getKey().getImgurl());
|
||||
img.setImgurl(entry.getKey().getImgurl());//图片链接
|
||||
}
|
||||
img.setUpdatetime(times);
|
||||
img.setSource(key.getStorageType());
|
||||
img.setUserid(u == null?0:u.getId());
|
||||
img.setSizes((entry.getValue()));
|
||||
img.setImgname(SetText.getSubString(entry.getKey().getImgurl(), key.getRequestAddress() + "/", ""));
|
||||
img.setImgtype(setday>0?1:0);
|
||||
userService.insertimg(img);
|
||||
long etime = System.currentTimeMillis();
|
||||
System.out.println("上传图片所用时长:" + String.valueOf(etime - stime) + "ms");
|
||||
//多线程插入ip值
|
||||
GetIPS getIPS = new GetIPS();
|
||||
getIPS.setImgname(SetText.getSubString(entry.getKey().getImgurl(), key.getRequestAddress() + "/", ""));
|
||||
Thread thread = new Thread(getIPS);
|
||||
thread.start();
|
||||
Map<ReturnImage, Integer> m = null;
|
||||
m = GetSource.storageSource(key.getStorageType(), null, userpath,map,setday);
|
||||
Images img = new Images();
|
||||
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
|
||||
String times = df.format(new Date());
|
||||
System.out.println("上传图片的时间是:"+times);
|
||||
for (Map.Entry<ReturnImage, Integer> entry : m.entrySet()) {
|
||||
if(key.getStorageType()==5){
|
||||
if(config.getDomain()!=null){
|
||||
jsonArray.add(config.getDomain()+"/links/"+entry.getKey().getImgurl());
|
||||
img.setImgurl(config.getDomain()+"/links/"+entry.getKey().getImgurl());//图片链接
|
||||
}else{
|
||||
jsonArray.add(config.getDomain()+"/links/"+entry.getKey().getImgurl());
|
||||
img.setImgurl("http://"+IPPortUtil.getLocalIP()+":"+IPPortUtil.getLocalPort()+"/links/"+entry.getKey().getImgurl());//图片链接
|
||||
}
|
||||
}else{
|
||||
jsonArray.add(entry.getKey().getImgurl());
|
||||
img.setImgurl(entry.getKey().getImgurl());//图片链接
|
||||
}
|
||||
}catch (Exception e) {
|
||||
Print.warning(e.toString());
|
||||
jsonArray.add(-4);
|
||||
img.setUpdatetime(times);
|
||||
img.setSource(key.getStorageType());
|
||||
img.setUserid(u == null?0:u.getId());
|
||||
img.setSizes((entry.getValue()));
|
||||
img.setImgname(SetText.getSubString(entry.getKey().getImgurl(), key.getRequestAddress() + "/", ""));
|
||||
img.setImgtype(setday>0?1:0);
|
||||
img.setAbnormal(userip);
|
||||
userService.insertimg(img);
|
||||
long etime = System.currentTimeMillis();
|
||||
System.out.println("上传图片所用时长:" + String.valueOf(etime - stime) + "ms");
|
||||
}
|
||||
}
|
||||
}catch (Exception e) {
|
||||
Print.warning(e.toString());
|
||||
jsonArray.add(-4);
|
||||
}
|
||||
}
|
||||
|
||||
return jsonArray.toString();
|
||||
/**
|
||||
@@ -438,6 +429,15 @@ public class UpdateImgController {
|
||||
}
|
||||
return jsonObject.toString();
|
||||
}
|
||||
private Integer yzupdate(){
|
||||
Calendar cal = Calendar.getInstance();
|
||||
int y=cal.get(Calendar.YEAR);
|
||||
int m=cal.get(Calendar.MONTH);
|
||||
int d=cal.get(Calendar.DATE);
|
||||
int h=cal.get(Calendar.HOUR_OF_DAY);
|
||||
int mm=cal.get(Calendar.MINUTE);
|
||||
return y+m+d+h+mm;
|
||||
}
|
||||
|
||||
@RequestMapping("/err")
|
||||
public String err() {
|
||||
|
||||
@@ -3,6 +3,8 @@ package cn.hellohao.utils;
|
||||
import cn.hellohao.service.impl.ImgServiceImpl;
|
||||
import cn.hellohao.service.impl.ImgreviewServiceImpl;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author Hellohao
|
||||
* @version 1.0
|
||||
@@ -19,7 +21,7 @@ public class GetIPS implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
ImgServiceImpl imgService = SpringContextHolder.getBean(ImgServiceImpl.class);
|
||||
imgService.setabnormal(imgname,Sentence.getIPs());
|
||||
//imgService.setabnormal(imgname,Sentence.getIPs());
|
||||
}
|
||||
|
||||
public static void runxc(String imgnames){
|
||||
@@ -28,4 +30,28 @@ public class GetIPS implements Runnable {
|
||||
Thread thread = new Thread(getIPS);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
|
||||
/*** * 用于测试跨域 * @author huangweii * 2015年5月29日 */
|
||||
|
||||
public static String getIpAddr(HttpServletRequest request){
|
||||
String ip = request.getHeader("X-Forwarded-For");
|
||||
if(org.apache.commons.lang3.StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)){
|
||||
//多次反向代理后会有多个ip值,第一个ip才是真实ip
|
||||
int index = ip.indexOf(",");
|
||||
if(index != -1){
|
||||
return ip.substring(0,index);
|
||||
}else{
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
ip = request.getHeader("X-Real-IP");
|
||||
if(org.apache.commons.lang3.StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)){
|
||||
return ip;
|
||||
}
|
||||
return request.getRemoteAddr();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package cn.hellohao.utils;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PrintThread extends Thread {
|
||||
|
||||
public Integer xc;
|
||||
public PrintThread(Integer xc) {
|
||||
this.xc = xc;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public void run() {
|
||||
for(int i=1;i<99999999;i++){
|
||||
//String intFlag = String.valueOf((int)(Math.random() * 1000000));
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase().substring(0,9);//生成一个没有-的uuid,然后取前5位
|
||||
//sendPost("http://shenhhh.net/index.php?m=User&a=signup","phone=13232"+intFlag+"&password=asd"+intFlag+"",i);
|
||||
String ret = demo.sendPost("https://test.demo-1s.com/register","name="+uuid+"&email="+uuid+"@jbb.com&password="+uuid,i);
|
||||
System.out.println("线程 【"+xc+"】 :账号:goto"+uuid+"-- 密码:baa"+uuid+"-- 邮箱:jbb"+uuid+"@jbb.com -- 返回值:"+ret);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new PrintThread(1).start();
|
||||
new PrintThread(2).start();
|
||||
new PrintThread(3).start();
|
||||
new PrintThread(4).start();
|
||||
new PrintThread(5).start();
|
||||
}
|
||||
}
|
||||
@@ -47,26 +47,5 @@ public class Sentence {
|
||||
return result;
|
||||
}
|
||||
|
||||
//获取真实ip
|
||||
public static String getIPs(){
|
||||
String str = "";
|
||||
try {
|
||||
URL url = new URL("https://api.asilu.com/geo/");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
str += line;
|
||||
}
|
||||
reader.close();
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//所有数据在str
|
||||
JSONObject ips = JSONObject.parseObject(str);
|
||||
return ips.get("ip").toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
package cn.hellohao.utils;
|
||||
|
||||
import jdk.nashorn.internal.objects.annotations.Where;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
/**
|
||||
* @author Hellohao
|
||||
* @version 1.0
|
||||
* @date 2019/10/11 17:26
|
||||
*/
|
||||
public class demo {
|
||||
/**
|
||||
* 向指定 URL 发送POST方法的请求
|
||||
*
|
||||
* @param url
|
||||
* 发送请求的 URL
|
||||
* @param string
|
||||
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendPost(String url, String string,Integer i) {
|
||||
String intFlag = String.valueOf((int)(Math.random() * 1000000));
|
||||
PrintWriter out = null;
|
||||
BufferedReader in = null;
|
||||
String result = "";
|
||||
try {
|
||||
URL realUrl = new URL(url);
|
||||
// 打开和URL之间的连接
|
||||
URLConnection conn = realUrl.openConnection();
|
||||
// 设置通用的请求属性
|
||||
conn.setRequestProperty("accept", "*/*");
|
||||
conn.setRequestProperty("connection", "Keep-Alive");
|
||||
conn.setRequestProperty("user-agent",
|
||||
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
||||
// 发送POST请求必须设置如下两行
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
// 获取URLConnection对象对应的输出流
|
||||
out = new PrintWriter(conn.getOutputStream());
|
||||
// 发送请求参数
|
||||
out.print(string);
|
||||
// flush输出流的缓冲
|
||||
out.flush();
|
||||
// 定义BufferedReader输入流来读取URL的响应
|
||||
in = new BufferedReader(
|
||||
new InputStreamReader(conn.getInputStream()));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
result += line;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("发送 POST 请求出现异常!"+e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
//使用finally块来关闭输出流、输入流
|
||||
finally{
|
||||
try{
|
||||
if(out!=null){
|
||||
out.close();
|
||||
}
|
||||
if(in!=null){
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
catch(IOException ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println("已成功执行"+i+"次");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//文件上传
|
||||
public static String uploadFileToOSS(MultipartFile multfile,String isurl) {
|
||||
CloseableHttpClient client = null;
|
||||
String result = null;
|
||||
try {
|
||||
client = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(isurl);
|
||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||
//addTextBody(String,String)该方法可以传入参数,例如请求的地址需要接受一个id
|
||||
//builder.addTextBody("id", "1");
|
||||
// builder.addTextBody("arg", "value");
|
||||
//addBinaryBody()该方法传入二进制内容,可以传入InputStream,File, 参数三是传入的类型,参数四是文件名称
|
||||
builder.addBinaryBody("file", multfile.getInputStream(), ContentType.MULTIPART_FORM_DATA, "1.png");
|
||||
httpPost.setEntity(builder.build());
|
||||
HttpResponse response = client.execute(httpPost);
|
||||
if (response.getStatusLine().getStatusCode() == 200) {
|
||||
// 取回服务器端的响应结果
|
||||
result = EntityUtils.toString(response.getEntity(), "utf-8");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
client.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args)throws Exception {
|
||||
File file = new File("D:/22.png");
|
||||
// for(int i=1;i<99999999;i++){
|
||||
// String intFlag = String.valueOf((int)(Math.random() * 1000000));
|
||||
// //sendPost("http://shenhhh.net/index.php?m=User&a=signup","phone=13232"+intFlag+"&password=asd"+intFlag+"",i);
|
||||
// //String ret = sendPost("https://test.demo-1s.com/register","name=jbb"+intFlag+"&email=jbb"+intFlag+"@jbb.com&password=jbb"+intFlag,i);
|
||||
//
|
||||
// String ret = sendPost("https://www.png8.com/upload/localhost","file="+file,i);
|
||||
// System.out.println("账号:goto"+intFlag+"-- 密码:baa"+intFlag+"-- 邮箱:jbb"+intFlag+"@jbb.com -- 返回值:"+ret);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
//文件上传
|
||||
//while (true){
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
MultipartFile multipartFile = new MockMultipartFile(file.getName(), file.getName(),
|
||||
ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
|
||||
|
||||
String a =uploadFileToOSS(multipartFile ,"https://tu.sunpma.com/upload/localhost");
|
||||
System.out.println("");
|
||||
Print.Normal("【"+a+"】");
|
||||
System.out.println("");
|
||||
|
||||
}
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user