public class getrandompictrue extends baseaction implements ignoreaction// 將生成的字母存入到session中
servletactioncontext.getrequest().getsession().setattribute("checkcode", sb.tostring());
// 步驟五 繪製干擾線
graphics.setcolor(getrandcolor(160, 200));
int x1;
int x2;
int y1;
int y2;
for (int i = 0; i < 30; i++)
// 將上面輸出到瀏覽器 imageio
graphics.dispose();// 釋放資源
try catch (ioexception e)
return none;
} /**
* 功能:設定第一種驗證碼的屬性
*/
public void initnumverificationcode(bufferedimage image)
this.setstr(srand);/* 賦值驗證碼 */
// 圖象生效
g.dispose();
this.setimage(drawimage(image));
} /**
* 功能:設定第二種驗證碼屬性
*/
public void initletterandnumverificationcode(bufferedimage image) ;
string srand = "";
for (int i = 0; i < 4; i++) else
} srand += temprand;
g.setcolor(new color(20 + random.nextint(10), 20 + random
.nextint(110), 20 + random.nextint(110)));
g.drawstring(temprand, 13 * i + 6, 16);
} this.setstr(srand);/* 賦值驗證碼 */
g.dispose(); // 圖象生效
this.setimage(drawimage(image));
} /**
* 功能:設定第三種驗證碼屬性 即:肆+?=24
*/
public void initchineseplusnumverificationcode(bufferedimage image) ;
random random = new random(); // 生成隨機類
graphics g = initimage(image, random);
int x = random.nextint(10) + 1;
int y = random.nextint(30);
this.setstr(string.valueof(y));
g.setfont(new font("楷體", font.plain, 14));// 設定字型
g.setcolor(new color(20 + random.nextint(10), 20 + random.nextint(110),
20 + random.nextint(110)));
g.drawstring(cn[x - 1], 1 * 1 + 6, 16);
g.drawstring("+", 22, 16);
g.drawstring("?", 35, 16);
g.drawstring("=", 48, 16);
g.drawstring(string.valueof(x + y), 61, 16);
g.dispose(); // 圖象生效
this.setimage(drawimage(image));
} public graphics initimage(bufferedimage image, random random)
return g;
} public bytearrayinputstream drawimage(bufferedimage image) catch (exception e)
return input;
} /*
* 功能:給定範圍獲得隨機顏色
*/
private color getrandcolor(int fc, int bc)
/**
* 功能:獲取驗證碼的字串值
* * @return
*/
public string getverificationcodevalue()
/**
* * @return
*/
public bytearrayinputstream getimage()
public string getstr()
public void setstr(string str)
public void setimage(bytearrayinputstream image)
private void mian()
}
工具類 傳送簡訊驗證碼
傳送簡訊驗證碼 很簡單的乙個移動端傳送簡訊驗證碼的功能,驗證碼生成及傳送 第三方介面 都是後台完成,本文內容只是從前端通過js傳送請求。var time 30 var interval btnsendverifiedcode click function test cellphone ajax be...
PHP驗證碼類
php驗證碼類 如果不適用指定的字型,那麼就用imagestring 函式,如果需要遇到指定的字型,就要用到imagettftext 函式。字型的位置在c盤下windows fonts.verificationcode.class.php class verificationcode 生成驗證碼 p...
GD 驗證碼類
1 建立畫布 2 干擾 3 文字 4 輸出 5 釋放資源 class code 定有出口程式 function printimage 1 建立畫布 背景色淺色 顏色隨機 private function bg 2 干擾 private function disturb 10條隨機出現的線 for i...