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

📄 smsclient.java

📁 用java写编写的一个GPS源代码请大家多多指教
💻 JAVA
字号:
package com.gps.center.parsedata;import java.lang.*;import java.net.Socket;import java.io.*;import java.lang.String;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;/* 短信客户端 */public class SMSClient {    private Socket ClientSocket; //客户端引socket用    private DataInputStream is;    private DataOutputStream os;    public String Error;    public String Option;    public String Record;    public String Mobile;    public String Content;    public String DateTime;    //初始化变量    public SMSClient() {        Error = "";        Option = "";        Record = "";        Mobile = "";        Content = "";        DateTime = "";    }    public boolean OpenSMS(String mServer, int mPort) {        String mBuffer = ""; //接收读取的字符串        boolean mResult = false;        try {            if (mServer.equals("")) {                mServer = "localhost";            }            if (mPort == 0) {                mPort = 8090;            }            //创建ClientSocket连接            try {                System.out.println("短信Socket初始化完成");                ClientSocket = new Socket(mServer, mPort);                is = new DataInputStream(new BufferedInputStream(ClientSocket.                        getInputStream()));                os = new DataOutputStream(new BufferedOutputStream(ClientSocket.                        getOutputStream()));                //读取输入流中数据                mBuffer = is.readLine();            } catch (Exception e) {                System.out.print("没开短信猫" + e);                e.printStackTrace();            }            if (mBuffer.equalsIgnoreCase("ok")) { //equalsIgnoreCase()忽略大小写与equals()用法相同                os.write(("SMS\r\n").getBytes()); //写入标志                mResult = true;            }            System.out.println(mBuffer.toString());        } catch (Exception e) {            System.out.print(e.toString());            e.printStackTrace();            mResult = false;        }        return (mResult);    }    //发送短信消息    public boolean SendSMS(String mRecord, String mMobile, String mContent) {        boolean mResult = false;        byte[] bRecord;        byte[] bMobile;        byte[] bContent;        byte[] bFlag;        try {            //赋值到数组            System.out.println(mMobile+"电话号码");            bRecord = (mRecord + "\r\n").getBytes();            bMobile = (mMobile + "\r\n").getBytes();            bContent = (mContent + "\r\n").getBytes();            bFlag = new byte[3];            //标志            bFlag[0] = 0x1A;            bFlag[1] = '\r';            bFlag[2] = '\n';            //写出到下面的流里            os.write(bFlag);            os.write(bRecord);            os.write(bMobile);            os.write(bContent);            os.write(bFlag);            os.flush();            /*System.out.println(bFlag);            System.out.println(bRecord);            System.out.println(bMobile+"电话号码");            System.out.println(bContent);            System.out.println(bFlag);*/            Error = is.readLine();            if (Error.equalsIgnoreCase("OK")) {                mResult = true;            } else {                mResult = false;            }        } catch (Exception e) {            mResult = false;        }        return (mResult);    }    //读取短信    public String ReadSMS() {        String mResult = "";        //GB18030-GB18030-Simplified Chinese,PRC standard        byte[] bFlag;        try {            bFlag = new byte[3];            bFlag[0] = 0x1B;            bFlag[1] = '\r';            bFlag[2] = '\n';            os.write(bFlag);            os.flush();            mResult = is.readLine();            Option = is.readLine();            Record = is.readLine();            Mobile = is.readLine();            Content = is.readLine();            DateTime = is.readLine();            Error = is.readLine();            if (Error.equalsIgnoreCase("OK")) {                mResult = mResult;            } else {                mResult = "0";            }        } catch (Exception e) {            mResult = "0";        }        return (mResult);    }    //关闭socket    public boolean CloseSMS() {        boolean mResult = false;        try {            os.write(("END\r\n").getBytes()); //结束标志            ClientSocket.close();            mResult = true;            System.out.println("短信Socket已经关闭");        } catch (Exception e) {            mResult = false;        }        return (mResult);    }}

⌨️ 快捷键说明

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