Send SMS Verification code/SMS notification via third party interface (recommended) _java

Source: Internet
Author: User
Tags abs stringbuffer

Requirements: The first delivery password for the public default password is changed to click into the function, SMS sent the system automatically generated eight digits, uppercase and lowercase letters and special symbols generated by the password. SMS Send service is provided by Cloud communication http://www.yuntongxun.com/.

Random Password Generation method:

/** * Generates password * @author Chao.gao * @param The total length of the generated password * @return The string of the password/public static string genrandomnum (int pwd_ Len) {//String re= "(? =.*\d) (? =.*[a-z]) (? =.*[a-z]) (? =.*[!@#$%^&]). {
10,} "; String regex = "^ (?!) [0-9]+$] (?!)
[a-za-z]+$) [a-za-z0-9@#$%]{8,16}$];
35 is because the array is starting from 0, 26 letters + 10 digits final int maxnum = 26; int i; generated random number int count = 0; The length of the generated password char[] str = {' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' g ', ' h ', ' I ', ' j ', ' K ', ' l ', ' m ', ' n ', ' o ', ' P ', ' Q ', ' R ', ' s ', ' t
', ' u ', ' V ', ' w ', ' x ', ' y ', ' z '}; Char[] Upchar = {' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' O ', ' P ', ' Q ', ' R ', ' S ', ' T ', ' U ',
' V ', ' W ', ' X ', ' Y ', ' Z '};
Char[] NumChar = {' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 '};
Char[] Spechar = {'! ', ' @ ', ' # ', ' $ ', '% '};
StringBuffer pwd = new StringBuffer ("");
Random r = new Random ();  while (Count < 2) {//Generate random number, take absolute value to prevent negative generation, I = Math.Abs (R.nextint (maxnum)); Str.length) {pwd.append (str[i]); count++;}
} count=0; while (Count < 2) {//Generate random numbers, take absolute values to prevent negative numbers from being generated, I = Math.Abs (R.nextint (7))
R.length) {pwd.append (upchar[i]); count++;}
count=0;  while (Count < 2) {//Generate random number, take absolute value to prevent negative generation, I = Math.Abs (R.nextint (maxnum));
Numchar.length) {pwd.append (numchar[i]); count++;}
count=0;  while (Count < 2) {//Generate random number, take absolute value to prevent negative generation, I = Math.Abs (R.nextint (maxnum));
Spechar.length) {pwd.append (spechar[i]); count++;}
return pwd.tostring (); }

Send SMS Interface: (jar package See attachment)

Reference:

Https://www.yuntongxun.com/doc/rest/sms/3_2_2_3.html

public class Sdktestsendtemplatesms {public static void main (string[] args) {hashmap<string, object> result = nul 
L
CCPRESTSDK Restapi = new Ccprestsdk ();
Restapi.init ("app.cloopen.com", "8883"); 
Initialize the server address and port, the production environment is configured to app.cloopen.com, and the port is 8883.
Restapi.setaccount ("Accountsid", "Accounttoken");
Initialize the master account name and the main account token, after landing Cloud communication website, can in "console-application" to see the developer account SID and the main account token auth TOKEN.
Restapi.setappid ("AppId");
Initialize the application ID and, if it is developed in the sandbox environment, configure the AppID in the console-application-test demo.
If you switch to a production environment, use appid result = Restapi.sendtemplatesms ("Number 1, number 2, etc", "template id", new string[]{"template content 1", "Template content 2"}) that you created the application with. 
System.out.println ("sdktestgetsubaccounts result=" + result); if ("000000". Equals (Result.get ("StatusCode")) {//Normal return output data package information (map) hashmap<string,object> data = (HashMap
<string, object>) result.get ("Data");
Set<string> keyset = Data.keyset (); 
for (String key:keyset) {object = Data.get (key); 
SYSTEM.OUT.PRINTLN (key + "=" +object); }else{//Exception returns output error code and error message System.out.println ("Error code =" + Result.get ("statuscOde ") +" error message = "+result.get (" statusmsg "));}} 

The above is a small series to introduce to you through the Third-party interface to send SMS authentication code/SMS notice (recommended), I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.