Joke Collection Website - Public benefit messages - Java programming verification code sent to mobile phone
Java programming verification code sent to mobile phone
& lt%!
Color get randcolor (int fc, int BC){// Get random colors in a given range.
Random Random = new Random();
if(fc & gt; 255)fc = 255;
if(BC & gt; 255)BC = 255;
int r = fc+random . nextint(BC-fc);
int g = fc+random . nextint(BC-fc);
int b = fc+random . nextint(BC-fc);
Returns a new color (r, g, b);
}
% & gt
& lt%
//Set the page not to be cached.
Response.setHeader("Pragma ","no cache ");
response . set header(" Cache-Control "," no-Cache ");
response . setdate header(" Expires ",0);
//Create an image in memory
int width=60,height = 20
BufferedImage image = new buffered image (width, height, buffered image. TYPE _ INT _ RGB);
//Get the graphic context
graphics g = image . get graphics();
//Generate a random class
Random Random = new Random();
//Set the background color
g.setColor(getRandColor(200,250));
g.fillRect(0,0,width,height);
//Set the font
G.setFont ("Times New Roman", font. Plain,18));
//Draw a border
//g . set Color(new Color());
//g.drawRect(0,0,width- 1,height- 1);
// 155 interference lines are randomly generated, which makes the authentication code in the image difficult to be detected by other programs.
g . set color(getRandColor( 160,200));
for(int I = 0; I< 155; i++)
{
int x = random . nextint(width);
int y = random . nextint(height);
int XL = random . nextint( 12);
int yl = random . nextint( 12);
g.drawLine(x,y,x+xl,y+yl);
}
//Take the randomly generated authentication code (4 digits)
//String rand = request . getparameter(" rand ");
//rand = rand.substring(0,rand.indexOf(" . "));
String sRand =
for(int I = 0; I<4; i++){
string rand = string . value of(random . nextint( 10));
sRand+= rand;
//Display the verification code in the image.
g . set Color(new Color(20+random . nextint( 1 10),20+random . nextint( 1 10),20+random . nextint( 1 10))); //The calling functions are all the same color, probably because the seeds are too close, so they can only be generated directly.
G. rope drawing (rand, 13*i+6,16);
}
//Store the authentication code in the session.
session.setAttribute("ccode ",sRand);
//Image takes effect
g . dispose();
//Output the image to the page
ImageIO.write(image," JPEG ",response . get output stream());
% & gt
- Related articles
- How to solve the problem of always receiving loan text messages
- Weekend blessing SMS at the end of April
- Valentine's Day messages to your boyfriend
- What procedures do merchants need to join Meituan Takeout or Ele.me? How do Meituan and Ele.me charge merchants after joining?
- Can mobile companies recover the text of short messages?
- Shall I call you to get the health certificate when it is ready? If not, can I get it in a few days?
- Will Changhanghua call the company after the deadline?
- Apple's mobile phone often turns on low battery mode, will it affect the battery? What problems should we pay attention to?
- What does Wechat mean to eliminate pornography?
- Why didn't China Merchants Securities have a reverse page on Saturday and Sunday?