当前位置: 首页 > news >正文

阿里云做网站需要些什么软件广州百度推广客服电话多少

阿里云做网站需要些什么软件,广州百度推广客服电话多少,做网站 sql 用哪种,大连金普新区城乡建设局网站通过时间获取验证码 1.需求2.代码实现2.1 依赖2.2 时间参数处理方法2.3 截取验证码方法2.4 验证方法 3.总结 1.需求 要求是很简单的,每个验证码的有效时间是2小时,这个并不是收到验证码开始计时的,而是每个两小时的时间段使用的是相同的验证…

通过时间获取验证码

  • 1.需求
  • 2.代码实现
    • 2.1 依赖
    • 2.2 时间参数处理方法
    • 2.3 截取验证码方法
    • 2.4 验证方法
  • 3.总结

1.需求

要求是很简单的,每个验证码的有效时间是2小时,这个并不是收到验证码开始计时的,而是每个两小时的时间段使用的是相同的验证码。

2.代码实现

2.1 依赖

<dependency><groupId>gov.nist.math</groupId><artifactId>jama</artifactId><version>1.0.3</version>
</dependency><dependency><groupId>commons-codec</groupId><artifactId>commons-codec</artifactId><version>1.6</version>
</dependency>

2.2 时间参数处理方法

2个小时处理为相同的值

@Slf4j
public class VerificationCodeUtil {/*** 时间字符串** @param dateStr yyyy-MM-dd HH:mm:ss*/public static String getCode(String dateStr) {int dataStrLength = 13;try {if (dateStr.length() >= dataStrLength) {String yearMonthDay = dateStr.substring(0, 10);int hour = Integer.parseInt(dateStr.substring(11, 13));int twoHour = 2;if (hour % twoHour != 0) {hour--;}String md5Str = DigestUtils.md5Hex("vc#" + yearMonthDay + hour);return getCodeByMd5(md5Str);} else {log.error("dateStr [{}] not match format [yyyy-MM-dd HH:mm:ss]!", dateStr);}} catch (Exception e) {e.printStackTrace();log.error("dateStr [{}] not match format [yyyy-MM-dd HH:mm:ss]!", dateStr);}return dateStr;}
}

2.3 截取验证码方法

@Slf4j
public class VerificationCodeUtil {// 对指定字符串生成验证码private static String getCodeByMd5(String md5Str) {try {byte[] md5 = md5Str.getBytes();double[][] preMatrix = new double[4][8];for (int j = 0; j < 4; j++) {for (int k = 0; k < 8; k++) {preMatrix[j][k] = md5[j * 8 + k];}}Matrix matrix = new Matrix(preMatrix);Matrix matrix1 = matrix.getMatrix(1, 2, 2, 5);Matrix matrix2 = matrix.transpose();Matrix matrix21 = matrix2.getMatrix(0, 3, 0, 3);Matrix matrix22 = matrix2.getMatrix(4, 7, 0, 3);Matrix matrix3 = matrix21.plus(matrix22);Matrix result = matrix1.times(matrix3);double[][] re = result.getArray();StringBuilder str = new StringBuilder();for (double[] doubles : re) {for (double aDouble : doubles) {int a = (int) aDouble % 16;str.append(Integer.toHexString(a));}}return str.toString().toUpperCase();} catch (Exception e) {e.printStackTrace();return null;}}
}

2.4 验证方法

@Slf4j
public class VerificationCodeUtil {public static void main(String[] args) {DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");DateTime parse = DateUtil.parse("2023-11-09 23:59:59", "yyyy-MM-dd HH:mm:ss");String format = df.format(parse);System.out.println(getCode(format));// 00:00 3A756DFC// 00:59 3A756DFC// 01:59 3A756DFC// 01:59 3A756DFC// 02:00 9E937D4B// 02:59 9E937D4B// 03:00 9E937D4B// 22:00 D014DD79// 23:59 D014DD79        }
}

3.总结

很简单的算法分享。优点:

  • 不需要将生成的验证码缓存。
  • 时间入参,能够重复获取相同的值。
http://www.mnyf.cn/news/49856.html

相关文章:

  • 做网站的域名网站建设开发
  • 电商加盟网站建设广州今日头条新闻最新
  • 杂粮网站建设的必要性什么推广方式能快速引流
  • 广西庆海建设发展有限公司网站微信广告投放推广平台
  • 平顶山市建设局网站快速建网站
  • 做爰全过程免费网站可以看站内营销推广方式
  • 淘宝里面的网站怎么做的谷歌关键词工具
  • 房屋 哪个网站做的最好搜外滴滴友链
  • 一学一做演讲视频网站百度竞价托管费用
  • 做网站 不是计算机专业晚上看b站
  • 查域名的网站百度快速排名用什
  • 网页设计制作课程baike seotl
  • 全国互联网备案信息查询系统湖南seo网站开发
  • 网站开发合作协议合同范本seo排名优化推荐
  • 佛山做网站格搜索网站排名优化
  • 西安做搭建网站网络营销工具及其特点
  • 北京朝阳住房建设委员会网站产品推广广告
  • 灌南网站开发seo怎么刷排名
  • 三元里网站建设百度推广开户费用多少
  • 如何利用wordpress广州谷歌优化
  • 东莞市微客巴巴做网站网络优化工程师有多累
  • 网站建设期末作业网络优化工程师简历
  • 怎样吧自己做的网站发布短视频seo询盘系统
  • 网页设计与网站建设在线作业答案东莞百度搜索优化
  • wordpress如何开启多站点国际最新消息
  • 临西做网站哪里便宜长尾关键词爱站网
  • 建一个外贸网站多少钱北京网站优化公司哪家好
  • 手机网站菜单栏怎么做找网站公司制作网站
  • 公司没有备案了网站百度一下官方入口
  • 佛山网站优化美姿姿seo台州seo网站排名优化