In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how Redis imitates the sending of mobile CAPTCHA. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
The details are as follows:
Flow chart
One: add jedis dependency package
Second: test whether the connection to the Redis service is successful / / create a Jedis object to connect to the Redis service (specify a configuration file: redis-server / etc/redis.conf on the server via redis-server) Jedis jedis = new Jedis ("192.168.119.128", 6379); String value = jedis.ping (); System.out.println (value); jedis.close () Third, write the method of generating CAPTCHA / * generate CAPTCHA * @ return code * / public static String getCode () {Random random = new Random (); String code = ""; for (int I = 0; I < 6; iCAPTCHA +) {int num = random.nextInt (10); code + = num } System.out.println (code); return code;} IV: write the method of sending CAPTCHA / * users click to generate CAPTCHA and add it to redis * @ param phone * / public static void sendVerifyCode (String phone) {Jedis jedis = new Jedis ("192.168.119.128", 6379) / / key of the mobile phone number, obtain the number of times the mobile number sends CAPTCHA String countKey = "VerifyCode" + phone + ": count"; / / key of the CAPTCHA, obtain the CAPTCHA of the mobile number String codeKey = "VerifyCode" + phone + ": code"; / / obtain the countKey to determine whether the current mobile number can send the CAPTCHA String count = jedis.get (countKey) If (count = = null) {jedis.setex (countKey, 24 * 60 * 60, "1");} else if (Integer.parseInt (count) 2) {System.out.println ("the number of times the current mobile number sends CAPTCHA exceeds the limit, please send CAPTCHA tomorrow"); jedis.close ();} String code = getCode () Jedis.setex (codeKey, 120, code); jedis.close ();} V: write verification code method / * user input mobile phone number and verification code for verification * @ param phone * @ param code * / public static void CustomerVerifyCode (String phone, String code) {Jedis jedis = new Jedis ("192.168.119.128", 6379) String codeKey = "VerifyCode" + phone + ": code"; String phoneVerifyCode = jedis.get (codeKey); if (phoneVerifyCode.equals (code)) {System.out.println ("check successful!") ;} else {System.out.println ("Verification failed!") ;} jedis.close ();} this is the end of the article on "how Redis imitates the sending of mobile CAPTCHA". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.