package com.huayu.volleyball.common;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* 发送短信接口抽取
*/
public class SendMethod {
public static String Send(String mobile) throws Exception {
// 访问第三方接口
String postUrl = "http://106.ihuyi.cn/webservice/sms.php?method=Submit";
// 随机生成六位数
//int randomNum = new Random().nextInt(999999);
int randomNum=(int)((Math.random()*9+1)*100000);
// 随机数生成string类型
String mobile_code = String.valueOf(randomNum);
String account = "";// 第三方账号
String password = "";// 第三方密码
String content = new String("验证码"+mobile_code+",用于注册/登录个人账号等,5分钟内有效,超级排球工作人员与商户不会向您索取验证码,请勿向任何人泄露。");
URL url = new URL(postUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
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();
return mobile_code;
}
}