我想知道我应该使用什么方法来通过Nexmo接收消息。有没有人在这个问题上有过经验,因为Nexmo似乎没有关于如何通过那里的库接收消息的清晰文档。任何帮助都会很好。
发布于 2017-05-26 09:05:45
对于您拥有的每个Nexmo号码,您可以配置一个URL,该URL将由Nexmo在收到该号码的SMS时调用。GET请求将包含有关接收到的SMS作为请求params的信息。
增加了一些复杂性(当您正在开发时),因为Nexmo需要能够到达一个托管在您的开发机器上的URL,这在Internet上可能是不可公开的!为此,您需要运行类似于恩格洛克的操作,它将使用公共URL为本地计算机上的端口提供隧道。
我建议从一个简单的servlet开始,打印出它的参数:
public class InboundSMSServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException,
java.io.IOException {
System.out.println("Received: " + req.getMethod());
for (String param : Collections.list(req.getParameterNames())) {
String value = req.getParameter(param);
System.out.println(param + ": " + value);
}
}
}..。把它配置成一个方便的URL ..。
<servlet>
<servlet-name>inbound-sms</servlet-name>
<servlet-class>getstarted.InboundSMSServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>inbound-sms</servlet-name>
<url-pattern>/inbound</url-pattern>
</servlet-mapping>同时运行servlet容器和ngrok,并检查带有/YOUR_PROJECT_NAME/inbound的ngrok是否正常工作。然后进入Nexmo仪表板,你的号码,然后按下你想要接收短信的号码编辑。输入上面测试的Ngrok URL。
现在将SMS发送到您配置的号码,您应该会看到打印到控制台的消息的内容;如下所示:
Received: GET
messageId: 0B0000004A2D09D9
to: 447520666777
text: Hello Nexmo!
msisdn: 447720123123
type: text
keyword: HELLO
message-timestamp: 2017-04-27 14:41:32如何在Nexmo站点上记录这一工作的详细信息
https://stackoverflow.com/questions/44103987
复制相似问题