Send SMS Verification Code and email Verification Code-java implementation

Source: Internet
Author: User




SMS Verification Code



SMS Verification code is to call some interface to send SMS, SMS verification code in the login, registration and other operations to use the most extensive, this section of this article demonstrates how to use Java to make a simple SMS verification code login.



I'm using a short message interface (not an ad) for aggregating data, because the interface invocation of aggregated data is convenient and simple, so first you need to go to the aggregation data to request a SMS interface API:





The application will require you to do real-name authentication, if you do not want to be certified to skip certification is also possible.






After applying for SMS API go to the following interface and click "Template":








You need to apply for a text message template, define the template content according to your own needs (before defining the template rule description below this page):








After you submit your review, you can see the audit status of the template list and template below this page:








Then click on "My Data" and click on "interface" in the SMS API service:








The invocation instructions for the interface are all in this page and need to follow the rules here to invoke the API:











After the SMS template application can use this API, the following shows how to use Java to invoke this API, make a simple SMS verification code login:



The first is the INDEX.JSP code for the page:








Class to invoke the SMS interface:








To process the servlet that sent the Authenticode request:








Finally, the servlet that handles the logon business:











Operation Result:








Verification Code Received:







Enter the verification code to sign in:








Console Print Content:














Email Verification Code



Generally can use the mailbox to register the account, in the login, registration or forget the password and other operations, can use the mailbox to verify, so the mailbox verification code is also used more widely, but compared to SMS verification code, the mailbox verification code use less, because now is a person has a mobile phone number, but not necessarily have a mailbox account.



Use the mailbox to send the verification code, do not need to like SMS verification code to call the SMS Service API to send the verification code, but need to have a mailbox server capable of sending mail or use a third-party mailbox, such as 163, 126, QQ mailbox.



Mailbox servers or third-party mailboxes require the POP3, SMTP, and IMAP services to be turned on, because these services are enabled before they can be called by a third party to send mail. Because it is troublesome to build a mailbox server myself, I use 163 of the mailbox as a demo here.






1. First you have to go to the mailbox to open the service, log in and click Settings to see the options for these services:








2. Set up the service, the first time you set up, you will need SMS verification, and then will ask you to set a password:








3. SMS Verification:








4. Set the password:








5. Complete:





The password for this setting is the authorization code to remember, when you send the message you need to use this authorization code.






Then we use Java to write a class to send the message, but before you write this code you have to get the jar package in the first, you need to use these third-party jar packages to implement the mail delivery:








Once you have the jar package, import the jar packages into the Lib directory under Web engineering:








With these jar packages, you can start writing code, we'll write a simple class to test the success of sending a message, code example:








Operation Result:





, the message can be sent normally, and the recipient can receive it.









Questions about the verification code for the message:


Sometimes the mail will be sent slowly, even can not send out. So the user in this case needs to wait, the most classic is that the icon of the circle will always be in the loop, in order to solve the problem of waiting, you can send the verification code sent to a queue collection, let it send in the background, so that the user will not be stuck in the current page to send the verification code:




























This article is from the "zero" blog, make sure to keep this source http://zero01.blog.51cto.com/12831981/1983738



Send SMS Verification Code and email Verification Code-java implementation


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.