⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 receivesms.java

📁 使用java实现的计算机自主发短信到手机。 运行界面上
💻 JAVA
字号:
package keti2;

import java.io.*;
import java.lang.Integer;
import javax.comm.*;
import java.util.*;
import java.util.StringTokenizer;

public class ReceiveSMS
    extends ATcommand {
  protected String sms;
  protected String test;
  protected static String s1;
  protected String Phnum;
  protected String chinesesms;
  public ReceiveSMS() throws IOException, NoSuchPortException,
      PortInUseException,
      UnsupportedCommOperationException {
  }

  public String reiceive(int geshu) throws IOException {
    sms = ReadSMS(geshu);
    Phnum = phonenumber(sms, geshu);
    System.out.print(sms);
    /*%%%%%%下面是一次只读一条时,用转换成汉字的程序部分%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
    StringTokenizer stringtokenizer = new StringTokenizer(sms);

    int i = stringtokenizer.countTokens();

    int j = 3;

    String s4 = new String();
    String s5 = new String();
    String s2 = new String();
    s2 = stringtokenizer.nextToken();
    s2 = stringtokenizer.nextToken();
    s2 = stringtokenizer.nextToken();
    char[] cbuffer;
    if (i == 10) {
      while (stringtokenizer.hasMoreTokens()) {

        if (j != i - 2 && j < i) {
          s2 = stringtokenizer.nextToken();
        }
        else if (j == i - 2) {
          s4 = stringtokenizer.nextToken().trim();
          char first;
          first = s4.charAt(0);
          if (Character.isDigit(first)) {
            int k = s4.length() / 4 + 1;
            int k2 = 1;
            int k3 = 0;
            cbuffer = new char[k];
            int k1 = 1;
            while (k2 < k) {
              cbuffer[k1] = (char) Integer.parseInt(s4.substring(k3, k3 + 4),
                  16);
              k3 = k3 + 4;
              k2++;
              k1++;
            }
            s4 = new String(cbuffer);
            s4 = s4.trim();
          }

          s1 = s1 + s4;

        }
        else {
          s2 = stringtokenizer.nextToken();
        }
        s1 = s1 + s2;
        j++;

        System.out.print("\n");

      } //endwhile

    } //end if
    else {
      while (stringtokenizer.hasMoreTokens()) {
        if (j < 3) {
          if (j != i - 2 && j < i) {
            s2 = stringtokenizer.nextToken();
          }

        } //endif(j<3)
        else if ( (j >= 3) && (j <= i - 2)) {
          s4 = stringtokenizer.nextToken();
          s5 = s5 + s4;
        } //endelse if((j>=3)&&(j<=i-2))
        else {
          s2 = stringtokenizer.nextToken();
        } //end else
        s1 = s1 + s2;
        j++;
        s4 = s5;
      } //endwhile
    } //endelse
    /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
    System.out.print("\n");
    System.out.print(Phnum);
    chinesesms = s4;
    return chinesesms;

  } //end reiceive()

  public String phonenumber(String text, int u) { //这是一次只读入一条时的取得号码的方法
    String num = new String();
    StringTokenizer stringtokenizer1 = new StringTokenizer(text);

    int i = stringtokenizer1.countTokens();
    String s7 = new String();
    s7 = stringtokenizer1.nextToken();
    s7 = stringtokenizer1.nextToken();
    s7 = stringtokenizer1.nextToken();
    s7 = stringtokenizer1.nextToken();
    s7 = stringtokenizer1.nextToken();
    s7 = stringtokenizer1.nextToken();
    s7 = stringtokenizer1.nextToken();
    s7 = stringtokenizer1.nextToken();
    s7 = s7.substring(10, 21);

    num = s7;

    return num;
  }

  public String CnEnCode(String text, int num) { //这是一次读如多条时的汉字处理方法

    if (num < 10) {
      text = text.substring(54);
    }
    else {
      text = text.substring(55);
    }
    int l = (text.length() / 4) + 1;
    int k1 = 1;
    int k2 = 1;
    int k3 = 0;
    char[] cbuffer = new char[l + 1];
    // System.out.print(text);

    while (k2 < l) {
      cbuffer[k1] = (char) Integer.parseInt(text.substring(k3, k3 + 4), 16);
      k3 = k3 + 4;
      k2++;
      k1++;
    }
    cbuffer[l] = '\0';
    String cn = new String(cbuffer);
    cn = cn.trim();
    String chinese = cn;
    return chinese;
  }

  public String getphonenum(String text, int num) {
    String phone = new String();
    if (num < 10) {
      phone = text.substring(18, 29);
    }
    else {
      phone = text.substring(19, 30);
    }
    return phone;
  }

  public String getcnpdu(String text, int index) {
    String chinesepdu = new String();
    System.out.print("\n");
    System.out.print(text.length());
    if (index < 10) {
      chinesepdu = text.substring(65);
    }
    else {
      chinesepdu = text.substring(66);
    }

    int l = chinesepdu.length() / 4 + 1;
    int k2 = 1;
    int k3 = 0;
    char[] cbuffer = new char[l + 1];

    int k1 = 1;
    while (k2 < l) {
      cbuffer[k1] = (char) Integer.parseInt(chinesepdu.substring(k3, k3 + 4),
                                            16);

      // System.out.print(cbuffer[k1]);

      k3 = k3 + 4;
      k2++;
      k1++;

    }

    chinesepdu = new String(cbuffer);
    chinesepdu = chinesepdu.trim();
    System.out.print("\n");
    System.out.print(chinesepdu);

    return chinesepdu;

  }

  String getpduindex(String text) {
    String pduindex = new String();
    if (text.substring(1, 2).equals(","))

      //pduindex=Integer.parseInt(text.substring(1,2),10);
      pduindex = text.substring(0, 1);
    else if (!text.substring(1, 2).equals(","))

      //pduindex=Integer.parseInt(text.substring(1,3),10);
      pduindex = text.substring(0, 2);
    return pduindex;

  }

  String getenglish7pdu(String text, int index) {

    int nSrc = 1;
    int nDst = 0;
    int nByte = 1;
    int j = 1;

    int l = 0;
    int k = 3;
    String englishpdu = new String();
    if (index < 10) {
      englishpdu = text.substring(65);
    }
    else {
      englishpdu = text.substring(66);
    }
    int nSrcLength = englishpdu.length() / 2;
    int max = nSrcLength + (nSrcLength / 7);

    String textleft = new String("");
    String textright = new String();
    String[] textall = new String[max + 1];
    String[] sbuffer = new String[nSrcLength + 1];
    char[] cbuffer = new char[max + 1];

    System.out.print(englishpdu);
    for (int i = 0; i < nSrcLength - 1; i++) {
      sbuffer[i +
          1] = Integer.toBinaryString(Integer.parseInt(englishpdu.
          substring(l, l + 2), 16));
      l = l + 2;

      //System.out.print("\n"+sbuffer[i+1]);
    }

    sbuffer[nSrcLength] = Integer.toBinaryString(Integer.parseInt(englishpdu.
        substring(l), 16));

    for (int i = 1; i <= nSrcLength; i++) {
      if (sbuffer[i].length() < 8) {
        while (sbuffer[i].length() < 8) {
          sbuffer[i] = "0" + sbuffer[i];
        }
      }

    }
    System.out.print("\n end");
    while (nSrc <= nSrcLength) {
      textright = sbuffer[nSrc].substring(nByte);

      textall[j] = textright + textleft;

      j++;
      textleft = sbuffer[nSrc].substring(0, nByte);
      if (nByte == 7) {
        textall[j] = textleft;
        textleft = "";
        j++;
        nByte = 0;
      }
      nByte++;
      nSrc++;
    } //endwhile
    for (int i = 1; i <= max; i++) {
      textall[i] = Integer.toHexString(Integer.parseInt(textall[i], 2));
      textall[i] = "00" + textall[i];
    }
    for (int i = 1; i <= max; i++) {
      cbuffer[i] = (char) Integer.parseInt(textall[i], 16);

    }

    String epdu = new String(cbuffer);
    epdu = epdu.trim();
    System.out.print("\n" + epdu);
    return epdu;
  }

  String getpduphone(String text, int index) {

    String pduphone = new String();
    String newphone = new String();
    if (index < 10) pduphone = text.substring(31, 45);
    else pduphone = text.substring(32, 46);
    newphone = pduphone.substring(3, 4) + pduphone.substring(2, 3) +
        pduphone.substring(5, 6) + pduphone.substring(4, 5) +
        pduphone.substring(7, 8) + pduphone.substring(6, 7) +
        pduphone.substring(9, 10) + pduphone.substring(8, 9) +
        pduphone.substring(11, 12) + pduphone.substring(10, 11) +
        pduphone.substring(13, 14);
    //System.out.print(newphone);
    return newphone;
  }

  String fenxipdu(String text, int index) {
    String pdustructure = new String();
    String schar = new String();
    if (index < 10)
      schar = text.substring(47, 49);
    else
      schar = text.substring(48, 50);
    if (schar.equals("00"))
      pdustructure = "en";
    else if (schar.equals("08"))
      pdustructure = "cn";
    return pdustructure;
  }

} //end class()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -