您可以尝试其中任何一种:
解决方案 1:
第 1 步:通过 USB 将手机/加密狗连接到 COM 端口。
第二步:通过smslib.jar调用获取短信的代码
获取短信的示例代码:
public void sendSMS() throws Exception{
OutboundNotification outboundNotification = new OutboundNotification();
SerialModemGateway gateway = new SerialModemGateway("modem.com5", "COM5", 9600, "ZTE", "COM5");
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSmscNumber("+91XXXXXXXXXX"); // 10-digit Mobile Number
Service.getInstance().setOutboundMessageNotification(outboundNotification);
Service.getInstance().addGateway(gateway);
Service.getInstance().startService();
OutboundMessage msg = new OutboundMessage(ExcelConnect.strSMSTo, ExcelConnect.strSMSText);
Service.getInstance().sendMessage(msg);
System.out.println(msg);
System.out.println(ExcelConnect.strSMSTo + "-" + ExcelConnect.strSMSText);
Service.getInstance().stopService();
Service.getInstance().removeGateway(gateway);
}
第 3 步:解析短信以获取最新收到的短信获取的列表中的 OTP
.
解决方案 2:
第一步:连接安卓手机/iphone。
第 2 步:在任一手机中自动化 SMS 应用程序,如果它的 android - 通过 appium(或任何其他自动化应用程序)自动化 SMS 应用程序,或者如果它的 iphone - 自动化其 SMS 应用程序功能,
获取 SMS 并解析它以获取 OTP
.
解决方案 3:
第 1 步:注册 HTTP SMS 网关(其中大多数提供付费 API 调用,免费 API 调用用于测试)。
第二步:调用方法获取短信。
第3步:解析消息(按最新收到的短信排序后)得到OTP
.
您可以通过这三种方式获取 OTP,然后您可以将其发送给您的 Web 应用程序。
.
解决方案 4:
从 DB 获取 OTP,如果它的内部应用程序或者是否可以访问。
.
'方案 3 和方案 4' 效率最高,对短信接收平台没有任何依赖。
.
解决方案合并如下: