Requirements: Change the first delivery password to the public default password to the click-on function, and send the eight passwords automatically generated by the system with numbers, upper and lowercase letters and special symbols. The SMS sending service is provided by Cloud Communication http://www.yuntongxun.com/.
Random password generation method:
/*** Generate the instant password* @author chaos.gao* @param pwd_len Total length of the generated password* @return The string of the password*/public static String genRandomNum(int pwd_len) {// String re="(?=.*/d)(?=.*[az])(?=.*[AZ])(?=.*[!@#$%^&]).{10,}";String regex = "^(?![0-9]+$)(?![a-zA-Z]+$)[A-Za-z0-9@#$%]{8,16}$";//35 is because the array starts from 0, 26 letters + 10 numbers final int maxNum = 26;int i; //The 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 numbers, take absolute values, and prevent negative numbers, i = Math.abs(r.nextInt(maxNum)); //The maximum generated number is 36-1if (i >= 0 && i < str.length) {pwd.append(str[i]);count++;}}count=0;while (count < 2) {//Generate random numbers, take absolute values, and prevent negative numbers, i = Math.abs(r.nextInt(7)); //The maximum generated number is 7-1if (i >= 0 && i < upChar.length) {pwd.append(upChar[i]);count++;}}count=0;while (count < 2) {//Generate random numbers, take absolute values, and prevent negative numbers, i = Math.abs(r.nextInt(maxNum)); //The maximum generated number is 10-1if (i >= 0 && i < numChar.length) {pwd.append(numChar[i]);count++;}}count=0;while (count < 2) {//Generate random numbers, take absolute values, and prevent negative numbers, i = Math.abs(r.nextInt(maxNum)); //The maximum generated number is 10-1if (i >= 0 && i < speChar.length) {pwd.append(speChar[i]);count++;}} return pwd.toString();}Send SMS interface: (see attachment for jar package)
refer to:
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 = null; CCPRestSDK restAPI = new CCPRestSDK();restAPI.init("app.cloopen.com", "8883");// Initialize the server address and port, configure the production environment to app.cloopen.com, and the port is 8883. restAPI.setAccount("accountSid", "accountToken");// Initialize the main account name and main account token. After logging into the cloud communication website, you can see the developer's main account ACCOUNT SID and main account token AUTH TOKEN in the "Console-Application". restAPI.setAppId("AppId");// Initialize the application ID. If it is developed in a sandbox environment, please configure the APPID in "Console-App-Test DEMO". //If you switch to the production environment, please use the APPIDresult of the application you created by yourself = restAPI.sendTemplateSMS("Number 1, No. 2, etc.", "TemplateId" , new String[]{"Template Content 1","Template Content 2"});System.out.println("SDKTestGetSubAccounts result=" + result); if("0000000".equals(result.get("statusCode"))){//Return the output data package information normally (map) HashMap<String,Object> data = (HashMap<String, Object>) result.get("data");Set<String> keySet = data.keySet();for(String key:keySet){ Object object = data.get(key); System.out.println(key +" = "+object); }}else{//Exception returns the output error code and error message System.out.println("Error code=" + result.get("statusCode") +" Error message = "+result.get("statusMsg"));}}}The above is what the editor introduced to you to send SMS verification code/SMS notification (recommended) through a third-party interface. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!