提问人:Naresh V 提问时间:10/31/2023 更新时间:10/31/2023 访问量:16
Kannel SMS 发送回执 URL 如何在 Java 中使用
kannel sms delivery receipt url how to consume in java
问:
我是 kannel 的新手,我可以通过调用 kannel sendSms get url 成功发送短信。我想获得交货报告,建议使用回调 dlr-ulr,我已包含在 url 中。但是无法决定我需要开发Spring Boot应用程序还是servlet应用程序。最后,我将如何从回调 url 中提取值。
`CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = null;
CloseableHttpResponse response = null;
HttpEntity entity = null;
try {
String callbacjUrl="http://localhost:8080/hello?&smc_id=%F&dlr=%d";
// Create GET URL
URI uri = new URIBuilder().setScheme("http").setHost("10.0.0.190:15015").setPath("/cgi-bin/sendsms")
// URI uri = new URIBuilder().setScheme("http").setHost("localhost:15001").setPath("/cgi-bin/sendsms")
// URI uri = new URIBuilder().setScheme("http").setHost("localhost:15015").setPath("/cgi-bin/sendsms")
.setParameter("username", "user") // kannel username
.setParameter("password", "pass") // kannel password
//.setParameter("smsc", "cell3") // smsc name
.setParameter("from", "840") // sender of message (can be any string
// or number)
.setParameter("to", "658123657") // destination (must be a mobile number)
.setParameter("text", "hello sending test message") // message to send
.setParameter("dlr-url", callbacjUrl)
.build();
System.out.println("uis is is"+uri.toString());
//.setParameter("dlr-mask", "31").setParameter("from", "Test")
httpGet = new HttpGet(uri);
// LOG.info(httpGet.getURI());
httpGet.setHeader("content-type", "text/plain");
System.out.println("hello before excute");
response = httpclient.execute(httpGet);
System.out.println("hello after excute"+response.getParams().toString());
// LOG.info(response.getStatusLine());
entity = response.getEntity();
URL url = new URL(callbacjUrl);
url.getQuery();
System.out.println(getQueryMap(url.getQuery()));
String result = new BufferedReader(new InputStreamReader(entity.getContent()))
.lines().collect(Collectors.joining("\n"));
System.out.println("result --"+result);
System.out.println("entity.getContent()"+entity.getContent().toString());
EntityUtils.consume(entity);
System.out.println("EntityUtils.consume() ended");
} catch (Exception e) {
System.out.println("e"+e.getMessage());
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}`
答: 暂无答案
评论