对垃圾短信sayNO!我教你实现,网络手机号码接收验证码!

对垃圾短信sayNO!我教你实现,网络手机号码接收验证码!_第1张图片
  Hello,大家好,我是fntp,本期更新博客,为大家带来最新一期的鑫软教程,带大家一起来学习!现阶段,我们面临着数据信息隐私泄露的风险,怎么各种网络应用服务在我们注册完账号后,不断地给我们发送垃圾信息,那如何避免每天收到这么多垃圾信息,避开信息隐私泄露?我们可以使用Java实现短信接码工具奥!基于网络号码实现接收网络短信,多人共用,解决一时之需!
  首先还是老规矩,我们先来看效果实现的怎么样:

工具软件截图如下所示:
对垃圾短信sayNO!我教你实现,网络手机号码接收验证码!_第2张图片
对垃圾短信sayNO!我教你实现,网络手机号码接收验证码!_第3张图片
实现原理如下:

  1. 使用Jsoup(Java网络爬虫)爬出HTML
  2. 使用字符串解析工具剔除无用字符,取出有效数据
  3. 使用Java的Table实现数据表格展示
  4. 使用Java的GUI进行窗口化程序,显得更加美观

好啦,来看一下核心代码实现吧:

package com.sinsy.fntp.utils;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class Utils {
     
	
	
//	 ==========基础方法
    public  Document getDocument (String url){
     
        try {
     
            return Jsoup.connect(url).timeout(5000).get();
        } catch (IOException e) {
     
            e.printStackTrace();
        }
        return null;
    }
    
    
    
//    ==========拿到号码数组
			    public String[] getPhoneNumbers(){
     
			      Document doc = new Utils().getDocument("http://www.z-sms.com/");
			      // 获取目标HTML代码
			      Elements thefirstElement = doc.select("[class=col-md-4]");
			//      拿到目前的所有号码的个数
			      int count = thefirstElement.size();
			      int number = 1;
			      //count就是总的数量,也就可以作为这个数组的总的容量
			      String phoneNumber[] = new String[count];
			      String phoneQuhao[] = new String[count];
			      for(int i = 0;i<count;i++) {
     
			     	 Elements elements2 = thefirstElement.select("[class=course]");
			     	 String phonenumberZong= elements2.select("[class=number]").get(i).text().replace("复制", ",").replace(" ", ",").replace("+","-");
			//     	 拿到区号
			     	 String qh =new Utils().SplitTheJson(phonenumberZong);
			//     	 拿到号码段
			     	 String phonenumber =new Utils().SplitTheJson2(phonenumberZong);
			
			//     	 System.out.println(phonenumberZong);
//			     	 System.out.println(" 号码为: [ "+number+" ]   "+"区号:"+qh+"号码:"+phonenumber);
			     	phoneNumber[i] = phonenumber;
			     	phoneQuhao[i]= qh;
			     	 number++;
			      }
			//      System.out.println(count);
				return phoneNumber;
			      }
    
    
				//    =====================获得区号数组
				    public String[] getQuhao(){
     
				        Document doc = new Utils().getDocument("http://www.z-sms.com/");
				        // 获取目标HTML代码
				        Elements thefirstElement = doc.select("[class=col-md-4]");
				//        拿到目前的所有号码的个数
				        int count = thefirstElement.size();
				        int number = 1;
				        //count就是总的数量,也就可以作为这个数组的总的容量
				        String phoneQuhao[] = new String[count];
				        for(int i = 0;i<count;i++) {
     
				       	 Elements elements2 = thefirstElement.select("[class=course]");
				       	 String phonenumberZong= elements2.select("[class=number]").get(i).text().replace("复制", ",").replace(" ", ",").replace("+","-");
				//       	 拿到区号
				       	 String qh =new Utils().SplitTheJson(phonenumberZong);
				//       	 System.out.println(phonenumberZong);
//				       	 System.out.println(" 号码为: [ "+number+" ]   "+"区号:"+qh);
				       	phoneQuhao[i]= qh;
				       	 number++;
				        }
				//        System.out.println(count);
				  	return phoneQuhao;
				        }

				    
//				    刷新时间数组
				    public String[] getRefreshTime(){
     
				        Document doc = new Utils().getDocument("http://www.z-sms.com/");
				        // 获取目标HTML代码
				        Elements thefirstElement = doc.select("[class=col-md-4]");
				//        拿到目前的所有号码的个数
				        int count = thefirstElement.size();
				        int number = 1;
				        //count就是总的数量,也就可以作为这个数组的总的容量	
				        String RefreshTime[] = new String[count];
				        Elements elements2 = thefirstElement.select("[class=course]");
				        for(int i = 0;i<count;i++) {
     
							       	 String phonenumberZong= elements2.get(i).text().replace(" ", ",");
							       	 phonenumberZong= new Utils().SplitTheJson1(phonenumberZong);
//									System.out.println(" 号码为: [ "+number+" ]   "+"刷新时间:"+phonenumberZong);
									RefreshTime[i]= phonenumberZong;
										       	 number++;
				        }
				//        System.out.println(count);
				  	return RefreshTime;
				        }

				    
//				    字符串匹配算法
	public String SplitTheJson(String str) {
     
		String regex = "-(.*?),";
		String param ="";
		Pattern pattern = Pattern.compile(regex);
		Matcher m = pattern.matcher(str);
		while (m.find()) {
       
            int i = 1;  
            param+=m.group(i);
            i++;  
        } 
		return param;
	}
	public String SplitTheJson2(String str) {
     
		String regex = ",(.*?),";
		String param ="";
		Pattern pattern = Pattern.compile(regex);
		Matcher m = pattern.matcher(str);
		while (m.find()) {
       
            int i = 1;  
            param+=m.group(i);
            i++;  
        } 
		return param;
	}
	public String SplitTheJson1(String str) {
     
		String regex = "复制,(.*?),";
		String param ="";
		Pattern pattern = Pattern.compile(regex);
		Matcher m = pattern.matcher(str);
		while (m.find()) {
       
            int i = 1;  
            param+=m.group(i);
            i++;  
        } 
		return param;
	}
	
	
//	拿到短信内容的代码:http://www.z-sms.com/lv.php?pho_num=17194242613&1
	  public String GetContent(String str){
     
	        Document doc = new Utils().getDocument("http://www.z-sms.com/lv.php?pho_num="+str+"&1");
	        // 获取目标HTML代码
	        Elements thefirstElement = doc.select("[class=conters]");
	//        拿到目前的所有号码的个数
	        //count就是总的数量,也就可以作为这个数组的总的容量	
	        Elements elements2 = thefirstElement.select("span");
//	        String imgpath = elements2.select("img[src]").get(0).toString().replace("\"(更多号码", "");

			String yzm= elements2.get(0).text();
//			System.out.println(yzm+"img地址:"+imgpath);
	  	return yzm;
	        }
	  public String GetImagePath(String str){
     
	        Document doc = new Utils().getDocument("http://www.z-sms.com/lv.php?pho_num="+str+"&1");
	        // 获取目标HTML代码
	        Elements thefirstElement = doc.select("[class=conters]");
	//        拿到目前的所有号码的个数
	        //count就是总的数量,也就可以作为这个数组的总的容量	
	        Elements elements2 = thefirstElement.select("span");
	        String imgpath = elements2.select("img[src]").get(0).toString().replace("\"(更多号码, "").replace("\">", "");
	        return imgpath;
	  }
//	     	//这是最近刷新时间的开始
//	 Elements quhao = thefirstElement.select("[class=col-md-4]");
//	 String refresh = quhao.select("p").get(1).text();
	 //最近刷新时间的结束
    public static void main(String[] args) {
     
	for (int i = 0; i <5; i++) {
     
//		System.out.println(new Utils().GetContent(new Utils().getPhoneNumbers()[i]));
	}
	}
}

