【问题标题】:send sms using third-party REST service inside a Spring boot application在 Spring Boot 应用程序中使用第三方 REST 服务发送短信
【发布时间】:2018-02-24 12:58:57
【问题描述】:

我想在 Spring Boot 应用程序中使用第三方 REST 服务向用户手机号码发送短信。 API如下:

http://cloud.smsindiahub.in/vendorsms/pushsms.aspx?user=abc&password=xyz&msisdn=919898xxxxxx&sid=SenderId&msg=test%20message&fl=0&gwid=2

user: Your login username. password: Your login password. msisdn: Single mobile number sid: Approved sender id(Only 6 characters). msg: Your message content(Minimum 459 characters/3 messages). Note: If you are using template then edit only the dynamic part which is in ##Field##. fl: if flash message then 1 or else 0 gwid: 2 (its for Transactions route.) Note: Only 100 mobile numbers are allowed.

所以我想问我可以在 Spring Boot 中使用RestTemplate 或其他更好的方式吗? 我还想保存如下响应,即 josn 响应:

{"ErrorCode":"000","ErrorMessage":"Success","JobId":"381a8090-b230-42fa-ac04-157cc2142bfa","MessageData":[{"MobileNumber":"919898xxxxxx ","MessageParts":[{"MessageId": "919898xxxxxx -67e3765cdf034f438a432eacb88d0c14","MessagePartId":1,"MessageText":"test message"}]}]}

对于 REST API 用户名和密码保存 application.xml 是安全的吗?还有如何在课堂上保存和访问。
如果有任何相同的例子,请给我发送链接。 谢谢。

【问题讨论】:

  • 任何人请回复

标签: spring rest spring-boot spring-rest


【解决方案1】:

首先,您的 API 提供者应该使用不同的身份验证方法,例如 Auth 密钥,因为在 RestAPI 中使用用户名和密码不是一个好的选择。

现在,您可以在 springboot 中调用第 3 方 RestAPI url,如下所示:

private static void custom_func()
{
    final String uri = "http://cloud.smsindiahub.in/vendorsms/pushsms.aspx?user=abc&password=xyz&msisdn=919898xxxxxx&sid=SenderId&msg=test%20message&fl=0&gwid=2";

    RestTemplate restTemplate = new RestTemplate();
    String result = restTemplate.getForObject(uri, String.class);

    System.out.println(result);
}

【讨论】:

    猜你喜欢
    • 2016-02-06
    • 1970-01-01
    • 2017-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    • 2016-06-05
    相关资源
    最近更新 更多