日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java web 手机验证_javaWeb发送手机短信验证码(云通讯)

發布時間:2024/9/30 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java web 手机验证_javaWeb发送手机短信验证码(云通讯) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

/*** 2>向手機發送驗證碼

*@paramrequest( telephone 手機號碼)

*@return向前臺返回的結果*/

public voidsendSmsIdentifyingCode() {

String phone_no=getRequest().getParameter("phone_no");

String templateId=getRequest().getParameter("templateId");//request.getParameter("phone_no");//設置多少分鐘內短信有效(單位:分鐘)

int timeOutMin = 5;

String randomInt= creatNum()+"";//生成驗證隨機數

ObjectNode smsResult =sendInfo(phone_no, timeOutMin, randomInt , templateId );//電話號碼--有效時間--驗證碼隨機數--模板ID

System.out.println(randomInt);

HttpServletResponse response=ServletActionContext.getResponse();

response.setContentType("text/html");

PrintWriter out= null;try{

out=response.getWriter();

}catch(IOException e) {

e.printStackTrace();

}if (smsResult == null) {

out.println(ResultMessageUtils.creatJsonResultMessage(CoreStatus.RESULT_900009));

}else if (smsResult.get("statusCode").textValue().equals("000000")) {

Map telephoneCode = new HashMap<>();

String code= smsResult.get("randomNum").asText().replace("\"", "");

telephoneCode.put("code", code);

telephoneCode.put("time", String.valueOf(DateUtils.getSystemDate().getTime()));

telephoneCode.put("message", "Success");//存入Redis中

cacheClient.setObject("tel" +phone_no, telephoneCode);

out.print( ResultMessageUtils.creatJsonResultMessage(CoreStatus.RESULT_000000));

}else{

ObjectNode result;

result=JsonUtils.createObjectNode();

result.put("code", smsResult.get("statusCode").textValue());

result.put("message", smsResult.get("statusMsg").textValue());

result.put("datatime", DateUtils.getDefaultDateTimeToString());//return result.toString();

out.println(result.toString());

}

}/*** 向手機發送信息

*

*@paramphone_no

*@paramtimeOutMin(可以為空)

*@paramrandomNum

*@parammsm_type

*@paramtemplateId 短信模板Id

*@returnsmsResult*/

publicObjectNode sendInfo(String phone_no, Integer timeOutMin, String randomNum,String templateId) {//Map telephoneMap = (Map) cacheClient.getObject("tel" + phone_no);

List messageSubstitutes = newArrayList();if (timeOutMin != null) {

messageSubstitutes.add(String.valueOf(randomNum));

messageSubstitutes.add(String.valueOf(timeOutMin));

}

List telephoneList = new ArrayList<>();

telephoneList.add(phone_no);

String smsResultString=smsService.sendSms(telephoneList, templateId, messageSubstitutes);

ObjectNode smsResult=(ObjectNode) JsonUtils.stringToJsonObject(smsResultString);

smsResult.put("randomNum", randomNum.replace("\"", ""));returnsmsResult;

}/*** 生成隨機驗證碼(密碼)

*

*@return

*/

publicInteger creatNum() {int randomInt = new Random().nextInt(900000) + 100000;//設置短信發送內容

returnrandomInt;

}

總結

以上是生活随笔為你收集整理的java web 手机验证_javaWeb发送手机短信验证码(云通讯)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。