In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to realize the SMS sending interface of the SpringBoot project". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to realize the SMS sending interface of the SpringBoot project".
one。 Implementation of short message interface
Description: request a third-party SMS interface platform (while the interface request of the third-party SMS platform is implemented by webservice). At this time, we need to test whether the interface is connected. The tool SoapUI testing tool you want to use cannot use PostMan. Even if you use post to assemble the parameters and request the SMS platform interface, it will not work (ping IP before the request, only in the same network segment. Or use VPN remote connection can also be requested), after the interface is connected. Start the naked code. The code is completed using IDEA tools, and the implementation logic depends on the requirements.
First import two dependent commons-logging commons-logging 1.2 commons-discovery commons-discovery 0.2 webservice implementation (IDEA)
① creates a new package, mouse click on this package
② find generate and click
The following interface will appear in ③. Note that the WSDL URL address should be changed (SMS platform request API address, followed by a question mark and wsdl) and Apache Axis should also be changed to Glassfish / JAX-WS.
This interface appears after ④ changes, and after clicking OK, the file automatically created by idea will appear under the newly created package.
⑤ can delete the .class file at this time, leaving these three files (Note: the SMSNewAllService class can be understood as an implementation class that opens the webservice interface)
Implementation and call of ⑥ service
Package com.enn.claim.config.sms;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.stereotype.Component;/** * in the configuration file: send SMS platform address / account / password / SMS type / fee department and other parameters * / @ Component@ConfigurationProperties (prefix = "send-messages") public class SmsProperties {private String address; private String userName; private String passWord; private String smsType; private String feeDept Public String getAddress () {return address;} public void setAddress (String address) {this.address = address;} public String getUserName () {return userName;} public void setUserName (String userName) {this.userName = userName;} public String getPassword () {return passWord;} public void setPassword (String password) {this.passWord = password } public String getSmsType () {return smsType;} public void setSmsType (String smsType) {this.smsType = smsType;} public String getFeeDept () {return feeDept;} public void setFeeDept (String feeDept) {this.feeDept = feeDept } @ Override public String toString () {return "SmsProperties {" + "address='" + address +'\'+ ", userName='" + userName +'\'+ ", passWord='" + passWord +'\'+ ", smsType='" + smsType +'\'+ " FeeDept=' "+ feeDept +'\'+'}' }} / * send SMS * @ param sendMessageVo * @ return * / @ Override public SendSmsResult sendMessage (SendSmsVo sendMessageVo) {/ / 0. Parameter check sendMessageVo = this.validParams (sendMessageVo); / / 1. Create the returned result set SendSmsResult smsResult = new SendSmsResult (); try {/ / 2. Assemble and send the mobile phone number String mobiles = ""; for (int I = 0; I
< sendMessageVo.getMobile().size(); i++) { if (i == 0) { mobiles = sendMessageVo.getMobile().get(i); } else { mobiles = mobiles + "," + sendMessageVo.getMobile().get(i); } } //3.发送短信 log.info("开始请求发送短信>> "+" start sending SMS messages "); SMSNewAllService service = new SMSNewAllService (); ISMSNewAll ismsNewAll = service.getISMSNewAllPort (); String resultSend = ismsNewAll.sendSMSWithExt (smsProperties.getUserName (), smsProperties.getPassword (), mobiles, sendMessageVo.getSmsBody (), smsProperties.getSmsType (), sendMessageVo.getReplyFlag (), smsProperties.getFeeDept (), sendMessageVo.getAllowStartTime (), sendMessageVo.getAllowEndTime (), sendMessageVo.getDeadLineTime (), sendMessageVo.getAppointTime (), sendMessageVo.getArea (), sendMessageVo.getExtCode () Log.info (return value of "request to send SMS > {}:" + resultSend); / / 4. Judge the returned result if (ObjectUtils.isEmpty (resultSend)) {return SmsResultUtil.error ("failed to send SMS request, SMS service provider did not respond!");} / / 5. Processing the returned information JSONObject jsonObject = JSONObject.parseObject (resultSend); String errorCode = jsonObject.get ("errorCode"). ToString (); String status = jsonObject.get ("status"). ToString (); if ("0" .equals (errorCode) & & "ok" .equals (status)) {String msgInfo = jsonObject.getString ("msgInfo") SmsResult = SmsResultUtil.returnMessage (SmsConstants.SystemCode.OK, SmsConstants.MessageCode.SUCCESS_CODE, SmsConstants.MessageMsg.SUCCESS_MSG, msgInfo); return smsResult;} else {String errorMsg = jsonObject.getString ("errorMsg") SmsResult = SmsResultUtil.returnMessage (SmsConstants.SystemCode.ERROR, SmsConstants.MessageCode.FAIL_CODE, "request to send SMS failed, and the error message returned by the service provider is" + errorMsg, "); return smsResult;}} catch (Exception e) {log.info (" failed to send SMS request, system exception {} ", e); e.printStackTrace () Return SmsResultUtil.error ("failed to send SMS request, system exception!");} finally {log.info ("send SMS result {}", JSONObject.toJSONString (smsResult));}}
⑦ yml profile configuration
Thank you for reading, the above is the content of "how to achieve SMS sending interface in SpringBoot project". After the study of this article, I believe you have a deeper understanding of how to implement SMS sending interface in SpringBoot project, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.