java手機驗證碼注冊
❶ java web 發送驗證碼到手機功能怎麼實現
你不去找經銷商申請介面有代碼也沒用
❷ java注冊 發過來的手機驗證碼怎麼獲得
假如注冊的電話是 13000000000
用戶點擊注冊後,後台生成一個6位的隨機數,保存到資料庫,並且將該版驗證碼,調用短權信介面,發送給該手機號!接下來用戶填寫收到的驗證碼,並且進行驗證(匹配資料庫存的驗證碼,以及該驗證碼是否失效)!
❸ 手機簡訊驗證碼java介面怎麼寫
這個首先你要確定一下簡訊平台,他們會給你提供簡訊實現的介面文檔。
比如:
public static String doPost(String reqUrl, Map parameters, String recvEncoding)
{
HttpURLConnection url_con = null;
String responseContent = null;
try
{
StringBuffer params = new StringBuffer();
Iterator iter = parameters.entrySet().iterator();
while (iter
.hasNext())
{
Map.Entry element = (Map.Entry)iter.next();
params.append(element.getKey().toString());
params.append("=");
params.append(URLEncoder.encode(element.getValue().toString(),
requestEncoding));
params.append("&");
}
if (params.length() > 0)
{
params = params.deleteCharAt(params.length() - 1);
}
URL url = new URL(reqUrl);
url_con = (HttpURLConnection)url.openConnection();
url_con.setRequestMethod("POST");
System.setProperty("sun.net.client.defaultConnectTimeout",
String.valueOf(connectTimeOut));
System.setProperty("sun.net.client.defaultReadTimeout",
String.valueOf(readTimeOut));
url_con.setDoOutput(true);
byte[] b = params.toString().getBytes();
url_con.getOutputStream().write(b, 0, b.length);
url_con.getOutputStream().flush();
url_con.getOutputStream().close();
InputStream in = url_con.getInputStream();
BufferedReader rd = new BufferedReader(
new InputStreamReader(in,
recvEncoding));
String tempLine = rd.readLine();
StringBuffer tempStr = new StringBuffer();
String crlf = System.getProperty("line.separator");
while (tempLine != null)
{
tempStr.append(tempLine);
tempStr.append(crlf);
tempLine = rd.readLine();
}
responseContent = tempStr.toString();
rd.close();
in.close();
}
catch (IOException localIOException)
{
}
finally
{
if (url_con != null)
{
url_con.disconnect();
}
}
return responseContent;
}
public static String sendTelCode(String mobile,String telcode){
Map<String ,String> map = new HashMap<String ,String>();
map.put("account", "Babo");
map.put("mobile", mobile);
map.put("pswd", "D3dddD");
try {
map.put("msg", java.net.URLEncoder.encode("您的驗證碼是"+telcode+",若非本人操作請忽略","utf-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String getValue = doPost("http://www.ibabo.cn:7788/msg/HttpSendSM", map, "UTF-8");
System.out.println(getValue);
return getValue;
}
❹ Java如何實現驗證碼驗證功能
Java如何實現驗證碼驗證功能呢?日常生活中,驗證碼隨處可見,他可以在一定程度上保護賬號安全,那麼他是怎麼實現的呢?
Java實現驗證碼驗證功能其實非常簡單:用到了一個Graphics類在畫板上繪制字母,隨機選取一定數量的字母隨機生成,然後在畫板上隨機生成幾條干擾線。
首先,寫一個驗證碼生成幫助類,用來繪制隨機字母:
importjava.awt.Color;
importjava.awt.Font;
importjava.awt.Graphics;
importjava.awt.image.BufferedImage;
importjava.io.IOException;
importjava.io.OutputStream;
importjava.util.Random;
importjavax.imageio.ImageIO;
publicfinalclassGraphicHelper{
/**
*以字元串形式返回生成的驗證碼,同時輸出一個圖片
*
*@paramwidth
*圖片的寬度
*@paramheight
*圖片的高度
*@paramimgType
*圖片的類型
*@paramoutput
*圖片的輸出流(圖片將輸出到這個流中)
*@return返回所生成的驗證碼(字元串)
*/
publicstaticStringcreate(finalintwidth,finalintheight,finalStringimgType,OutputStreamoutput){
StringBuffersb=newStringBuffer();
Randomrandom=newRandom();
BufferedImageimage=newBufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphicsgraphic=image.getGraphics();
graphic.setColor(Color.getColor("F8F8F8"));
graphic.fillRect(0,0,width,height);
Color[]colors=newColor[]{Color.BLUE,Color.GRAY,Color.GREEN,Color.RED,Color.BLACK,Color.ORANGE,
Color.CYAN};
//在"畫板"上生成干擾線條(50是線條個數)
for(inti=0;i<50;i++){
graphic.setColor(colors[random.nextInt(colors.length)]);
finalintx=random.nextInt(width);
finalinty=random.nextInt(height);
finalintw=random.nextInt(20);
finalinth=random.nextInt(20);
finalintsignA=random.nextBoolean()?1:-1;
finalintsignB=random.nextBoolean()?1:-1;
graphic.drawLine(x,y,x+w*signA,y+h*signB);
}
//在"畫板"上繪制字母
graphic.setFont(newFont("ComicSansMS",Font.BOLD,30));
for(inti=0;i<6;i++){
finalinttemp=random.nextInt(26)+97;
Strings=String.valueOf((char)temp);
sb.append(s);
graphic.setColor(colors[random.nextInt(colors.length)]);
graphic.drawString(s,i*(width/6),height-(height/3));
}
graphic.dispose();
try{
ImageIO.write(image,imgType,output);
}catch(IOExceptione){
e.printStackTrace();
}
returnsb.toString();
}
}
接著,創建一個servlet,用來固定圖片大小,以及處理驗證碼的使用場景,以及捕獲頁面生成的驗證碼(捕獲到的二維碼與用戶輸入的驗證碼一致才能通過)。
importjava.io.OutputStream;
importjavax.servlet.ServletException;
importjavax.servlet.annotation.WebServlet;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importjavax.servlet.http.HttpSession;
@WebServlet(urlPatterns="/verify/regist.do")
{
=3398560501558431737L;
@Override
protectedvoidservice(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
//獲得當前請求對應的會話對象
HttpSessionsession=request.getSession();
//從請求中獲得URI(統一資源標識符)
Stringuri=request.getRequestURI();
System.out.println("hello:"+uri);
finalintwidth=180;//圖片寬度
finalintheight=40;//圖片高度
finalStringimgType="jpeg";//指定圖片格式(不是指MIME類型)
finalOutputStreamoutput=response.getOutputStream();//獲得可以向客戶端返回圖片的輸出流
//(位元組流)
//創建驗證碼圖片並返回圖片上的字元串
Stringcode=GraphicHelper.create(width,height,imgType,output);
System.out.println("驗證碼內容:"+code);
//建立uri和相應的驗證碼的關聯(存儲到當前會話對象的屬性中)
session.setAttribute(uri,code);
System.out.println(session.getAttribute(uri));
}
}
接著寫一個html注冊頁面用來檢驗一下:
<html>
<head>
<metacharset="UTF-8">
<title>注冊</title>
<linkrel="stylesheet"href="styles/general.css">
<linkrel="stylesheet"href="styles/cell.css">
<linkrel="stylesheet"href="styles/form.css">
<scripttype="text/javascript"src="js/ref.js"></script>
<styletype="text/css">
.logo-container{
margin-top:50px;
}
.logo-containerimg{
width:100px;
}
.message-container{
height:80px;
}
.link-container{
height:40px;
line-height:40px;
}
.link-containera{
text-decoration:none;
}
</style>
</head>
<body>
<divclass="containerform-container">
<formaction="/wen/regist.do"method="post">
<divclass="form"><!--注冊表單開始-->
<divclass="form-row">
<spanclass="cell-1">
<iclass="fafa-user"></i>
</span>
<spanclass="cell-11"style="text-align:left;">
<inputtype="text"name="username"placeholder="請輸入用戶名">
</span>
</div>
<divclass="form-row">
<spanclass="cell-1">
<iclass="fafa-key"></i>
</span>
<spanclass="cell-11"style="text-align:left;">
<inputtype="password"name="password"placeholder="請輸入密碼">
</span>
</div>
<divclass="form-row">
<spanclass="cell-1">
<iclass="fafa-keyboard-o"></i>
</span>
<spanclass="cell-11"style="text-align:left;">
<inputtype="password"name="confirm"placeholder="請確認密碼">
</span>
</div>
<divclass="form-row">
<spanclass="cell-7">
<inputtype="text"name="verifyCode"placeholder="請輸入驗證碼">
</span>
<spanclass="cell-5"style="text-align:center;">
<imgsrc="/demo/verify/regist.do"onclick="myRefersh(this)">
</span>
</div>
<divclass="form-row"style="border:none;">
<spanclass="cell-6"style="text-align:left">
<inputtype="reset"value="重置">
</span>
<spanclass="cell-6"style="text-align:right;">
<inputtype="submit"value="注冊">
</span>
</div>
</div><!--注冊表單結束-->
</form>
</div>
</body>
</html>
效果如下圖:
當點擊刷新頁面的時候,驗證碼也會隨著變化,但我們看不清驗證碼時,只要點擊驗證碼就會刷新,這樣局部的刷新可以用JavaScript來實現。
在<img
src="/demo/verify/regist.do">中,添加一個問號和一串後綴數字,當刷新時讓後綴數字不斷改變,那麼形成的驗證碼也會不斷變化,我們可以採用的一種辦法是後綴數字用date代替,date獲取本機時間,時間是隨時變的,這樣就保證了刷新驗證碼可以隨時變化。
代碼如下:
functionmyRefersh(e){
constsource=e.src;//獲得原來的src中的內容
//console.log("source:"+source);
varindex=source.indexOf("?");//從source中尋找?第一次出現的位置(如果不存在則返回-1)
//console.log("index:"+index);
if(index>-1){//如果找到了?就進入內部
vars=source.substring(0,index);//從source中截取index之前的內容(index以及index之後的內容都被舍棄)
//console.log("s:"+s);
vardate=newDate();//創建一個Date對象的一個實例
vartime=date.getTime();//從新創建的Date對象的實例中獲得該時間對應毫秒值
e.src=s+"?time="+time;//將加了尾巴的地址重新放入到src上
//console.log(e.src);
}else{
vardate=newDate();
e.src=source+"?time="+date.getTime();
}
}
如回答不詳細可追問
❺ java簡訊驗證碼如何驗證
先創建一個驗證碼,通過簡訊代理發送到用戶指定的手機,待用戶提交後做對比,看驗證碼是否一致。
整體流程:
用戶輸入手機號碼,點擊獲取驗證碼
伺服器創建驗證碼,並通過簡訊代理商發送到用戶手機
用戶查看驗證碼,輸入提交
伺服器進行確認,反饋成功或者失敗。
❻ java用戶注冊驗證代碼,用戶名,密碼,手機號,身份證,email,信息顯示在輸入框後面
是要效果還是需要通過java驗證之後不用刷新頁面客戶端就知道這些信息是否被人使用過或者該密碼是否符合該網站的信息填寫要求? 這樣的是同過ajax和驗證來實現!參考ajax!
❼ 注冊時怎麼保證手機號碼的唯一性用java代碼實現
保證手機號碼唯來一性,也就自是保證一條數據在該數據集合中數據有且只有一條。
這個實現代碼太多了,因為涉及到環境原因,還有系統架構,以及框架的使用。
只能給你提出解決方案
1、使用資料庫表唯一鍵實現(這里是防止並發問題,以最早進來的數據為准)
1)使用資料庫作為數據存儲,將手機號作為唯一鍵
2)用戶注冊時直接往資料庫中插入
3)如果已存在則會報唯一鍵的錯誤,然後將其捕獲返回該手機號已經存在。
❽ 發web網站中注冊頁面發送手機簡訊驗證碼功能的java代碼實現
說個流程吧
1.去移動或者電信申請一個web介面
2.客戶填寫請求輸入手機號碼提交內
3.調申請的接容口吧(注意給個對方(電信或者移動)的回調地址吧)
4.從回調地址里拿客戶輸入的數據了,判斷數據了
5.返回數據給客戶了
純屬個人理解
❾ 用java怎麼實現獲取手機驗證碼
你好,首先你得去購買一個簡訊介面,網上大把的有買的。然後購買之後會給你提供一個介面,然後你去調用購買的介面就可以。
❿ 如何實現java手機簡訊驗證功能
你要驗證什麼東西,驗證規則是什麼???
發出來啊