手机号工具

master
zhangmeng 2023-03-16 23:50:35 +08:00
parent 0ea72236df
commit 3330e2e05e
2 changed files with 250 additions and 19 deletions

View File

@ -1,13 +1,27 @@
package com.zhangmeng.tools.controller;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author :
* @version : 1.0
@ -20,30 +34,238 @@ public class TelephoneController {
public static final ObservableList<String> list2 = FXCollections.observableArrayList();
public static final ObservableList<String> list3 = FXCollections.observableArrayList();
public static final ObservableList<CheckBox> res_list = FXCollections.observableArrayList();
public static final ObservableList<CheckBox> checkbox_list = FXCollections.observableArrayList();
public static final ObservableList<String> show_list = FXCollections.observableArrayList();
@FXML
public AnchorPane root;
@FXML
public void initialize() {
init();
int i = 100;
for (String t1 : list1) {
public TextArea result_show;
if (i == 1000){
i = 100;
@FXML
public TextField telephone;
@FXML
public Button query;
@FXML
private Button gen;
@FXML
private TextField num;
@FXML
public void initialize() {
num.setText("100");
init();
init_checkbox(148.0, 168.0, list1);
init_checkbox(238.0, 258.0, list2);
init_checkbox(322.0, 342.0, list3);
show_list.addListener((ListChangeListener<String>) c -> {
while (c.next()){
if (c.wasAdded()) {
StringBuilder stringBuilder = new StringBuilder();
for (String s : show_list) {
stringBuilder.append(s);
}
receive(stringBuilder.toString());
}
}
});
gen.setOnAction(actionEvent -> {
show_list.clear();
check_res();
int size = Integer.parseInt(num.getText());
for (int i = 0; i < size; i++) {
CheckBox checkBox = null;
int index;
if (res_list.size() == 0) {
index = RandomUtil.randomInt(0, checkbox_list.size() - 1);
checkBox = checkbox_list.get(index);
} else {
if (res_list.size() == 1 ){
index = 0 ;
}else {
index = RandomUtil.randomInt(0, res_list.size() - 1);
}
checkBox = res_list.get(index);
}
String res = checkBox.getText() + random_8();
show_list.add(res);
show_list.add(System.lineSeparator());
}
});
query.setOnAction(actionEvent -> {
Map<String,Object> map = new HashMap<>();
map.put("phone",telephone.getText().substring(0,7));
String map_res = HttpUtil.post("https://api.uutool.cn/phone/location_batch", map);
R r = JSON.parseObject(map_res, R.class);
R.Data.Rows rows = r.getData().getRows().get(0);
String s = rows.getProvince() + "省 " + rows.city + "市 " + "区域编码:" +rows.area_code + "邮政编码:" + rows.getZip_code();
result_show.setText(s);
});
}
public void receive(String msg) {
Platform.runLater(() -> {
this.result_show.setText(msg);
});
}
public static class R {
private int status;
private Data data;
private String req_id;
public void setStatus(int status){
this.status = status;
}
public int getStatus(){
return this.status;
}
public void setData(Data data){
this.data = data;
}
public Data getData(){
return this.data;
}
public void setReq_id(String req_id){
this.req_id = req_id;
}
public String getReq_id(){
return this.req_id;
}
public static class Data {
private int count;
private List<Rows> rows ;
public void setCount(int count){
this.count = count;
}
public int getCount(){
return this.count;
}
public void setRows(List<Rows> rows){
this.rows = rows;
}
public List<Rows> getRows(){
return this.rows;
}
CheckBox checkBox = new CheckBox(t1);
root.getChildren().add(checkBox);
AnchorPane.setTopAnchor(checkBox,148.0);
AnchorPane.setLeftAnchor(checkBox,1017.0);
AnchorPane.setRightAnchor(checkBox,);
AnchorPane.setRightAnchor(checkBox,);
i += 100;
public static class Rows {
private String phone;
private String isp;
private String province;
private String city;
private String zip_code;
private String area_code;
private String segment;
public void setPhone(String phone){
this.phone = phone;
}
public String getPhone(){
return this.phone;
}
public void setIsp(String isp){
this.isp = isp;
}
public String getIsp(){
return this.isp;
}
public void setProvince(String province){
this.province = province;
}
public String getProvince(){
return this.province;
}
public void setCity(String city){
this.city = city;
}
public String getCity(){
return this.city;
}
public void setZip_code(String zip_code){
this.zip_code = zip_code;
}
public String getZip_code(){
return this.zip_code;
}
public void setArea_code(String area_code){
this.area_code = area_code;
}
public String getArea_code(){
return this.area_code;
}
public void setSegment(String segment){
this.segment = segment;
}
public String getSegment(){
return this.segment;
}
}
}
}
public void init(){
public void check_res() {
res_list.clear();
for (CheckBox checkBox : checkbox_list) {
if (checkBox.isSelected()) {
res_list.add(checkBox);
}
}
}
public void init_checkbox(double one, double two, ObservableList<String> list) {
double i = 100;
double j = 100;
for (String t1 : list) {
CheckBox checkBox = new CheckBox(t1);
root.getChildren().add(checkBox);
if (i <= 1000) {
AnchorPane.setTopAnchor(checkBox, one);
AnchorPane.setLeftAnchor(checkBox, i);
i += 100;
} else {
AnchorPane.setTopAnchor(checkBox, two);
AnchorPane.setLeftAnchor(checkBox, j);
j += 100;
}
checkBox.selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observableValue, Boolean aBoolean, Boolean t1) {
if (t1) {
}
}
});
checkbox_list.add(checkBox);
}
}
public void init() {
list1.add("134");
list1.add("135");
list1.add("136");
@ -91,7 +313,7 @@ public class TelephoneController {
list3.add("199");
}
public String random_8(){
public String random_8() {
int i = RandomUtil.randomInt(10000000, 99999999);
return String.valueOf(i);
}

View File

@ -1,18 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane fx:id="root" fx:controller="com.zhangmeng.tools.controller.TelephoneController" prefHeight="649.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane fx:id="root" prefHeight="649.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.zhangmeng.tools.controller.TelephoneController">
<children>
<Label layoutX="61.0" layoutY="87.0" text="号码生成设置" />
<Separator layoutX="141.0" layoutY="94.0" prefWidth="200.0" AnchorPane.leftAnchor="144.0" AnchorPane.rightAnchor="0.0" />
<Label layoutX="61.0" layoutY="148.0" text="移动:" />
<Label layoutX="61.0" layoutY="241.0" text="联通:" />
<Label layoutX="59.0" layoutY="325.0" text="电信:" />
<CheckBox layoutX="105.0" layoutY="148.0" mnemonicParsing="false" text="CheckBox" AnchorPane.bottomAnchor="484.0" AnchorPane.leftAnchor="105.0" AnchorPane.rightAnchor="1017.0" AnchorPane.topAnchor="148.0" />
<Label layoutX="61.0" layoutY="325.0" text="电信:" />
<TextArea fx:id="result_show" layoutX="97.0" layoutY="401.0" prefHeight="200.0" prefWidth="1056.0" AnchorPane.bottomAnchor="48.0" AnchorPane.leftAnchor="97.0" AnchorPane.rightAnchor="47.0" AnchorPane.topAnchor="401.0" />
<Button fx:id="gen" layoutX="328.0" layoutY="366.0" mnemonicParsing="false" text="生成" />
<Label layoutX="63.0" layoutY="370.0" text="生成个数:" />
<TextField fx:id="num" layoutX="123.0" layoutY="366.0" />
<Label layoutX="59.0" layoutY="401.0" text="结果:" />
<Label layoutX="430.0" layoutY="370.0" text="手机号:" />
<TextField fx:id="telephone" layoutX="486.0" layoutY="366.0" prefHeight="23.0" prefWidth="229.0" />
<Button fx:id="query" layoutX="746.0" layoutY="366.0" mnemonicParsing="false" text="查询" />
</children>
</AnchorPane>