正规短信验证码
Posted 根目录97
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了正规短信验证码相关的知识,希望对你有一定的参考价值。
1.松耦合可拓展短信验证码一般需要三张表,msg(短信记录表)msg_cfg(短信记录与模板关联表)msg_form(短信模板表)
package com.qianmo.qmyj.bean.dto; /** * 短信验证码表 */ public class Msg { private String moblNo;//手机号 private String msgCodeType;//验证码类型 private String msgCode;//验证码 private String aplDateTime;//短信申请时间 private String expDateTime;//短信失效时间 private String useStat;//使用状态 public String getMoblNo() { return moblNo; } public void setMoblNo(String moblNo) { this.moblNo = moblNo == null ? null : moblNo.trim(); } public String getMsgCodeType() { return msgCodeType; } public void setMsgCodeType(String msgCodeType) { this.msgCodeType = msgCodeType == null ? null : msgCodeType.trim(); } public String getMsgCode() { return msgCode; } public void setMsgCode(String msgCode) { this.msgCode = msgCode == null ? null : msgCode.trim(); } public String getAplDateTime() { return aplDateTime; } public void setAplDateTime(String aplDateTime) { this.aplDateTime = aplDateTime == null ? null : aplDateTime.trim(); } public String getExpDateTime() { return expDateTime; } public void setExpDateTime(String expDateTime) { this.expDateTime = expDateTime == null ? null : expDateTime.trim(); } public String getUseStat() { return useStat; } public void setUseStat(String useStat) { this.useStat = useStat == null ? null : useStat.trim(); } }
package com.qianmo.qmyj.bean.dto; /** * 短信验证码配置表 */ public class MsgCfg { private String sceneCode;//场景编号 private String msgFormId;//信息模版ID public String getSceneCode() { return sceneCode; } public void setSceneCode(String sceneCode) { this.sceneCode = sceneCode == null ? null : sceneCode.trim(); } public String getMsgFormId() { return msgFormId; } public void setMsgFormId(String msgFormId) { this.msgFormId = msgFormId == null ? null : msgFormId.trim(); } }
package com.qianmo.qmyj.bean.dto; /** * 短信验证码模版表 */ public class MsgForm { private String msgFormId;//信息模版ID private String sceneCode;//场景编号 private String msgFormDtl;//信息模版内容 public String getMsgFormId() { return msgFormId; } public void setMsgFormId(String msgFormId) { this.msgFormId = msgFormId == null ? null : msgFormId.trim(); } public String getSceneCode() { return sceneCode; } public void setSceneCode(String sceneCode) { this.sceneCode = sceneCode == null ? null : sceneCode.trim(); } public String getMsgFormDtl() { return msgFormDtl; } public void setMsgFormDtl(String msgFormDtl) { this.msgFormDtl = msgFormDtl == null ? null : msgFormDtl.trim(); } }
接下来联系短信服务商,购买短信,查看第三方api文档,下载一个demo测试。
下面是我在此项目中写的短信验证码,controller
package com.qianmo.qmyj.controller; import com.qianmo.qmyj.bean.request.GetMsgRequest; import com.qianmo.qmyj.bean.request.JPushRequest; import com.qianmo.qmyj.bean.response.GetMsgResponse; import com.qianmo.qmyj.bean.response.JPushResponse; import com.qianmo.qmyj.framework.util.QMDateUtil; import com.qianmo.qmyj.service.JPushService; import com.qianmo.qmyj.service.UserInfoExecuteService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.validation.Valid; /*import com.qianmo.pageDao.JPushUtil;*/ /*import com.qianmo.pageDao.JPushUtil;*/ /** * 短信验证 */ @Controller @RequestMapping(value = "/sendSMSController") public class sendSMSController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Resource private UserInfoExecuteService userInfoExecuteService;/** * 发送短信验证码 */ @RequestMapping(value = "/toSendSMS", method = RequestMethod.POST) @ResponseBody public GetMsgResponse toSendSMS(@Valid GetMsgRequest request) { logger.info("发送短信验证码接口开始处理:" + QMDateUtil.getYYYY_MM_DD_HH_MM_SS_CN() + ""); return userInfoExecuteService.getMsg(request); } }
serviceImpl
package com.qianmo.qmyj.service.impl; import com.qianmo.qmyj.bean.dto.Msg; import com.qianmo.qmyj.bean.dto.PushMessage; import com.qianmo.qmyj.bean.dto.UserInfo; import com.qianmo.qmyj.bean.request.*; import com.qianmo.qmyj.bean.response.*; import com.qianmo.qmyj.common.Constants; import com.qianmo.qmyj.common.GenerateUserId; import com.qianmo.qmyj.common.util.MD5Util; import com.qianmo.qmyj.common.util.MsgCodeUtil; import com.qianmo.qmyj.dao.MsgDao; import com.qianmo.qmyj.dao.PushMessageDao; import com.qianmo.qmyj.dao.UserInfoDao; import com.qianmo.qmyj.framework.util.DataVerifyUtil; import com.qianmo.qmyj.framework.util.QMDateUtil; import com.qianmo.qmyj.service.UserInfoExecuteService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; /** * Created by Administrator on 2017/5/4. */ @Service("userInfoExecuteService") public class UserInfoExecuteServiceImpl implements UserInfoExecuteService { private Logger logger = LoggerFactory.getLogger(getClass()); @Resource private MsgDao msgDao; @Resource private UserInfoDao userInfoDao; @Resource private MsgCodeUtil msgCodeUtil; @Resource private PushMessageDao pushMessageDao; @Override public GetMsgResponse getMsg(GetMsgRequest request) { logger.info("————————发送短信验证码接口:"+request); String msgCode = MsgCodeUtil.generateMsgCode();//生成短信验证码 String msgContext = msgCodeUtil.genSmsContext(request.getOprFlag(), msgCode); Msg msg = new Msg(); GetMsgResponse response = new GetMsgResponse(); msg.setAplDateTime(MsgCodeUtil.getStartTime()); msg.setExpDateTime(MsgCodeUtil.getEndTime()); msg.setMoblNo(request.getMobileNumber());//手机号 msg.setMsgCode(MsgCodeUtil.generateMsgCode()); msg.setUseStat(Constants.MSG_CODE.UN_USE); msg.setMsgCodeType(Constants.msgSence.get(request.getOprFlag())); msg.setAplDateTime(QMDateUtil.getYYYYMMDDHHMMSS());//生成时间 msg.setMsgCode(msgCode); msgDao.insertOrUpdateMsgCode(msg); //如果此类型的验证码存才则修改验证码,反之进行添加。 MsgCodeUtil.sendSMSGet(request.getMobileNumber(), msgContext, ""); response.setCode(Constants.SUCCESS_CODE); // response.setMessage(Constants.SUCCESS_MSG); response.setMessage(msgCode); logger.info("————————发送短信验证码接口成功"); response.setvCode("msgCode"); return response; } /*** * 注册 * @param request * @return */ @Override public VerificationResponse registered(VerificationRequest request) { //根据手机号获取验证码信息,判断是否一样,获取到期时间,判断是否有效,获取使用状态,判断是否已使用 //验证成功后,修改验证码使用状态。进行修改,然后进行用户注册 logger.info("------------------------>注册接口处理中:" + QMDateUtil.getYYYY_MM_DD_HH_MM_SS_CN() + "<------------------------"); VerificationResponse response = new VerificationResponse(); UserInfo customer = userInfoDao.getCustomerInfoByAccount(request.getMobileNumber()); if (!DataVerifyUtil.isBlank(customer)){ response.setCode(Constants.ERROR_CODE); response.setMessage(Constants.REG.REG_FAIL); return response; } long startTime = System.currentTimeMillis(); Msg msg = msgDao.selectMsgCodeByMoblNoOprFlag(request.getMobileNumber(),Constants.msgType.REG_FAIL);//00为注册 if (DataVerifyUtil.isBlank(msg)) { response.setCode(Constants.ERROR_CODE); response.setMessage("没有这条数据。"); return response; } String validTime = QMDateUtil.getYYYYMMDDHHMMSS(); if (!request.getMobileNumber().equals(msg.getMoblNo())){ logger.error("------------------->验证码不正确<----------------"); response.setCode("1"); response.setMessage("验证码不正确。"); return response; } if (validTime.compareTo(msg.getExpDateTime()) > 0) { response.setCode("2"); response.setMessage("有效期已过。"); return response; } if (msg.getUseStat().equals(Constants.MSG_CODE.ALR_USE)){ response.setCode("3"); response.setMessage("此验证码已使用。"); return response; } UserInfo newCus = new UserInfo(); newCus.setUserId(GenerateUserId.moblNoToUserId(request.getMobileNumber()));//用户编号 newCus.setCrtChannel(Constants.compStatus.compStatus);//渠道 00:app newCus.setMoblNo(request.getMobileNumber()); newCus.setCrtDateTime(QMDateUtil.getYYYYMMDDHHMMSS()); newCus.setCrtUpdTime(QMDateUtil.getYYYYMMDDHHMMSS()); newCus.setLoginPwd((MD5Util.MD5(request.getPassWord())).toUpperCase()); newCus.setSocre(Constants.REG.DEFAULT_SCORE); newCus.setRemark(request.getTermTp());//设备类型 android:android ios:ios newCus.setCertifStat(Constants.REG.DEFAULT_STAT);//身份验证状态 newCus.setNewbiePurchaseStat(Constants.REG.BUY_STAT);//新手必备包的购买状态 newCus.setReminDrugNumber(Constants.REG.BUY_STAT);//剩余药剂剂量 为0 newCus.setAcctBal(Constants.REG.BUY_STAT);//余额为0 newCus.setAllStar(Constants.REG.BUY_STAT);//总星级为0 newCus.setAvgStart(Constants.REG.BUY_STAT);//平均星级为0 if (userInfoDao.insertCustomer(newCus) < 1) { logger.error("-------------->数据库执行插入用户信息失败<----------"); response.setCode(Constants.ERROR_CODE); response.setMessage(Constants.ERROR_MSG); return response; } logger.info("----------------->注册成功<-------------"); Msg msg1 = new Msg(); msg1.setMoblNo(msg.getMoblNo());//手机号 msg1.setUseStat(Constants.MSG_CODE.ALR_USE);// 99 已使用 msg1.setMsgCodeType(msg.getMsgCodeType());//00注册 01修改 int s = msgDao.updateMsgInfo(msg1); if (DataVerifyUtil.isEmptySize(s)){ logger.info("----------------->修改短信状态失败<-------------"); response.setCode("3333"); response.setMessage("修改短信状态失败"); return response; } response.setCode(Constants.SUCCESS_CODE); response.setMessage(Constants.REG.SUCCESS); response.setUserInfo(newCus); return response; }
}
发送验证码第三方工具
1 package com.qianmo.qmyj.common.util; 2 3 import com.qianmo.qmyj.bean.dto.MsgCfg; 4 import com.qianmo.qmyj.bean.dto.MsgForm; 5 import com.qianmo.qmyj.common.CommonConstants; 6 import com.qianmo.qmyj.common.Constants; 7 import com.qianmo.qmyj.dao.MsgCfgDao; 8 import com.qianmo.qmyj.dao.MsgFormDao; 9 import com.qianmo.qmyj.framework.util.DataVerifyUtil; 10 import com.qianmo.qmyj.framework.util.QMDateUtil; 11 import org.slf4j.Logger; 12 import org.slf4j.LoggerFactory; 13 import org.springframework.stereotype.Component; 14 15 import javax.annotation.Resource; 16 import java.io.*; 17 import java.net.MalformedURLException; 18 import java.net.URL; 19 import java.net.URLConnection; 20 import java.net.URLEncoder; 21 import java.text.SimpleDateFormat; 22 import java.util.ArrayList; 23 import java.util.Calendar; 24 import java.util.List; 25 import java.util.Random; 26 27 /** 28 * Created by Administrator on 2017/5/4. 29 */ 30 @Component 31 public class MsgCodeUtil { 32 33 private static Logger logger = LoggerFactory.getLogger(MsgCodeUtil.class); 34 35 36 @Resource 37 private MsgCfgDao msgCfgDao; 38 @Resource 39 private MsgFormDao msgFormDao; 40 41 42 /** 43 * 生成6位随机数 44 */ 45 public static synchronized String generateMsgCode() { 46 Random random = new Random(); 47 int x = random.nextInt(899999); 48 x = x + 100000; 49 return String.valueOf(x); 50 } 51 52 /** 53 * 获取短信生成时间 54 * 55 * @return 56 */ 57 public static String getStartTime() { 58 return QMDateUtil.getYYYYMMDDHHMMSS(); 59 } 60 /** 61 * 获取短信失效时间(5分钟) 62 * 63 * @return 64 */ 65 public static String getEndTime() { 66 Calendar time = Calendar.getInstance(); 67 /*默认配置短信失效时间为5分钟,可在CommonConstants.properties中更改*/ 68 time.add(Calendar.MINUTE, Integer.parseInt(CommonConstants.getProperty("MSG_TIME"))); 69 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); 70 return sdf.format(time.getTimeInMillis()); 71 } 72 73 /** 74 * 短信参数list 75 * 76 * @param msgList 77 * @param msgText 78 * @return 79 */ 80 private static String msgCfg(List<String> msgList, String msgText) { 81 for (String str : msgList) 82 msgText = msgText.replaceFirst("t%", str); 83 return msgText; 84 } 85 /** 86 * 生成短信模版 87 * 88 * @param oprFlag 89 * @param msgValidCode 90 * @return 91 */ 92 public String genSmsContext(String oprFlag, String msgValidCode) { 93 // 设置模板类型 94 String msgModeId = Constants.msgModeId.get(oprFlag); 95 96 logger.info("msgModeId:[" + msgModeId + "]"); 97 /**查询交易消息配置表*/ 98 MsgCfg msgCfg = msgCfgDao.getMsgCfgByPK(msgModeId); 99 if (DataVerifyUtil.isBlank(msgCfg)){ 100 logger.info("没有符合发送条件的交易" + "SceneCod=" + msgModeId); 101 return null; 102 } 103 /**消息模板表*/ 104 MsgForm msgForm = msgFormDao.selectByPK(msgCfg.getMsgFormId(),msgCfg.getSceneCode()); 105 if (DataVerifyUtil.isBlank(msgForm)) { 106 try { 107 logger.info("msgFormId:" + msgCfg.getMsgFormId() + "sceneCode:" + msgCfg.getSceneCode() + "没有对应的消息模版表"); 108 throw new Exception("没有对应的消息模版表"); 109 } catch (Exception e) { 110 e.printStackTrace(); 111 } 112 } 113 114 List<String> msgParam = new ArrayList<>(); 115 // msgParam.add(QMDateUtil.getYYYY_MM_DD_HH_MM_CN()); 116 msgParam.add(CommonConstants.getProperty("MSG_TIME")); // t% 数据库 短信模板动态有效时间 117 msgParam.add(msgValidCode); // t% 数据库 短信模板动态验证码 118 //你正在进行(青木易家app)注册,失效时间t%分钟,验证码为: t%。如不是本人操作,请忽略此条信息。 119 //你正在进行(青木易家app)修改登录密码,失效时间t%分钟,验证码为: t%。如不是本人操作,请忽略此条信息。 120 return MsgCodeUtil.msgCfg(msgParam, msgForm.getMsgFormDtl()); 121 122 // String msgContext = Constants.msgModeId.get(oprFlag); 123 // msgContext = msgContext + "验证码为:" + msgValidCode; 124 // logger.info("模板类型:[" + msgContext + "]"); 125 // return msgContext; 126 } 127 128 129 /** 130 * http get请求 发送方法 其他方法同理 返回值>0 提交成功 131 * 132 * @param Mobile 手机号码 133 * @param Content 发送内容 134 * @param send_time 定时发送的时间;可以为空,为空时为及时发送 135 * @return 返回值 136 * @throws MalformedURLException 137 * @throws UnsupportedEncodingException 138 */ 139 public static int sendSMSGet(String Mobile, String Content, String send_time) 140 { 141 URL url = null; 142 String CorpID = "XAJS002090";// 账户名 143 String Pwd = "[email protected]";// 密码 144 String send_content = null;// 发送内容 145 try { 146 send_content = URLEncoder.encode( 147 Content.replaceAll("<br/>", " "), "GBK"); 148 url = new URL("https://sdk2.028lk.com/sdk2/BatchSend2.aspx?CorpID=" 149 + CorpID + "&Pwd=" + Pwd + "&Mobile=" + Mobile + "&Content=" 150 + send_content + "&Cell=&SendTime=" + send_time); 151 } catch (MalformedURLException |UnsupportedEncodingException e) { 152 e.printStackTrace(); 153 } 154 BufferedReader in = null; 155 int inputLine = 0; 156 try { 157 System.out.println("开始发送短信手机号码为 :" + Mobile); 158 in = new BufferedReader(new InputStreamReader(url.openStream())); 159 inputLine = new Integer(in.readLine()).intValue(); 160 } catch (Exception e) { 161 System.out.println("网络异常,发送短信失败!"); 162 inputLine = -2; 163 } 164 System.out.println("结束发送短信返回值: " + inputLine); 165 return inputLine; 166 } 167 168 /** 169 * Hppt POST请求发送方法 返回值>0 为 提交成功 170 * 171 * @param Mobile 电话号码 172 * @param Content 发送内容 173 * @param send_time 定时发送时间,为空时,为及时发送 174 * @return 175 * @throws MalformedURLException 176 * @throws UnsupportedEncodingException 177 */ 178 public static int sendSMSPost(String Mobile, String Content, 179 String send_time) throws MalformedURLException, 180 UnsupportedEncodingException { 181 182 String inputLine = ""; 183 int value = -2; 184 DataOutputStream out = null; 185 InputStream in = null; 186 187 String CorpID = "XAJS002090";// 账户名 188 String Pwd = "[email protected]";// 密码 189 String send_content = URLEncoder.encode( 190 Content.replaceAll("<br/>", " "), "GBK");// 发送内容 191 192 String strUrl = "https://sdk2.028lk.com/sdk2/BatchSend2.aspx"; 193 String param = "CorpID=" + CorpID + "&Pwd=" + Pwd + "&Mobile=" + Mobile 194 + "&Content=" + send_content + "&Cell=&SendTime=" + send_time; 195 196 try { 197 198 inputLine = sendPost(strUrl, param); 199 200 System.out.println("开始发送短信手机号码为 :" + Mobile); 201 202 value = new Integer(inputLine).intValue(); 203 204 } catch (Exception e) { 205 206 System.out.println("网络异常,发送短信失败!"); 207 value = -2; 208 209 } 210 211 System.out.println(String.format("返回值:%d", value)); 212 213 return value; 214 } 215 /** 216 * 向指定 URL 发送POST方法的请求 217 * 218 * @param url 发送请求的 URL 219 * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 220 * @return 所代表远程资源的响应结果 221 */ 222 public static String sendPost(String url, String param) { 223 224 PrintWriter out = null; 225 BufferedReader in = null; 226 String result = ""; 227 228 try { 229 URL realUrl = new URL(url); 230 // 打开和URL之间的连接 231 URLConnection conn = realUrl.openConnection(); 232 // 设置通用的请求属性 233 conn.setRequestProperty("accept", "*/*"); 234 conn.setRequestProperty("connection", "Keep-Alive"); 235 conn.setRequestProperty("user-agent", 236 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); 237 // 发送POST请求必须设置如下两行 238 conn.setDoOutput(true); 239 conn.setDoInput(true); 240 // 获取URLConnection对象对应的输出流 241 out = new PrintWriter(conn.getOutputStream()); 242 // 发送请求参数 243 out.print(param); 244 // flush输出流的缓冲 245 out.flush(); 246 // 定义BufferedReader输入流来读取URL的响应 247 in = new BufferedReader( 248 new InputStreamReader(conn.getInputStream())); 249 String line; 250 while ((line = in.readLine()) != null) { 251 result += line; 252 } 253 } catch (Exception e) { 254 System.out.println("发送 POST 请求出现异常!" + e); 255 e.printStackTrace(); 256 } 257 // 使用finally块来关闭输出流、输入流 258 finally { 259 try { 260 if (out != null) { 261 out.close(); 262 } 263 if (in != null) { 264 in.close(); 265 } 266 } catch (IOException ex) { 267 ex.printStackTrace(); 268 } 269 } 270 return result; 271 } 272 273 /** 274 * 账号余额查询 275 * 276 * @param corpId 账号 277 * @param pwd 密码 278 * @return 279 */ 280 public static String getSelSum(String corpId, String pwd) { 281 282 String result = ""; 283 String msg = ""; 284 String strUrl = "https://sdk2.028lk.com/sdk2/SelSum.aspx"; 285 String param = "CorpID=" + corpId + "&Pwd=" + pwd; 286 287 try { 288 289 result = sendPost(strUrl, param); 290 291 if (result.equals("-1")) { 292 msg = "账号未注册"; 293 } else if (result.equals("-2")) { 294 msg = "其他错误"; 295 } else if (result.equals("-3")) { 296 msg = "密码错误"; 297 } else if (result.equals("-101")) { 298 msg = "调用接口频率过快(大于30s调用一次)"; 299 } else if (result.equals("-100")) { 300 msg = "IP黑名单"; 301 } else if (result.equals("-102")) { 302 msg = "账号黑名单"; 303 } else if (result.equals("-103")) { 304 msg = "IP未导白"; 305 } else { 306 msg = String.format("获取成功!%s", result); 307 } 308 309 System.out.println(msg); 310 311 } catch (Exception e) { 312 313 System.out.println("网络异常,回复消息获取失败!"); 314 315 } 316 317 return result; 318 } 319 320 /** 321 * 获取禁止发送的号码 322 * 323 * @param corpId 账号 324 * @param pwd 密码 325 * @return 326 */ 327 public static String getNotSend(String corpId, String pwd) { 328 329 String result = ""; 330 String msg = ""; 331 String strUrl = "https://sdk2.028lk.com/sdk2/NotSend.aspx"; 332 String param = "CorpID=" + corpId + "&Pwd=" + pwd; 333 334 try { 335 336 result = sendPost(strUrl, param); 337 338 if (result.equals("-1")) { 339 msg = "账号未注册"; 340 } else if (result.equals("-2")) { 341 msg = "其他错误"; 342 } else if (result.equals("-3")) { 343 msg = "密码错误"; 344 } else if (result.equals("-101")) { 345 msg = "调用接口频率过快(大于30s调用一次)"; 346 } else if (result.equals("-100")) { 347 msg = "IP黑名单"; 348 } else if (result.equals("-102")) { 349 msg = "账号黑名单"; 350 } else if (result.equals("-103")) { 351 msg = "IP未导白"; 352 } else { 353 msg = result; 354 } 355 356 System.out.println(msg); 357 358 } catch (Exception e) { 359 360 System.out.println("网络异常,禁止号码获取失败!"); 361 362 } 363 364 return result; 365 366 } 367 368 /** 369 * 获取回复消息 370 * 371 * @param corpId 账号 372 * @param pwd 密码 373 * @return 回复消息结果 374 */ 375 public static String getReplyMsg(String corpId, String pwd) { 376 377 String result = ""; 378 String msg = ""; 379 String strUrl = "https://sdk2.028lk.com/sdk2/Get.aspx"; 380 String param = "CorpID=" + corpId + "&Pwd=" + pwd; 381 382 try { 383 384 result = sendPost(strUrl, param); 385 // result ="||15281008413#123#2017-01-04||15281008412#123#2017-01-04||15281008413#121#2017-01-04||15281008410#123#2017-01-04||"; 386 387 if (result == null || result.equals("") || result.length() == 0) { 388 msg = "没有上行信息"; 389 } 390 391 if (result.equals("-1")) { 392 msg = "账号未注册"; 393 } else if (result.equals("-2")) { 394 msg = "其他错误"; 395 } else if (result.equals("-3")) { 396 msg = "密码错误"; 397 } else if (result.equals("-101")) { 398 msg = "调用接口频率过快(大于30s调用一次)"; 399 } else if (result.equals("-100")) { 400 msg = "IP黑名单"; 401 } else if (result.equals("-102")) { 402 msg = "账号黑名单"; 403 } else if (result.equals("-103")) { 404 msg = "IP未导白"; 405 406 } else { 407 408 msg = String.format("获取成功!%s", result); 409 410 result = result.replace("||", "|"); 411 412 String[] strArray = result.split("\\|"); 413 String outContent = ""; 414 415 int i = 0; 416 417 for (String str : strArray) { 418 419 if (str.equals("")) 420 continue; 421 422 String[] strConArr = str.split("#"); 423 424 if (strConArr == null || strConArr.length <= 0) 425 continue; 426 427 i = i + 1; 428 429 outContent = String.format("第%d条回复,手机号码:%s,回复内容:%s,回复时间:%s", 430 i, 431 strConArr[0], 432 strConArr[1], 433 strConArr[2]); 434 435 System.out.println(outContent); 436 437 } 438 } 439 440 System.out.println(msg); 441 442 } catch (Exception e) { 443 444 System.out.println("网络异常,回复消息获取失败!"); 445 446 } 447 448 return result; 449 } 450 451 452 public static void main(String[] args) { 453 MsgCodeUtil.generateMsgCode(); 454 MsgCodeUtil.getStartTime(); 455 MsgCodeUtil.getEndTime(); 456 } 457 }
以上是关于正规短信验证码的主要内容,如果未能解决你的问题,请参考以下文章