1. 注册软件账号;
2. 打开软件添加项目;
3. 进入主界面搜索项目关键词;
4. 然后选择好地区等点击获取号码;
5. 最后只要等待结果就可以了,自动接收的;
.版本 2.子程序 生成验证码, 文本型, , 在指定画板上画出验证码并返回验证码
.参数 画板, 画板, , 要画验证码的画板
.参数 长度, 整数型, , 验证码的长度
.参数 类型, 整数型, 可空, 验证码的类型,1是数字,2是字母,3是数字+字母,其他是随机选择
.局部变量 验证码, 文本型
.局部变量 计次, 整数型
.局部变量 计次2, 整数型
.局部变量 横, 整数型
.局部变量 随机数字, 文本型
.局部变量 随机字母, 文本型
.局部变量 随机数字加字母, 文本型
.如果真 (长度 > 0)
画板.清除 (, , , )
画板.字体.字体大小 = 取随机数 (20, 23)
置随机数种子 ()
.计次循环首 (长度, )
随机数字 = 随机数字 + 到文本 (取随机数 (0, 9))
.计次循环尾 ()
.计次循环首 (长度, )
随机字母 = 随机字母 + 选择 (取随机数 (1, 2) = 1, 到大写 (字符 (取随机数 (97, 122))), 字符 (取随机数 (97, 122)))
.计次循环尾 ()
.计次循环首 (长度, )
随机数字加字母 = 随机数字加字母 + 选择 (取随机数 (1, 2) = 1, 取文本中间 (随机数字, 取随机数 (1, 长度), 1), 取文本中间 (随机字母, 取随机数 (1, 长度), 1))
.计次循环尾 ()
验证码 = 多项选择 (选择 (类型 > 0 且 类型 < 4, 类型, 取随机数 (1, 3)), 随机数字, 随机字母, 随机数字加字母)
.如果真结束
.计次循环首 (画板.宽度, 计次)
.如果真 (取随机数 (1, 3) = 1)
.计次循环首 (画板.高度, 计次2)
.如果真 (取随机数 (1, 10) = 1)
画板.画点 (计次, 计次2, 取颜色值 (取随机数 (0, 255), 取随机数 (0, 255), 取随机数 (0, 255)))
.如果真结束
.计次循环尾 ()
.如果真结束
.计次循环尾 ()
.如果真 (长度 > 0)
.计次循环首 (长度, 计次)
横 = 取随机数 (横 + 计次 × 3 + 5, 横 + 20 + 长度)
输出调试文本 (横, “”)
画板.文本颜色 = 取颜色值 (取随机数 (0, 255), 取随机数 (0, 255), 取随机数 (0, 255))
画板.字体.角度 = 取随机数 (0, 500)
画板.定位写出 (横, 取随机数 (23, 画板.高度 - 23), 取文本中间 (验证码, 计次, 1))
.计次循环尾 ()
.如果真结束
返回 (验证码)
做一个公共类,或者公共页面,专门用来生成 随机码,每次提取一组,存入Session ,生成验证码图片。调用时将输入的值与存入的值对比即可。点击刷新验证码就是重新获取生成一次,重新存入Session。。private void CreateCheckCode()
{
string checkCode = GetRandWord(5)
Response.Cookies.Add(new HttpCookie("CheckCode", checkCode))
CreateCheckImage(checkCode)
}
/// <summary>
/// 生成验证码图片
/// </summary>
/// <param name="checkCode"></param>
private void CreateCheckImage(string checkCode)
{
if ((checkCode != null) &&!(checkCode.Trim() == string.Empty))
{
Bitmap image = new Bitmap((int)Math.Ceiling((double)(checkCode.Length * 12.5)), 0x14)
Graphics g = Graphics.FromImage(image)
try
{
int i
Random random = new Random()
g.Clear(Color.White)
for (i = 0i <0x19i++)
{
int x1 = random.Next(image.Width)
int x2 = random.Next(image.Width)
int y1 = random.Next(image.Height)
int y2 = random.Next(image.Height)
g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2)
}
Font font = new Font("Arial", 12f, FontStyle.Italic | FontStyle.Bold)
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true)
g.DrawString(checkCode, font, brush, (float)2f, (float)2f)
for (i = 0i <100i++)
{
int x = random.Next(image.Width)
int y = random.Next(image.Height)
image.SetPixel(x, y, Color.FromArgb(random.Next()))
}
g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1)
MemoryStream ms = new MemoryStream()
image.Save(ms, ImageFormat.Gif)
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.ContentType = "image/Gif"
HttpContext.Current.Response.BinaryWrite(ms.ToArray())
}
finally
{
g.Dispose()
image.Dispose()
}
}
}
/// <summary>
/// 随机数
/// </summary>
/// <param name="length">长度</param>
/// <returns></returns>
private static string GetRandWord(int length)
{
string checkCode = string.Empty
Random random = new Random()
for (int i = 0i <lengthi++)
{
char code
int number = random.Next()
if ((number % 2) == 0)
{
code = (char)(0x30 + ((ushort)(number % 10)))
}
else
{
code = (char)(0x41 + ((ushort)(number % 0x1a)))
}
checkCode = checkCode + code.ToString()
}
return checkCode
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)