Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Java to realize the voice verification function of sending mobile phone short messages

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to use Java to achieve the voice verification function of sending mobile phone text messages. It is very detailed and has a certain reference value. Interested friends must read it!

The function of sending SMS verification code and voice verification code can be realized by using the third-party platform. The framework of this paper is struts2+spring+hibernate, and now the core code function of action layer is given.

Public class VerifyAction extends BaseAction {private static final long serialVersionUID = 1L; private CommonConfigService commonConfigService; private UserPhoneVerifyService userPhoneVerifyService; private UserVerifyService userVerifyService; private PhoneDetectService phoneDetectService; private AccountService accountService; / / send SMS verification code public String sensSms () {try {result.setResult (JsonResult.SUCCESS); if (model.getType () = = PhoneVerifyType.REGISTER) {if (userVerifyService.checkRegisterPhone (model.getPhone () {result.setErrorMessage ("the mobile number is registered") Result.setResult (JsonResult.ERROR); return SUCCESS;}} if (! phoneDetectService.check (model.getPhone () {result.setErrorMessage ("this mobile phone number is abnormal and cannot be verified"); result.setResult (JsonResult.ERROR); return SUCCESS } Dh4TongSmsOperator dh4TongSmsOperator = new Dh4TongSmsOperator (commonConfigService.getString ("dh4tong", "account"), DigestUtil.md5 (commonConfigService.getString ("dh4tong", "password")); String code = RandomUtil.randomNum (6) If (dh4TongSmsOperator.send (UUIDGenerator.generate (), model.getPhone (), String.format ("Dear user, your CAPTCHA is% s", code), "[XX system name]") {userPhoneVerifyService.record (model.getPhone (), model.getType (), code, model.getUserId ());} else {result.setErrorMessage ("Sorry, failed to send SMS, please try again later") Result.setResult (JsonResult.ERROR); return SUCCESS;} result.setErrorMessage ("SMS verification code has been sent successfully, please use it in time within 5 minutes, thank you!") ;} catch (Exception e) {e.printStackTrace ();} return SUCCESS;} / / send voice verification code public String sensVoice () {try {result.setResult (JsonResult.SUCCESS); if (model.getType () = = PhoneVerifyType.REGISTER) {if (userVerifyService.checkRegisterPhone (model.getPhone () {result.setErrorMessage ("the mobile number is registered") Result.setResult (JsonResult.ERROR); return SUCCESS;}} if (! phoneDetectService.check (model.getPhone () {result.setErrorMessage ("the phone number is abnormal and cannot be verified"); result.setResult (JsonResult.ERROR); return SUCCESS;} String code = RandomUtil.randomNum (6) Dh4TongVoiceOperator dh4TongVoiceOperator = new Dh4TongVoiceOperator (commonConfigService.getString ("dh4tong", "account"), DigestUtil.md5 (commonConfigService.getString ("dh4tong", "password")); if (dh4TongVoiceOperator.send (UUIDGenerator.generate (), request.getPhone (), code)) {userPhoneVerifyService.record (request.getPhone (), request.getType (), code, request.getUserId ()) } else {result.setErrorMessage ("Sorry, failed to send voice, please try again later"); result.setResult (JsonResult.ERROR); return SUCCESS;} result.setErrorMessage ("Voice verification code was sent successfully, please use it in time within 5 minutes, thank you!") Catch (Exception e) {e.printStackTrace ();} return SUCCESS;} public void setCommonConfigService (CommonConfigService commonConfigService) {this.commonConfigService = commonConfigService;} public void setUserPhoneVerifyService (UserPhoneVerifyService userPhoneVerifyService) {this.userPhoneVerifyService = userPhoneVerifyService;} public void setUserVerifyService (UserVerifyService userVerifyService) {this.userVerifyService = userVerifyService;} public void setPhoneDetectService (PhoneDetectService phoneDetectService) {this.phoneDetectService = phoneDetectService;} public void setAccountService (AccountService accountService) {this.accountService = accountService }} the above is all the contents of the article "how to use Java to achieve voice verification of sending SMS messages". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report