這篇文章主要介紹如何使用Java實現(xiàn)發(fā)送手機短信語音驗證功能,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:國際域名空間、網(wǎng)站空間、營銷軟件、網(wǎng)站建設(shè)、龍泉網(wǎng)站維護、網(wǎng)站推廣。利用第三方平臺可以實現(xiàn)發(fā)送手機短信驗證碼和語音驗證碼的功能,本文使用框架是struts2+spring+hibernate,現(xiàn)就action層給出核心代碼功能。
public class VerifyAction extends BaseAction<VerifyRequest> { private static final long serialVersionUID = 1L; private CommonConfigService commonConfigService; private UserPhoneVerifyService userPhoneVerifyService; private UserVerifyService userVerifyService; private PhoneDetectService phoneDetectService; private AccountService accountService; // 發(fā)送短信驗證碼 public String sensSms() { try { result.setResult(JsonResult.SUCCESS); if (model.getType() == PhoneVerifyType.REGISTER) { if (userVerifyService.checkRegisterPhone(model.getPhone())) { result.setErrorMessage("該手機號已注冊"); result.setResult(JsonResult.ERROR); return SUCCESS; } } if (!phoneDetectService.check(model.getPhone())) { result.setErrorMessage("該手機號異常,不能進行驗證操作"); 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("尊敬的用戶,您的驗證碼是:%s", code), "【XX系統(tǒng)名】")) { userPhoneVerifyService.record(model.getPhone(), model.getType(), code, model.getUserId()); } else { result.setErrorMessage("很抱歉,發(fā)送短信失敗,請稍后再試"); result.setResult(JsonResult.ERROR); return SUCCESS; } result.setErrorMessage( "短信驗證碼發(fā)送成功,請在5分鐘內(nèi)及時使用,謝謝!"); } catch (Exception e) { e.printStackTrace(); } return SUCCESS; } // 發(fā)送語音驗證碼 public String sensVoice() { try { result.setResult(JsonResult.SUCCESS); if (model.getType() == PhoneVerifyType.REGISTER) { if (userVerifyService.checkRegisterPhone(model.getPhone())) { result.setErrorMessage("該手機號已注冊"); result.setResult(JsonResult.ERROR); return SUCCESS; } } if (!phoneDetectService.check(model.getPhone())) { result.setErrorMessage("該手機號異常,不能進行驗證操作"); 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("很抱歉,發(fā)送語音失敗,請稍后再試"); result.setResult(JsonResult.ERROR); return SUCCESS; } result.setErrorMessage("語音驗證碼發(fā)送成功,請在5分鐘內(nèi)及時使用,謝謝!"); } 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; }}
以上是“如何使用Java實現(xiàn)發(fā)送手機短信語音驗證功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
分享題目:如何使用Java實現(xiàn)發(fā)送手機短信語音驗證功能-創(chuàng)新互聯(lián)
網(wǎng)站地址:http://vcdvsql.cn/article46/csidhg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、小程序開發(fā)、面包屑導航、App設(shè)計、網(wǎng)頁設(shè)計公司、用戶體驗
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容