java实现语音发送,Java实现发送手机短信语音验证功能代码实例
這篇文章主要介紹了java實現發送手機短信語音驗證功能代碼實例,www.cppcns.com文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
利用第三方平臺可以實現發送手機短信驗證碼和語音驗證碼的功能,本文使用框架是struts2+spring+hibernate,現就action層給出核心代碼功能。
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;
// 發送短信驗證碼
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;
}
Dh3TongSmsOperator dh3TongSmsOperator = new Dh3TongSmsOperator(
commonConfigService.getString("dh3tong", "account"),
DigestUtil.md5(commonConfigService.getString("dh3tong", "password")));
SEhdySImResult(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);
Dh3TongVoiceOperator dh3TongVoiceOperator = new Dh3TongVoiceOperator(
commonConfigService.getString("dh3tong", "account")www.cppcns.com,
DigestUtil.md5(commonConfigService.getString("dh3tong", "password")));
if (dh3TongVoiceOperator.send(UUIDGenerator.generate(), request.getPhone(), code)) {
userPhoneVerifyService.record(request.getPhone(), request.getType(), code, request.getUserId());
} else {
result.setErrorMessage("很抱歉,發送語音失敗,請稍后再試");
result.setResult(JsonResult.ERROR);
return SUCCESS;
}
result.setErrorMessage("語音驗證碼發送成功,請在5分鐘內及時使用,謝謝!");
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
public void setCommonConfigService(CommonConfigService commonConfigService) {
this.commonConfigService = commonConfigService;
}
public void setUserPhoneVerifyService(UserPhoneVerifyService userPhoneVerifyService) {
this.userPhoneVerifyService = userPhoneVerifyService;
}
public EhdySImvoid setUserVerifyService(UserVerifyService userVerifyService) {
this.userVerifyService = userVerifyService;
}
public void setPhoneDetectService(PhoneDetectService phoneDetectService) {
this.phoneDetectService = phoneDetectService;
}
public void setAccountService(AccountService accountService) {
this.accountService = accountService;
}
}
以上是干貨分享,已測試驗證過!
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持我們。
本文標題: Java實現發送手機短信語音驗證功能代碼實例
本文地址: http://www.cppcns.com/ruanjian/java/274432.html
總結
以上是生活随笔為你收集整理的java实现语音发送,Java实现发送手机短信语音验证功能代码实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java引用传递_理解Java中的引用传
- 下一篇: python history文件_【py