/**
*
* @Title: sendVerificationCode
* @Description: TODO(发送验证码)
* @param @return
* 设定文件
* @return String 返回类型
* @throws IOException
* @throws FileNotFoundException
* @throws @author
* @date 2017年6月1日上午9:43:20
*/
public static Map<String, Object> sendVerificationCode(String telephone,Integer count) {
System.out.println("短信发送...");
Map<String, Object> resultMap = new HashMap<String,Object>();
if (!phoneNumber(telephone)) {
resultMap.put("CODE",-29);
resultMap.put("Message","手机号码不正确!");
return resultMap;
}
// 写在配置文档里 解析config.propertie
// Properties props = new Properties();
// String httpUrl = PropKit.get("msg_url");
// String sn = PropKit.get("msg_sn");
// String pw = PropKit.get("msg_password");
// try {
// props.load(new FileInputStream("/config.propertie"));
// } catch (Exception e) {
// e.printStackTrace();
// }
// String httpUrl = props.getProperty("msg_url");
// String sn = props.getProperty("msg_sn");
// String pw = props.getProperty("msg_password");
// String contents = props.getProperty("msg_content");
//发送的一个路径
String httpUrl ="";
//账号
String sn = "";
//密码
String pw = "";
//发送的文档信息 加随机数 count随机数
String contents = ""+count+"";
String pwd = getMD5(sn+pw).toUpperCase();
String httpArg = "sn="+sn+"&pwd="+pwd+"&mobile=" + telephone;
BufferedReader reader = null;
StringBuffer sbf = new StringBuffer();
try {
System.out.println(contents+"-----");
contents = URLEncoder.encode(contents, "gb2312");
System.out.println(contents+"++++++=");
httpArg = httpArg +"&content="+ contents;
httpUrl = httpUrl + "?" + httpArg;
URL url = new URL(httpUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
InputStream is = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(is, "gb2312"));
String strRead = null;
while ((strRead = reader.readLine()) != null) {
sbf.append(strRead);
}
reader.close();
System.out.println("短信发送结果:" + sbf.toString());
long a = Long.parseLong(sbf.toString());
if (a > 0) {
//resultMap.setCode(0);
resultMap.put("CODE", 200);
} else {
//resultMap.setCode(-29);
//resultMap.setMessage(sbf.toString());
resultMap.put("message", sbf.toString());
}
} catch (Exception e) {
e.printStackTrace();
//resultMap.setCode(-29);
//resultMap.setMessage(e.getMessage());
resultMap.put("message", e.getMessage());
}
return resultMap;
}