获得时间的核心代码:

package com.sinsy.fntp.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class GetCurrentDate {
     
public static void main(String[] args) {
     
	System.out.println(new GetCurrentDate().GetDate());
	
}
 public String GetDate() {
     
	 Date date = new Date(); 
	 SimpleDateFormat simple = new SimpleDateFormat("yyyy年MM月dd日hh时mm分ss秒");
//	 System.out.println(simple.format(date));  
	 return simple.format(date);
 }
}

最后窗口化的程序实现代码:

package com.sinsy.fntp.mian;

import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Composite;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.ImageIcon;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Label;
import org.eclipse.wb.swt.SWTResourceManager;

import com.sinsy.fntp.utils.GetCurrentDate;
import com.sinsy.fntp.utils.Utils;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

public class Mainwindows {
     

	protected Shell shlv;
	private Table table;
	private GetCurrentDate date = new GetCurrentDate();
	private Utils utils= new Utils();
	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args) {
     
		try {
     
			Mainwindows window = new Mainwindows();
			window.open();
		} catch (Exception e) {
     
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
     
		Display display = Display.getDefault();
		createContents();
		shlv.open();
		shlv.layout();
		while (!shlv.isDisposed()) {
     
			if (!display.readAndDispatch()) {
     
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
     
		Display display = Display.getDefault();
		shlv = new Shell(display,SWT.MIN);
		shlv.setSize(830, 608);
		shlv.setText("\u946B\u8F6F\u624B\u673A\u9A8C\u8BC1\u7801\u4EE3\u6536\u5DE5\u5177V1.0");
		Composite composite_2 = new Composite(shlv, SWT.BORDER);
		composite_2.setBounds(10, 137, 599, 414);
		
//		JavaSWT嵌入Table表单事件
		table = new Table(composite_2, SWT.BORDER | SWT.FULL_SELECTION);
		table.addSelectionListener(new SelectionAdapter() {
     
			@Override
			public void widgetSelected(SelectionEvent e) {
     
					String url = table.getItem(table.getSelectionIndex()).getText(6);
					new showcode().openwindow(url);
			}
		});
		table.setBounds(0, 0, 595, 410);
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
		String tableHeader[]= new String[] {
     "时间","区号","手机号码","上次刷新","来源"};
		for (int i=0;i<tableHeader.length;i++){
     
			TableColumn tableColumn = new TableColumn(table, SWT.CENTER);
			tableColumn.setText( tableHeader[i]);
			//设置表头可移动,默认为false
			tableColumn.setMoveable(true);
			tableColumn.setWidth(196);
			}
			TableColumn tableColumn = new TableColumn(table, SWT.CENTER);
			tableColumn.setText("短信内容(默认字符串验证码)");
			tableColumn.setMoveable(true);
			tableColumn.setWidth(396);
			TableColumn tableColumn1 = new TableColumn(table, SWT.CENTER);
			tableColumn1.setText("图片验证码");
			tableColumn1.setMoveable(true);
			tableColumn1.setWidth(396);
			
			 Date date = new Date(); 
			 SimpleDateFormat simple = new SimpleDateFormat("yyyy年MM月dd日hh时mm分ss秒");
//			 System.out.println(simple.format(date));  
			String qh[]=utils.getQuhao();
			String pn[]=utils.getPhoneNumbers();
			String tm[]=utils.getRefreshTime();
			
			 for (int i = 0; i < 24; i++) {
     
		            TableItem item = new TableItem(table, SWT.NONE);
		            item.setText(new String[] {
     simple.format(date),qh[i],pn[i], tm[i] ,"SINSY",utils.GetContent(pn[i]),utils.GetImagePath(pn[i])});
		            
		        }
			
		Composite composite = new Composite(shlv, SWT.BORDER);
		composite.setBounds(10, 10, 792, 121);
		
		Label lblNewLabel_2 = new Label(composite, SWT.NONE);
		lblNewLabel_2.setImage(SWTResourceManager.getImage(Mainwindows.class, "/img/1.png"));
		lblNewLabel_2.setBounds(0, 0, 788, 117);
		
		Composite composite_3 = new Composite(shlv, SWT.BORDER);
		composite_3.setBounds(615, 137, 187, 58);
		
		Button button = new Button(composite_3, SWT.NONE);
		button.addSelectionListener(new SelectionAdapter() {
     
			@Override
			public void widgetSelected(SelectionEvent e) {
     
				 Date date = new Date(); 
				 SimpleDateFormat simple = new SimpleDateFormat("yyyy年MM月dd日hh时mm分ss秒");
//				 System.out.println(simple.format(date));  
				String qh[]=utils.getQuhao();
				String pn[]=utils.getPhoneNumbers();
				String tm[]=utils.getRefreshTime();
				
				 for (int i = 0; i < 24; i++) {
     
			            TableItem item = new TableItem(table, SWT.NONE);
			            item.setText(new String[] {
     simple.format(date),qh[i],pn[i], tm[i] ,"SINSY",utils.GetContent(pn[i]),utils.GetImagePath(pn[i])});
			            
			        }
				
			}
		});
		
		button.setBounds(58, 10, 72, 34);
		button.setText("\u5168\u5C40\u5237\u65B0");
		
		Composite composite_1 = new Composite(shlv, SWT.BORDER);
		composite_1.setBounds(615, 201, 187, 350);
		
		Label lblNewLabel = new Label(composite_1, SWT.NONE);
		lblNewLabel.setImage(SWTResourceManager.getImage(Mainwindows.class, "/img/0.png"));
		lblNewLabel.setBounds(0, 0, 183, 182);
		
		Label lblNewLabel_1 = new Label(composite_1, SWT.WRAP | SWT.CENTER);
		lblNewLabel_1.setBounds(0, 188, 183, 158);
		lblNewLabel_1.setText("SINSY\u624B\u673A\u63A5\u7801\u5DE5\u5177\uFF0C\u4E00\u952E\u6446\u8131\u5783\u573E\u77ED\u4FE1\u7684\u675F\u7F1A\uFF0C\u5229\u7528\u7F51\u7EDC\u624B\u673A\u53F7\u7801\u63A5\u53D7\u9A8C\u8BC1\u77ED\u4FE1\uFF0C\u4ECE\u6B64\u6CE8\u518C\u4E0D\u518D\u662F\u95EE\u9898\uFF01\u7528\u4ED6\u7684\u53F7\u7801\uFF0C\u8D70\u81EA\u5DF1\u7684\u8DEF\uFF01\u8BA9\u4ED6\u4EEC\u8FFD\u53BB\u5427\uFF01\u54C8\u54C8\u54C8\u54C8\uFF0C\u946B\u8F6F\u5B98\u7F51\uFF1Awww.sinsy.club");
	}

}

至此,本项目的所有资源代码已经全部展示出来了,源代码下载地址:
点击此处下载源代码
或者扫描二维码下载:
对垃圾短信sayNO!我教你实现,网络手机号码接收验证码!_第4张图片
兄弟姐妹们,如果您觉得本文对您学习Java有帮助,请您点个赞,加个关注吧!您的肯定与支持是博主坚持原创作品写下去的动力!感谢您的支持!我会持续更新!
对垃圾短信sayNO!我教你实现,网络手机号码接收验证码!_第5张图片

你可能感兴趣的:(java程序开发,鑫软工具,java,短信验证码,网络短信接收)