编程语言
首页 > 编程语言> > java短信群发项目:

java短信群发项目:

作者:互联网

编写一个项目,
1. 以下手机号码段(每隔一个号添加一次),添加到Map集合当中
2. 从控制台输入要发送信息的短信号码,如果要发送多个,请用英文逗号隔开,输入短信内容
3. 编写一个短信发送类,号码发送前,先判断号码是否为空,再判断是否为红名单用户(手机号码在集合中),如果为红名 单,输出红名单数据,并计算红名单校验耗费的时间,如果条件都满足,发送短信,短信发送成功的概率为98%, 最后 展示发送成功的短信号码和内容
备注:红名单和普通名单可以同时提交发送,但是红名单的不能发送不会影响到普通名单号码的正常发送
展示的结果:是红名单输出红名单数据和耗费的时间
不是红名单输出普通用户的号码和短信的内容。
手机号码段:
头三位   中间四位    末尾四位
136      0371       0000-9999
      0766
      7335
      7362
      6385
      0769
      7494
      3381
      7496
      7370

137      3383
      3319
      0088
      8361
      3315
      8168
      8151
      0386
181     3788
      3789
      3782
      3787
      0349
      3567
      2234
      0382

180      3951
      0169
      3991
      3955
      3928
      3788
      0387
      3997
      3923

150     0381
      3719
      0371
      3816
      0389
      3681
      0389
      9326
      3837
      3802

public class Phone {
    //              下标      电话
    static HashMap<Integer, String> hm = new HashMap<>();

    public Phone() {
        //第一批
        String[] middle1 = {"0371", "0766", "7335", "7362", "6385", "0769", "7494", "3381", "7496", "7370"};
        //尾数
        ArrayList<String> end = new ArrayList<>();
        for (int i = 0; i <= 9999; i++) {
            int q = i / 1000;
            int b = i % 1000 / 100;
            int s = i % 1000 % 100 / 10;
            if (q == 0 && b == 0 && s == 0) {
                String temp = "000";
                temp += i;
                end.add(temp);
            } else if (q == 0 && b == 0) {
                String temp = "00";
                temp += i;
                end.add(temp);
            } else if (q == 0) {
                String temp = "0";
                temp += i;
                end.add(temp);
            } else {
                end.add(i + "");
            }
        }
        //下标
        int index = 0;
        for (String s : end) {
            for (String i : middle1) {
                String temp = 136 + i + s;
                hm.put(index, temp);
                index++;
            }
        }
        //System.out.println("middle1=" + index);

        String[] middle2 = {"3383", "3319", "0088", "8361", "3315", "8168", "8151", "0386"};
        for (String s : end) {
            for (String i : middle2) {
                hm.put(index, 137 + i + s);
                index++;
            }
        }
        //System.out.println("middle2=" + index);

        String[] middle3 = {" 3788" + "3789" + "3782" + " 3787" + "0349" + "3567" + "2234" + " 0382"};
        for (String s : end) {
            for (String i : middle3) {
                String temp = 181 + i + s;
                hm.put(index, temp);
                index++;
            }
        }
        //System.out.println("middle3=" + index);

        String[] middle4 = {"3951", "0169", " 3991", " 3955", "3928", "3788", "0387", "3997", "3923"};
        for (String s : end) {
            for (String i : middle4) {
                String temp = 180 + i + s;
                hm.put(index, temp);
                index++;
            }
        }
        //System.out.println("middle4=" + index);

        String[] middle5 = {"0381", "3719", "0371", "3816", "0389", "3681", "0389", "9326", "3837", "3802"};
        for (String s : end) {
            for (String i : middle5) {
                String temp = 150 + i + s;
                hm.put(index, temp);
                index++;
            }
        }
        System.out.println("middle5=" + index);
        System.out.println(end.size());
    }

    //是否有红名单手机号如果有就删除并打印
    public void isRedphone(ArrayList<String> p) {
        boolean is =false ;
        long star = System.currentTimeMillis();
        Set<Integer> key = hm.keySet();
        for (Integer i : key) {
            String s = hm.get(i);
            for (int k = 0; k < p.size(); k++) {
                if (s.equals(p.get(k))) {
                    System.out.println("找到红名单手机号=" + s);
                    p.remove(k);
                is=true;
                }
            }
        }
        long end = System.currentTimeMillis();
        if (is){
        System.out.println("一共耗时"+(end-star)+"毫秒!");
        }
    }

    //查看手机名单
    public void show(ArrayList<String> p) {
        for (String s : p) {
            System.out.print(s + "\t");
        }
        System.out.println();
    }

}
public class Massage {
    private ArrayList<String> p;
    private String massage;

    public Massage() {
    }

    public Massage(ArrayList<String> p, String massage) {
        this.p = p;
        this.massage = massage;
    }

    public ArrayList<String> getP() {
        return p;
    }

    public void setP(ArrayList<String> p) {
        this.p = p;
    }

    public String getMassage() {
        return massage;
    }

    public void setMassage(String massage) {
        this.massage = massage;
    }

    //发送信息
    public void send() {
        for (int i = 0; i < p.size(); i++) {
            double is = Math.random() * 1;
            //System.out.println(is);
            if (is < (1 - 0.98)) {
                System.out.println("电话:" + p.get(i) + "发送成功");
            } else {
                System.out.println("电话:" + p.get(i) + "发送成功");
            }
        }
        System.out.println("短信内容为:" + massage);
    }
}
public class Text {
    public static void main(String[] args) {
        Massage ma = new Massage();
        Phone p = new Phone();
        ArrayList<String> ph = new ArrayList<>();
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入要发送的手机号多个用逗号分割");
        //13603719999,15003714562,18438860920
        String phones = sc.nextLine();
        //分割
        String[] split = phones.split(",");
        for (String s : split) {
            //用集合操控容易
            ph.add(s);
        }
        //查看是否有红名单调用方法
        p.isRedphone(ph);
        System.out.println("查看:");
        p.show(ph);//查看一下
        ma.setP(ph);//传入手机号
        System.out.println("请输入短信内容:");
        String massage = sc.nextLine();
        ma.setMassage(massage);
        //发送
        ma.send();

    }
}

 

标签:java,String,项目,信群发,System,println,public,massage,out
来源: https://www.cnblogs.com/zk2020/p/14090566.html