用第三方短信提供商
我们项目用的是:http://www.smschinese.cn/api.shtml

解决方案 »

  1.   

    <%@ page contentType="text/html; charset=gb2312" language="java"
    import="java.sql.*" import="java.net.*" import="java.io.*" errorPage=""%>
    <%@page import="java.io.DataInputStream"%>
    <%@ page import='com.xianxia.been.MD5'%><%
    //用户ID和KEY
    String UserId = "";
    String key = ""; String phone = request.getParameter("Tel"); MD5 md5 = new MD5();

    String pwdmd5 = md5.getMD5ofStr(UserId + "0" + phone + key); String curlPost = "UserId=" + URLEncoder.encode(UserId, "UTF-8")
    + "&phone=" + URLEncoder.encode(phone, "UTF-8")
    + "&Md5Str=" + URLEncoder.encode(pwdmd5, "UTF-8"); URL url = null;
    HttpURLConnection httpurlconnection = null;
    try {
    url = new URL("http://106.ihuyi.com/webservice/sms.php?");
    //url = new URL("http://127.0.0.1:81/webcode/outcallInterface.php");
    httpurlconnection = (HttpURLConnection) url.openConnection();
    httpurlconnection.setDoOutput(true);
    httpurlconnection.setRequestMethod("POST");
    httpurlconnection.setRequestProperty("Connection", "Keep-Alive");
    httpurlconnection.setRequestProperty("Content-Type ",
    "application/x-www-form-urlencoded ");
    httpurlconnection.getOutputStream().write(
    curlPost.getBytes("UTF-8"));
    httpurlconnection.getOutputStream().flush();
    httpurlconnection.getOutputStream().close(); DataInputStream is = new DataInputStream(httpurlconnection
    .getInputStream());
    BufferedReader reader = new BufferedReader(
    new InputStreamReader(is));
    StringBuilder sb = new StringBuilder(); String line = null; try {
    while ((line = reader.readLine()) != null) {
    sb.append(line);
    }
    } catch (IOException e) { } finally {
    try {
    is.close();
    } catch (IOException e) { }
    } String authcode = sb.toString();
    // out.print(authcode);
    if (authcode.length() > 1) {
    session.setAttribute("code", authcode); out.print("ok"); return;
    } else {
    out.print("error");
    return;
    }
    } catch (Exception e) {
    //e.printStackTrace();
    } finally {
    if (httpurlconnection != null) {
    httpurlconnection.disconnect();
    }
    }
    %>
    这样可以吗