/*标签:短信,String,验证码,private,pwd,static,new,java,final From: https://blog.51cto.com/u_3871599/6142197
* 如uid是:test,登录密码是:123123
pwd=md5(123123test),即
pwd=b9887c5ebb23ebb294acab183ecf0769
线生成地址:http://www.sms.cn/password
*/
private static final String addr = "http://api.sms.cn/mt/";
private static final String userId = "xxxxxx";
private static final String pwd = "b9887c5ebb23ebb294acab183ecf0769";
private static final String encode = "utf8";
public static String send(String code, String mobile) throws Exception {
String msgContent = "XXXXXXXXXXXXXXXXXXXXXX欢迎您的加入,验证码为:" + code;
//组建请求
String straddr = addr +
"?uid=" + userId +
"&pwd=" + pwd +
"&mobile=" + mobile +
"&encode=" + encode +
"&content=" + msgContent;
StringBuffer sb = new StringBuffer(straddr);
System.out.println("URL:" + sb);
//发送请求
URL url = new URL(sb.toString());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
BufferedReader in = new BufferedReader(new InputStreamReader( url.openStream(), "gbk"));
//返回结果
String inputline = in.readLine();
return inputline;
}