搜索

手机短信验证码java接口怎么写

发布网友 发布时间:2022-04-20 05:24

我来回答

3个回答

热心网友 时间:2022-04-19 03:40

这个首先你要确定一下短信平台,他们会给你提供短信实现的接口文档。
比如:
public static String doPost(String reqUrl, Map parameters, String recvEncoding)
{
HttpURLConnection url_con = null;
String responseContent = null;
try
{
StringBuffer params = new StringBuffer();
Iterator iter = parameters.entrySet().iterator();
while (iter
.hasNext())
{
Map.Entry element = (Map.Entry)iter.next();
params.append(element.getKey().toString());
params.append("=");
params.append(URLEncoder.encode(element.getValue().toString(),
requestEncoding));
params.append("&");
}

if (params.length() > 0)
{
params = params.deleteCharAt(params.length() - 1);
}

URL url = new URL(reqUrl);
url_con = (HttpURLConnection)url.openConnection();
url_con.setRequestMethod("POST");
System.setProperty("sun.net.client.defaultConnectTimeout",
String.valueOf(connectTimeOut));
System.setProperty("sun.net.client.defaultReadTimeout",
String.valueOf(readTimeOut));

url_con.setDoOutput(true);
byte[] b = params.toString().getBytes();
url_con.getOutputStream().write(b, 0, b.length);
url_con.getOutputStream().flush();
url_con.getOutputStream().close();

InputStream in = url_con.getInputStream();
BufferedReader rd = new BufferedReader(
new InputStreamReader(in,
recvEncoding));
String tempLine = rd.readLine();
StringBuffer tempStr = new StringBuffer();
String crlf = System.getProperty("line.separator");
while (tempLine != null)
{
tempStr.append(tempLine);
tempStr.append(crlf);
tempLine = rd.readLine();
}
responseContent = tempStr.toString();
rd.close();
in.close();
}
catch (IOException localIOException)
{
}
finally
{
if (url_con != null)
{
url_con.disconnect();
}
}
return responseContent;
}

public static String sendTelCode(String mobile,String telcode){

Map<String ,String> map = new HashMap<String ,String>();
map.put("account", "Babo");
map.put("mobile", mobile);
map.put("pswd", "D3dddD");
try {
map.put("msg", java.net.URLEncoder.encode("您的验证码是"+telcode+",若非本人操作请忽略","utf-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

String getValue = doPost("http://www.ibabo.cn:7788/msg/HttpSendSM", map, "UTF-8");
System.out.println(getValue);
return getValue;
}

热心网友 时间:2022-04-19 04:58

这个短信验证码平台会提供的把,广东第五大道就有

热心网友 时间:2022-04-19 06:33

你不去找经销商申请接口有代码也没用
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com
Top