java调用短信api发送短信进行注册

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;
}


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值