Joke Collection Website - Public benefit messages - Send verification code to mobile phone number

Send verification code to mobile phone number

Build a utlls

Package com.itjh.util;

import org . Apache . commons ./web _ API/";

/**

* @param Uid SMS user id? : Lu Fang 123

* @param Key interface key: SMS login (non-login password) can be checked.

* @param sendPhoneNum SMS sending destination number

* @param desc SMS content

* @return Integer( 1: success code, other failures, see comments).

*/

Public static Integersend (string Uid, string Key, string sendPhoneNum, string desc){

http client client = new http client();

post method post = new post method(SMS _ Url);

post . addrequestheader(" Content-Type "," application/x-www-form-urlencoded; charset = gbk "); //Set transcoding in the header file

//Set parameters

Name value pair [] data = {

A new name-value pair ("Uid", Uid),

New name-value pair ("Key", Key),//key

The new NameValuePair("smsMob ",sendPhoneNum),

New name-value pair ("smsText", desc)

};

Post.setRequestBody (data);

Try {

client . execute method(post);

}catch (exception e) {? e . printstacktrace(); ? }

header[]headers = post . getresponse headers();

int status code = post . getstatus code();

system . out . println(" status code:"+status code);

for (Header h :headers) {

system . out . println(h . tostring());

}

String result = "";

Try {

Result = new string (post.getResponseBodyAsString ()). getBytes(" gbk "));

}catch (exception e) {? e . printstacktrace(); ? }

post . release connection();

Returns Integer.parseInt (result);

}

/**

*? - 1? No user account.

-2 The incorrect interface key [View Key] is not the account login password.

-2 1 MD5 interface key encryption is incorrect.

-3 The number of short messages is insufficient.

-1 1 User is disabled.

-14 illegal characters appear in the short message content.

-4 The format of mobile phone number is incorrect.

-4 1 Mobile phone number does not exist.

-42 SMS content is empty

-5 1 SMS signature format is incorrect. Interface signature format is: signature content.

-6 IP restriction

The number of messages sent is greater than 0.

As a supplement.

*/

Public static StringgetMessage (integer code)

Stringmessage

If (code & gt0) {

Message ="SMS-f sent successfully! There is a "+code+"message;

}else if(code == - 1){

Message ="SMS- no user account ";

}else if(code == -2){

Message ="SMS- incorrect interface key ";

}else if(code == -2 1){

Message ="SMS-MD5 interface key encryption is incorrect ";

}else if(code == -3){

Message ="SMS- SMS is insufficient ";

} else if(code = =- 1 1){

Message ="SMS- user is disabled ";

}else if(code == - 14){

Message ="SMS- illegal characters appear in the short message content ";

}else if(code == -4){

Message ="SMS- Incorrect phone number format ";

}else if(code == -4 1){

Message ="SMS- mobile phone number is empty ";

}else if(code == -42){

Message ="SMS- SMS content is empty ";

}else if(code == -5 1){

Message ="SMS- SMS signature format is incorrect. Interface signature format is: signature content ";

}else if(code == -6){

Message ="SMS-IP restriction ";

} Otherwise {

Message = "Other error";

}

Return message;

}

/**

* randomly generate 6-digit verification code

* @ Return

*/

Public static StringgetRandomCode (integer code) (

Random Random = new Random();

StringBufferresult = new string buffer();

for(int I = 0; I

result . append(random . nextint( 10));

}

Returns result. tostring ();

}

Public static StringgetRandomCode(){

Random Random = new Random();

String result = "";

for(int I = 0; I<6; i++){

result+= random . nextint( 10);

}

Return the result;

}

Public void testSendMessage(){

// SendMessageUtil.send ("SMS account", "interface key", "target number" and "sending content");

//Name, key and mobile phone number

Sendmessageutil.send ("jimingyu ","d4 1d8cd98f00b 204e980 ","15226921418 ","Verification code: "+getRandomCode (6

IntegerresultCode = 1;

system . out . println(sendmessage util . getmessage(result code));

}

}

Configuration file pom.xml

Public logging

Public logging

1. 1. 1

Universal codec

Universal codec

1.4

commons-/User/? Action = key