當(dāng)前位置:
首頁(yè) >
前端技术
> javascript
>内容正文
javascript
JSP怎么给手机发短信对接验证码短信接口DEMO示例
生活随笔
收集整理的這篇文章主要介紹了
JSP怎么给手机发短信对接验证码短信接口DEMO示例
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
發(fā)現(xiàn)一個(gè)超簡(jiǎn)單驗(yàn)證碼短信接口對(duì)接DEMO示例
步驟
1.注冊(cè) 互億無線 賬號(hào)
2.查找APIID和APIKEY
3.代碼的書寫
注冊(cè) 互億無線 賬號(hào)
網(wǎng)站: http://user.ihuyi.com/?JA9Ewr
查找APIID和APIKEY
注意事項(xiàng):
(1)調(diào)試期間,請(qǐng)使用用系統(tǒng)默認(rèn)的短信內(nèi)容:您的驗(yàn)證碼是:【變量】。請(qǐng)不要把驗(yàn)證碼泄露給其他人。
?
String postUrl = "http://106.ihuyi.com/webservice/sms.php?method=Submit";int mobile_code = (int)((Math.random()*9+1)*100000); //獲取隨機(jī)數(shù)String account = "用戶名"; //查看用戶名 登錄用戶中心->驗(yàn)證碼通知短信>產(chǎn)品總覽->API接口信息->APIIDString password = "密碼"; //查看密碼 登錄用戶中心->驗(yàn)證碼通知短信>產(chǎn)品總覽->API接口信息->APIKEYString mobile = request.getParameter("mobile");String content = new String("您的驗(yàn)證碼是:" + mobile_code + "。請(qǐng)不要把驗(yàn)證碼泄露給其他人。");try {URL url = new URL(postUrl);HttpURLConnection connection = (HttpURLConnection) url.openConnection();connection.setDoOutput(true);//允許連接提交信息connection.setRequestMethod("POST");//網(wǎng)頁(yè)提交方式"GET"、"POST"connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");connection.setRequestProperty("Connection", "Keep-Alive");StringBuffer sb = new StringBuffer();sb.append("account="+account);sb.append("&password="+password);sb.append("&mobile="+mobile);sb.append("&content="+content);OutputStream os = connection.getOutputStream();os.write(sb.toString().getBytes());os.close();String line, result = "";BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));while ((line = in.readLine()) != null) {result += line + "\n";}in.close();out.println(result);} catch (IOException e) {e.printStackTrace(System.out);}總結(jié)
以上是生活随笔為你收集整理的JSP怎么给手机发短信对接验证码短信接口DEMO示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 游戏图片推荐格式及压缩方式。Textur
- 下一篇: 基于NodeJS健身房会员管理小程序的设