手机短信验证码java接口怎么写
3个回答
2017-10-14 · 【免费测试,验证码5秒必达】
北京巴卜技术有限公司
北京巴卜技术有限公司(以下简称巴卜)是具备国际水准的移动商务平台技术和应用方案提供商。自成立以来,巴卜始终 致力于为国内外企业提供具备国际技术水准的移动商务平台及运营服务。
向TA提问
关注
展开全部
这个首先你要确定一下短信平台,他们会给你提供短信实现的接口文档。
比如:
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;
}
比如:
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;
}
摩杜云
2024-07-09 广告
2024-07-09 广告
判断一个发送邮件api公司的好坏,不只是看价格,还要考虑很多因素。建议可以多对比几个看看。您可以到摩杜云了解下。摩杜云成立于2019年,依托于公司多年技术沉淀和强大的云计算研发实力,面向全世界各个国家和地区、企业组织和个人开发者,提供全球的...
点击进入详情页
本回答由摩杜云提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询