1

我正在使用 gammu 发送短信,我想知道是否可以使用两台或多台带有 java 应用程序的计算机同时发送消息。我尝试了 10 次,并且 10 次中有 1 次从两台计算机成功发送了消息。9次只有一台计算机可以发送短信而另一台无法发送。是否有某种设置或命令,以便我可以同时从这两台计算机发送消息?对于配置,我使用 Gammu 的默认配置

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;

public class TestingSms {



public static void main(String[] args) {
        // TODO Auto-generated method stub
        String host = "MY GAMMU IP";
        String user = "MY USERNAME";
        String password = "MY PASSWORD";
        int port = 22;
        String sms ="haloo";

        JSch jsch = new JSch();
        try {
            Session session = jsch.getSession(user, host, port);
            session.setPassword(password);
            session.setConfig("StrictHostKeyChecking", "no");
            session.connect();

            ChannelExec exec = (ChannelExec) session.openChannel("exec");
            exec.setCommand("gammu sendsms TEXT 08xxxxxxxxxx -text \""+sms+"\"");
            exec.setErrStream(System.err);

            exec.connect();

            BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream()));
            String temp;
            while((temp=reader.readLine())!=null) {
                System.out.println(temp);
            }
            exec.disconnect();
            session.disconnect();

            System.out.println("\n\nFinish");
        } catch (JSchException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

失败消息:

Warning: No configuration read, using builtin defaults!
No response in specified timeout. Probably phone not connected.

先感谢您

4

1 回答 1

1

也许您更愿意为此使用Gammu SMSD - 它在服务器上运行并从/向数据库发送/接收消息。这样,您只需将消息插入数据库即可轻松地从其他主机发送消息。

该错误Warning: No configuration read, using builtin defaults!表明 Gammu 没有找到配置文件,也许您正在以其他用户身份运行它?或者尝试使用--config 参数指定配置文件的路径。

于 2017-11-17T13:17:08.280 回答