當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JSP怎么给手机发短信对接验证码短信接口DEMO示例
生活随笔
收集整理的這篇文章主要介紹了
JSP怎么给手机发短信对接验证码短信接口DEMO示例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
發現一個超簡單驗證碼短信接口對接DEMO示例
步驟
1.注冊 互億無線 賬號
2.查找APIID和APIKEY
3.代碼的書寫
注冊 互億無線 賬號
網站: http://user.ihuyi.com/?JA9Ewr
查找APIID和APIKEY
注意事項:
(1)調試期間,請使用用系統默認的短信內容:您的驗證碼是:【變量】。請不要把驗證碼泄露給其他人。
?
String postUrl = "http://106.ihuyi.com/webservice/sms.php?method=Submit";int mobile_code = (int)((Math.random()*9+1)*100000); //獲取隨機數String account = "用戶名"; //查看用戶名 登錄用戶中心->驗證碼通知短信>產品總覽->API接口信息->APIIDString password = "密碼"; //查看密碼 登錄用戶中心->驗證碼通知短信>產品總覽->API接口信息->APIKEYString mobile = request.getParameter("mobile");String content = new String("您的驗證碼是:" + mobile_code + "。請不要把驗證碼泄露給其他人。");try {URL url = new URL(postUrl);HttpURLConnection connection = (HttpURLConnection) url.openConnection();connection.setDoOutput(true);//允許連接提交信息connection.setRequestMethod("POST");//網頁提交方式"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);}總結
以上是生活随笔為你收集整理的JSP怎么给手机发短信对接验证码短信接口DEMO示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 游戏图片推荐格式及压缩方式。Textur
- 下一篇: Zabbix与ELK整合实现对安全日志数