日期:2014-05-17  浏览次数:20822 次

jsp 短信验证码的demo啊
求一个jsp开发 短信验证码的例子

------解决方案--------------------
关键得有短信猫
------解决方案--------------------
不同的短信平台,方法不一样,不过为了方便接入,肯定都是很简单的
------解决方案--------------------

    public static String SMS(String phone) {
        try {
            //发送POST请求
         long yzCode= Math.round(Math.random()*899999+100000);
          ServletActionContext.getRequest().getSession().setAttribute("phonevalcode", yzCode);
           // URL url = new URL("http://utf8.sms.webchinese.cn");
            URL url = new URL("http://106.ihuyi.com/webservice/sms.php?method=Submit");
            String postData="account=cf_hehehe&password=hehe123&mobile="+java.net.URLEncoder.encode(phone,"utf-8")+"&content="+java.net.URLEncoder.encode("您的验证码是:"+yzCode+"。请不要把验证码泄露给其他人。","utf-8");
           //String postData="Uid=yonjue&Key=hehe1234567890&smsMob="+java.net.URLEncoder.encode(phone,"utf-8")+"&smsText="+java.net.URLEncoder.encode("尊敬的用户,您在线下100注册验证码是:"+yzCode+"。请不要把验证码泄露给其他人","utf-8");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            conn.setRequestProperty("Connection", "Keep-Alive");
            conn.setUseCaches(false);
            conn.setDoOutput(true);

            conn.setRequestProperty("Content-Length", "" + postData.length());
            OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
            
            out.write(postData);
            out.flush();