发送短信功能
以建周短信平台为例
package com.wjz.util; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; public class SMSUtil { /** * * @param url * 短信平台地址 * @param phone * 目标手机 * @param message * 短信内容 * @param account * 动态获取短信平台账号如从数据库中获得 * @param password * 动态获取短信平台密码如从数据库中获得 * @return */ public static String send(String url, String phone, String message, String account, String password) { HttpClient httpClient = new HttpClient(); PostMethod postMethod = new PostMethod(url); postMethod.getParams().setContentCharset("UTF-8"); postMethod.addParameter("account", account); postMethod.addParameter("password", password); postMethod.addParameter("destmobile", phone); postMethod.addParameter("sendDateTime", ""); postMethod.addParameter("msgText", message); String responseMsg = null; try { int code = httpClient.executeMethod(postMethod); if (code == HttpStatus.SC_OK) { responseMsg = postMethod.getResponseBodyAsString(); } } catch (Exception e) { // } finally { postMethod.releaseConnection(); } return responseMsg; } }