diff --git a/src/main/java/cn/hellohao/TbedApplication.java b/src/main/java/cn/hellohao/TbedApplication.java index 60af641..917c34e 100644 --- a/src/main/java/cn/hellohao/TbedApplication.java +++ b/src/main/java/cn/hellohao/TbedApplication.java @@ -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; diff --git a/src/main/java/cn/hellohao/controller/ClientController.java b/src/main/java/cn/hellohao/controller/ClientController.java index 9339de2..72cfc81 100644 --- a/src/main/java/cn/hellohao/controller/ClientController.java +++ b/src/main/java/cn/hellohao/controller/ClientController.java @@ -56,7 +56,9 @@ public class ClientController { @PostMapping(value = "/clientupimg") @ResponseBody - public ResultBean clientupimg(@RequestParam("file") List file, String email, String pass) throws Exception { + public ResultBean clientupimg(HttpServletRequest request,@RequestParam("file") List 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(); diff --git a/src/main/java/cn/hellohao/controller/UpdateImgController.java b/src/main/java/cn/hellohao/controller/UpdateImgController.java index cb33750..3dbcc71 100644 --- a/src/main/java/cn/hellohao/controller/UpdateImgController.java +++ b/src/main/java/cn/hellohao/controller/UpdateImgController.java @@ -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 map = new HashMap<>(); - map.put(TypeDict.checkType(xxx), request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/"+uuid); - Map 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 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 map = new HashMap<>(); + map.put(TypeDict.checkType(xxx), request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/"+uuid); + Map 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 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 map = new HashMap<>(); - map.put(TypeDict.checkType(xxx), request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/"+uuid); + Map map = new HashMap<>(); + map.put(TypeDict.checkType(xxx), request.getSession().getServletContext().getRealPath("/")+"/hellohaotmp/"+uuid); - Map 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 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 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 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() { diff --git a/src/main/java/cn/hellohao/utils/GetIPS.java b/src/main/java/cn/hellohao/utils/GetIPS.java index e0ac066..8839e4a 100644 --- a/src/main/java/cn/hellohao/utils/GetIPS.java +++ b/src/main/java/cn/hellohao/utils/GetIPS.java @@ -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(); + + } + + } diff --git a/src/main/java/cn/hellohao/utils/PrintThread.java b/src/main/java/cn/hellohao/utils/PrintThread.java new file mode 100644 index 0000000..50d5b4f --- /dev/null +++ b/src/main/java/cn/hellohao/utils/PrintThread.java @@ -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(); + } +} \ No newline at end of file diff --git a/src/main/java/cn/hellohao/utils/Sentence.java b/src/main/java/cn/hellohao/utils/Sentence.java index f67679d..62942cf 100644 --- a/src/main/java/cn/hellohao/utils/Sentence.java +++ b/src/main/java/cn/hellohao/utils/Sentence.java @@ -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(); - } - } diff --git a/src/main/java/cn/hellohao/utils/demo.java b/src/main/java/cn/hellohao/utils/demo.java new file mode 100644 index 0000000..be45d38 --- /dev/null +++ b/src/main/java/cn/hellohao/utils/demo.java @@ -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(""); + + } + + // } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 430b5d7..06f8b92 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,17 +1,17 @@ -#ݿ˺ +#数据库账号 spring.datasource.username=root -#ݿtest +#数据库密码test spring.datasource.password=root -#ݿӵַ +#数据库链接地址 spring.datasource.url=jdbc:mysql://localhost:3306/picturebed?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8 -#˿ +#端口 server.port=8088 -#ڱʽ ·ʽΪÿߵִ -#޸ġԲοٷĵhttp://doc.wwery.com +#鉴黄周期表达式 下方表达式为每天七点半执行 +#不懂请勿乱修改。具体可以参考官方文档http://doc.wwery.com Expression=0 30 04 * * ? -#±ߵҪ޸ġ +#下边的配置项不需要修改。 mybatis.configuration.map-underscore-to-camel-case=true mybatis.mapper-locations=classpath:mapper/*.xml logging.level.cn.hellohao.dao=debug @@ -24,7 +24,7 @@ multipart.maxFileSize=10240KB multipart.maxRequestSize=10240KB spring.thymeleaf.mode = LEGACYHTML5 spring.http.multipart.location=/data/upload_tmp -systemupdate=2019-11-08 +systemupdate=2019-11-18 diff --git a/src/main/resources/static/static/js/login-register.js b/src/main/resources/static/static/js/login-register.js index 8b3eb5b..4aaa5f9 100644 --- a/src/main/resources/static/static/js/login-register.js +++ b/src/main/resources/static/static/js/login-register.js @@ -120,6 +120,9 @@ function pos() { //验证邮箱 function ismail() { + $("#userzc").css('display','none'); + $("#zctishi").css('display','block'); + var registerusername = $("#registerusername").val(); var mail = $("#registeremail").val(); var registerpassword = $("#registerpassword").val(); diff --git a/src/main/resources/static/webuploade/js/upload.js b/src/main/resources/static/webuploade/js/upload.js index 1366b33..a85aa47 100644 --- a/src/main/resources/static/webuploade/js/upload.js +++ b/src/main/resources/static/webuploade/js/upload.js @@ -197,10 +197,7 @@ }); // 文件上传成功 - uploader.on( 'uploadSuccess', function(file,response) { - //alert(response.length); - //console.log(response.imgurls) $("#address").css('display', 'block'); if(response.imgurls==-100){ layui.use('layer', function () { @@ -609,6 +606,7 @@ break; case 'startUpload': + uploader.options.formData.upurlk = GetDateStr(new Date()); setState( 'uploading' ); break; @@ -670,4 +668,13 @@ updateTotalProgress(); }); -})( jQuery ); \ No newline at end of file +})( jQuery ); + +function GetDateStr(dd) { + var a = dd.getFullYear(); + var b = dd.getMonth(); + var c = dd.getDate(); + var d = dd.getHours(); + var e = dd.getMinutes(); + return $.base64.encode((a+b+c+d+e)+""); +} \ No newline at end of file diff --git a/src/main/resources/templates/admin/storageconfig.html b/src/main/resources/templates/admin/storageconfig.html index 25aa5dd..203a224 100644 --- a/src/main/resources/templates/admin/storageconfig.html +++ b/src/main/resources/templates/admin/storageconfig.html @@ -297,7 +297,7 @@ var StorageType = $("#StorageType").val(); if(StorageType==3){Endpoint="0";} else{ - if(StorageType==4){Endpoint = $("#Endpoint2").val();alert(Endpoint);}else{Endpoint = $("#Endpoint").val();} + if(StorageType==4){Endpoint = $("#Endpoint2").val();}else{Endpoint = $("#Endpoint").val();} } if($("#StorageType").val()==5){ $.ajax({ diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index d31ab7b..b01c396 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -6,8 +6,8 @@ - - + + @@ -140,10 +140,10 @@
  • 登录 
  • 注册 
  • -
  • GitHub
  • -
  • 作者
  • + + + + @@ -163,8 +163,8 @@

    立即上传 - - 客户端 + +

    纯粹免费的图片驿站

    @@ -316,8 +316,9 @@
    +
    - +
    @@ -402,7 +403,7 @@ var filesize = [[${filesize}]]; var imgcount = [[${imgcount}]]; var suffix= [[${suffix}]]; - var qq =$.base64.encode([[${updatekey}]]); + var qq ='hellohao-code-yz'; $(document).ready(function () { $(".jb").fadeToggle(); //$("#page-header").fadeToggle("slow"); @@ -479,6 +480,7 @@ }); function zhuce(mail, registerusername, registerpassword) { + //$("#userzc").removeClass("disabled"); if(zcverification){ //验证成功 $.ajax({ @@ -488,6 +490,7 @@ dataType: "json", success: function (data) { if (data.ret > 0) { + $("#zctishi").text('注册成功'); if (data.zctype == 1) { layui.use('layer', function(){ var layer = layui.layer; @@ -995,6 +998,7 @@ function setday() { } }); } +