ussd - 交互式 USSD session 的 SMSLib 示例

标签 ussd smslib

我有一个 USSD 应用程序,为用户提供交互式 session ,例如:

User> Dial USSD Shortcode
Serv> Return Main Menu
User> Select Option 1, e.g. "View Movie Times"
Serv> Return List of Cities
User> Select Option 3, e.g. Mumbai
Serv> Return List of Cinemas
User> etc ...

我想通过使用 SMSLib 来模拟用户来测试 USSD 服务器。

是否有示例 SMSLib 代码片段显示如何与 USSD 服务器执行交互式 USSD session ?

最佳答案

代码为link给出了使用smslib发送和接收USSD数据的示例:

// SendUSSD.java - Sample application.
//
// This application shows you the basic procedure for sending messages.
// You will find how to send synchronous and asynchronous messages.
//
// For asynchronous dispatch, the example application sets a callback
// notification, to see what's happened with messages.

package examples.modem;

import org.smslib.AGateway;
import org.smslib.AGateway.Protocols;
import org.smslib.IUSSDNotification;
import org.smslib.Library;
import org.smslib.Service;
import org.smslib.USSDResponse;
import org.smslib.modem.SerialModemGateway;

public class SendUSSD
{
        public void doIt() throws Exception
        {
                Service srv;
      USSDNotification ussdNotification = new USSDNotification();
                System.out.println("Example: Send USSD Command from a serial gsm modem.");
                System.out.println(Library.getLibraryDescription());
                System.out.println("Version: " + Library.getLibraryVersion());
                srv = new Service();
                SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM4", 19200, "Huawei", "E220");
                gateway.setProtocol(Protocols.PDU);
      gateway.setInbound(true);
                gateway.setOutbound(true);
                gateway.setSimPin("0000");
      srv.setUSSDNotification(ussdNotification);
                srv.addGateway(gateway);
                srv.startService();
                System.out.println();
                System.out.println("Modem Information:");
                System.out.println("  Manufacturer: " + gateway.getManufacturer());
                System.out.println("  Model: " + gateway.getModel());
                System.out.println("  Serial No: " + gateway.getSerialNo());
                System.out.println("  SIM IMSI: " + gateway.getImsi());
                System.out.println("  Signal Level: " + gateway.getSignalLevel() + "%");
                System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
                System.out.println();

      String resp = gateway.sendUSSDCommand("*888#"); // not working
//      String resp = gateway.sendCustomATCommand("AT+CUSD=1,\"*888#\",15\r"); // working
      System.out.println(resp);

      System.out.println("Now Sleeping - Hit <enter> to terminate.");
                System.in.read();
                srv.stopService();
        }

   public class USSDNotification implements IUSSDNotification
   {
      public void process(AGateway gateway, USSDResponse response) {
                        System.out.println("USSD handler called from Gateway: " + gateway.getGatewayId());
                        System.out.println(response);
      }
   }

        public static void main(String args[])
        {
                SendUSSD app = new SendUSSD();
                try
                {
                        app.doIt();
                }
                catch (Exception e)
                {
                        e.printStackTrace();
                }
        }
}

关于ussd - 交互式 USSD session 的 SMSLib 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13268389/

相关文章:

android - 交互式 ussd session (多步)在 android 8(奥利奥)上不起作用

java - 无法使用java发送短信

java - 如何使用 smslib 中的 smsserver.java?我已经阅读了文档

java - 使用 smslib 获取短信的文本和发件人

Android USSD 回复 保存

android - Android 上是否可以通过 Awareness API 读取/解析 USSD 响应消息?

android - USSD阅读回复

java - 连接到互联网时使用 HSPA 调制解调器发送短信

java - 如何使用 smslib 中的队列消息传递方法系列?