java发送验证码的代码 java编写验证码

Java短信验证码功能怎么实现?实现jiava短信验证码可以按下面java发送验证码的代码的步奏进行java发送验证码的代码:
1、首先java发送验证码的代码,找到一个支持Java语言的接口短信平台 。
2、接着下载接口文档java发送验证码的代码,和自己的开发平台进行对接 。
3、注意在对接之前测试一下短信的速度java发送验证码的代码,一旦对接好想换就比较麻烦,之前就吃过这个亏,最后有个朋友介绍我去短信网 。
4、如果要购买的话,一定要多测试几家 。
如果在碰到有疑问的地方一定要和技术或者客服多多沟通 。
java怎么实现群发短信的功能JAVA实现短信群发的步骤:
1、使用第三方短信平台服务商java发送验证码的代码,接入短信服务;
2、调用短信提交页面发送请求;
3、服务器向第三方短信平台提交发送请求;
4、短信平台通过运营商将短信下发至用户的手机上 。
以下是秒赛短信平台JAVA短信验证码接口代码示例
package test;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.lang3.StringUtils;
public class Apis {
// 短信发送接口的http地址java发送验证码的代码,请咨询客服
private static String url = “xxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
// 编码格式 。发送编码格式统一用UTF-8
private static String ENCODING = “UTF-8”;
public static void main(String[] args) throws IOException, URISyntaxException {
// 账号
String account = “************************”;
// 密码
String pswd = “************************”;
// 修改为您要发送的手机号java发送验证码的代码,多个用java发送验证码的代码,分割
String mobile = “13*********”;
// 设置您要发送的内容
String msg = “【秒赛科技】您的验证码是:1234”;
// 发短信调用示例
System.out.println(Apis.send(account,pswd, mobile, msg));
}
/**
* 发送短信
*
* @param account
*account
* @param pswd
*pswd
* @param mobile
*手机号码
* @param content
*短信发送内容
*/
public static String send(String account,String pswd, String mobile, String msg) {
NameValuePair[] data = https://www.04ip.com/post/{ new NameValuePair(“account”, account),
new NameValuePair(“pswd”, pswd),
new NameValuePair(“mobile”, mobile),
new NameValuePair(“msg”, msg),
new NameValuePair(“needstatus”, “true”),
new NameValuePair(“product”, “”) };
return doPost(url, data);
}
/**
* 基于HttpClient的post函数
* PH
* @param url
*提交的URL
*
* @param data
*提交NameValuePair参数
* @return 提交响应
*/
private static String doPost(String url, NameValuePair[] data) {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(url);
// method.setRequestHeader(“ContentType”,
// “application/x-www-form-urlencoded;charset=UTF-8”);
method.setRequestBody(data);
// client.getParams() 。setContentCharset(“UTF-8”);
client.getParams() 。setConnectionManagerTimeout(10000);
try {
client.executeMethod(method);
return method.getResponseBodyAsString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
验证码 代码java发送验证码的代码你在java发这个问题java发送验证码的代码!java发送验证码的代码我就把java 的验证码源码给你 。
tr
tdfont color="#FFFFFF"验证码java发送验证码的代码:/font/td
td width="22%"input type="text" name="randomcode" class='input' size='4' maxlength="8" style="width:50px;height:18px"onKeyDown="if (event.keyCode==13)submitLogin();"
/td
td width="48%"img src="https://www.04ip.com/post/showradomcode.jsp"/td
/tr
文件二java发送验证码的代码:showradomcode.jsp
%@ page contentType="image/jpeg" import="java.awt.image.*,javax.imageio.*" %jsp:useBean id="rc" class="com.hanweb.sso.ldap.util.RandomChar" scope="page"/%
//设置页面不缓存
//response.reset();
response.setContentType("image/jpeg");
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
//在内存中创建图象宽60 高18 4个字符 0条干扰线
BufferedImage image = rc.getRandomImage(58, 18, 4, 1);
//设置其session值
session.setAttribute("jcmsrandomchar", rc.getRandomString());
session.setMaxInactiveInterval(100000000);
ImageIO.write(image, "JPEG", response.getOutputStream());
%
文件三:RandomChar.java
package com.hanweb.sso.ldap.util;
/**
* Title: 随机码图形生成程序的处理 Description:
* 为了加强网络安全,防止黑课工具对系统的攻击,现在通用随机码来解决这个问题,因为每一次产生的随机码是随机的,所以使用穷举法破解密码的工具就无能为力了
* Copyright: Copyright (c) 2004-2010 Company: SDLDAP
*
* @author LiChanglai
* @version 1.0
*/
import java.util.*;
import java.awt.*;
import java.awt.image.*;
public class RandomChar {
/**
* 给定范围获得随机颜色
*
* @param fc
*int 参数1
* @param bc
*int 参数2
* @return Color 返回的color对象
*/
private String strRandomString; // 生成的随机数
/**
* 取其生成的随机数
*
* @return String
*/
public String getRandomString() {
return strRandomString;
}
/**
* 设置其生成的随数
*
* @param randomString
*String
*/
public void setRandomString(String randomString) {
this.strRandomString = randomString;
}
/**
* 取其某一范围的color
*
* @param fc
*int 范围参数1
* @param bc
*int 范围参数2
* @return Color
*/
private Color getRandColor(int fc, int bc) {
// 取其随机颜色
Random random = new Random();
if (fc255) {
fc = 255;
}
if (bc255) {
bc = 255;
}
int r = fcrandom.nextInt(bc - fc);
int g = fcrandom.nextInt(bc - fc);
int b = fcrandom.nextInt(bc - fc);
return new Color(r, g, b);
}
/**
* 用于生成其随机数
*
* @param randomCount
*int 随机数总长度
* @return String 返回的随机数
*/
private String getRandomString(int nRandomCount) {
/*
* String[] a = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
* "B", "C", "D", "E", "F", "G", "H", "I", "G", "K", "L", "M", "N", "O",
* "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "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" };
*/
String[] a = { "a", "b", "c", "d", "e", "f", "g", "h", "g", "k", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
String strRand = "";
int nRand;
// 取其随机数的总数
int LengthOfRandom = a.length;
// 生成随机类
Random random = new Random();
// 循环取随机取其整数,并将其整数所对应的结果进行累加
for (int i = 0; inRandomCount; i) {
nRand = random.nextInt(LengthOfRandom);
strRand= a[nRand];
}
// 返回累加后的结果
return strRand;
}
/**
* 生成其随机的图形
*
* @param width
*int 生成图形的宽度
* @param height
*int 生成图形的高度
* @param nLengthOfRandom
*int 随机码的个数
* @param nDisturbLineCount
*int 干扰线的条数
* @return BufferedImage
*/
public BufferedImage getRandomImage(int nWidth, int nHeight,
int nLengthOfRandom, int nDisturbLineCount)
{
// 在内存中创建图象
BufferedImage image = new BufferedImage(nWidth, nHeight,
BufferedImage.TYPE_INT_RGB);
// 获取图形上下文
Graphics g = image.getGraphics();
String strRand = "";
nLengthOfRandom = (nLengthOfRandom = 0) ? 6 : nLengthOfRandom;
nDisturbLineCount = (nDisturbLineCount = 0) ? 0 : nDisturbLineCount;
// 生成随机类
Random random = new Random();
// 设定背景色
g.setColor(getRandColor(200, 250));
g.fillRect(0, 0, nWidth, nHeight);
// 设定字体
g.setFont(new Font("Times New Roman", Font.PLAIN, 16));
// 画边框
g.setColor(new Color(255, 255, 255));
g.drawRect(0, 0, nWidth - 1, nHeight - 1);
// 随机产生nDisturbLineCount条干扰线 , 使图象中的认证码不易被其它程序探测到
g.setColor(getRandColor(160, 200));
for (int i = 0; inDisturbLineCount; i) {
int x = random.nextInt(nWidth);
int y = random.nextInt(nHeight);
int xl = random.nextInt(12);
int yl = random.nextInt(12);
g.drawLine(x, y, xxl, yyl);
}
// 取随机产生的认证码(6位)
strRand = this.getRandomString(nLengthOfRandom);
// 设置其属性randomString的值
this.strRandomString = strRand;
for (int i = 0; inLengthOfRandom; i) {
// 将认证码显示到图象中
g.setColor(new Color(20random.nextInt(110), 20random
.nextInt(110), 20random.nextInt(110)));
// 调用函数出来的颜色相同 , 可能是因为种子太接近,所以只能直接生成
g.drawString(strRand.substring(i, i1), 13 * i5, 14);
}
// 图象生效
g.dispose();
return image;
}
}
JAVAWEB项目怎么实现验证码import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Random;
import javax.imageio.ImageIO;
public class Code {
// 图片的宽度 。
private int width = 160;
// 图片的高度 。
private int height = 38;
// 验证码字符个数
private int codeCount = 4;
// 验证码干扰线数
private int lineCount = 20;
// 验证码
private String code = null;
// 验证码图片Buffer
private BufferedImage buffImg = null;
Random random = new Random();
private boolean type = false;
public Code() {
}
public Code(int width, int height) {
this.width = width;
this.height = height;
}
public Code(int width, int height, int codeCount) {
this.width = width;
this.height = height;
this.codeCount = codeCount;
}
public Code(int width, int height, int codeCount, int lineCount) {
this.width = width;
this.height = height;
this.codeCount = codeCount;
this.lineCount = lineCount;
}
public void init(boolean type){
this.type = type;
}
// 生成图片
private void creatImage(boolean type) {
int fontWidth = width / codeCount;// 字体的宽度
int fontHeight = height - 5;// 字体的高度
int codeY = height - 8;
// 图像buffer
buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = buffImg.getGraphics();
//Graphics2D g = buffImg.createGraphics();
// 设置背景色
g.setColor(getRandColor(200, 250));
g.fillRect(0, 0, width, height);

// 设置字体
Font font = null;
if(!type) font = new Font("Fixedsys", Font.BOLD, fontHeight);
else font = getFont(fontHeight);
g.setFont(font);
// 设置干扰线
for (int i = 0; ilineCount/2; i) {
int xs = random.nextInt(width);
int ys = random.nextInt(height);
int xe = xsrandom.nextInt(width);
int ye = ysrandom.nextInt(height);
g.setColor(getRandColor(1, 255));
if(!type) g.drawLine(xs, ys, xe, ye);
else shear(g, width, height, getRandColor(1, 255)) ;
}
// 添加噪点
float yawpRate = 0.01f;// 噪声率
int area = (int) (yawpRate * width * height);
for (int i = 0; iarea; i) {
int x = random.nextInt(width);
int y = random.nextInt(height);
buffImg.setRGB(x, y, random.nextInt(255));
}
String str1 = randomStr(codeCount);// 得到随机字符
this.code = str1;
for (int i = 0; icodeCount; i) {
String strRand = str1.substring(i, i1);
g.setColor(getRandColor(1, 255));
// g.drawString(a,x,y);
// a为要画出来的东西,x和y表示要画的东西最左侧字符的基线位于此图形上下文坐标系的 (x, y) 位置处
g.drawString(strRand, i*fontWidth 3, codeY);
}
}
// 得到随机字符
private String randomStr(int n) {
String str1 = "ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz1234567890";//I和l不要
String str2 = "";
int len = str1.length() - 1;
double r;
for (int i = 0; in; i) {
r = (Math.random()) * len;
str2 = str2str1.charAt((int) r);
}
return str2;
}
// 得到随机颜色
private Color getRandColor(int fc, int bc) {// 给定范围获得随机颜色
if (fc255)
fc = 255;
if (bc255)
bc = 255;
int r = fcrandom.nextInt(bc - fc);
int g = fcrandom.nextInt(bc - fc);
int b = fcrandom.nextInt(bc - fc);
return new Color(r, g, b);
}
/**
* 产生随机字体
*/
private Font getFont(int size) {
Random random = new Random();
Font font[] = new Font[5];
font[0] = new Font("Ravie", Font.PLAIN, size);
font[1] = new Font("Antique Olive Compact", Font.PLAIN, size);
font[2] = new Font("Fixedsys", Font.PLAIN, size);
font[3] = new Font("Wide Latin", Font.PLAIN, size);
font[4] = new Font("Gill Sans Ultra Bold", Font.PLAIN, size);
return font[random.nextInt(5)];
}
// 扭曲方法
private void shear(Graphics g, int w1, int h1, Color color) {
shearX(g, w1, h1, color);
shearY(g, w1, h1, color);
}
private void shearX(Graphics g, int w1, int h1, Color color) {
int period = random.nextInt(2);
boolean borderGap = true;
int frames = 1;
int phase = random.nextInt(2);
for (int i = 0; ih1; i) {
double d = (double) (period1)
* Math.sin((double) i / (double) period
(6.2831853071795862D * (double) phase)
/ (double) frames);
g.copyArea(0, i, w1, 1, (int) d, 0);
if (borderGap) {
g.setColor(color);
g.drawLine((int) d, i, 0, i);
g.drawLine((int) dw1, i, w1, i);
}
}
}
private void shearY(Graphics g, int w1, int h1, Color color) {
int period = random.nextInt(40)10; // 50;
boolean borderGap = true;
int frames = 20;
int phase = 7;
for (int i = 0; iw1; i) {
double d = (double) (period1)
* Math.sin((double) i / (double) period
(6.2831853071795862D * (double) phase)
/ (double) frames);
g.copyArea(i, 0, 1, h1, 0, (int) d);
if (borderGap) {
g.setColor(color);
g.drawLine(i, (int) d, i, 0);
g.drawLine(i, (int) dh1, i, h1);
}
}
}
public void write(OutputStream sos) throws IOException {
if(buffImg == null) creatImage(type);
ImageIO.write(buffImg, "png", sos);
//JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sos);
//encoder.encode(buffImg);
sos.close();
}
public BufferedImage getBuffImg() {
if(buffImg == null) creatImage(type);
return buffImg;
}
public String getCode() {
return code.toLowerCase();
}
//使用方法
/*public void getCode3(HttpServletRequest req, HttpServletResponse response,HttpSession session) throws IOException{
// 设置响应的类型格式为图片格式
response.setContentType("image/jpeg");
//禁止图像缓存 。
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);

CreateImageCode vCode = new CreateImageCode(100,30,5,10);
session.setAttribute("code", vCode.getCode());
vCode.write(response.getOutputStream());
response.flushBuffer();
}*/
}
发web网站中注册页面发送手机短信验证码功能的java代码实现说个流程吧
1.去移动或者电信申请一个web接口
2.客户填写请求输入手机号码提交
3.调申请java发送验证码的代码的接口吧(注意给个对方(电信或者移动)的回调地址吧)
4.从回调地址里拿客户输入的数据java发送验证码的代码了java发送验证码的代码,判断数据java发送验证码的代码了
5.返回数据给客户了
纯属个人理解
java 中怎样发送验证码发完以后,等一分钟后才能再发 。这种功能怎样实现,高手解答 。。。谢谢使用cookie或session存储当前发送的时间 , 等下次再发送的时候就直接提示等一分钟后才能发,javascript等客户端脚本是不能实现该功能的,至于代码吗,嘻嘻,您这个分也有点...,这个 , 这个 。。。
【java发送验证码的代码 java编写验证码】关于java发送验证码的代码和java编写验证码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读