当前位置:文档之家› JAVA短信接口代码示例

JAVA短信接口代码示例

JAVA调用短信接口代码示例

本文主要为大家分享java短信接口代码,java短信发送代码示例,感兴趣的小伙伴们可以参考一下。

请求方式:http、get

适用于:网站/APP短信验证码、会员营销、订单生成通知、发货通知\催费通知等等

特点:绿色短信,合法正规通道,全网收发、三网合一,双向互动,可回复高速群发

以下是完整的JAVA调用短信接口代码示例:

package test;

import java.io.IOException;

import java.io.UnsupportedEncodingException;

import https://www.doczj.com/doc/067907073.html,.URISyntaxException;

import https://www.doczj.com/doc/067907073.html,.URLEncoder;

import https://www.doczj.com/doc/067907073.html,mons.httpclient.HttpClient;

import https://www.doczj.com/doc/067907073.html,ValuePair;

import https://www.doczj.com/doc/067907073.html,mons.httpclient.methods.PostMethod; import https://www.doczj.com/doc/067907073.html,ng3.StringUtils;

public class Apis {

// 短信发送接口的http地址,请咨询客服

private static String url = "xxxxxxxxxxxxxxxxxxxxxxxx xxxx";

// 编码格式。发送编码格式统一用UTF-8

private static String ENCODING = "UTF-8";

public static void main(String[] args) throws IOExcep tion, URISyntaxException {

// 账号

String account = "************************";

// 密码

String pswd = "************************";

// 修改为您要发送的手机号,多个用,分割

String mobile = "13*********";

// 设置您要发送的内容

String msg = "【秒赛科技】您的验证码是:1234";

// 发短信调用示例

System.out.println(Apis.send(account,pswd, mobile , msg));

}

/**

* 发送短信

*

* @param account

* account

* @param pswd

* pswd

* @param mobile

* 手机号码

* @param content

* 短信发送内容

*/

public static String send(String account,String pswd, String mobile, String msg) {

NameValuePair[] data = { new NameValuePair("accou nt", account),

new NameValuePair("pswd", pswd),

new NameValuePair("mobile", mobile),

new NameValuePair("msg", msg),

new NameValuePair("needstatus", "true"),

new NameValuePair("product", "") };

return doPost(url, data);

}

/**

* 基于HttpClient的post函数

* PH

* @param url

* 提交的URL

*

* @param data

* 提交NameValuePair参数

* @return 提交响应

*/

private static String doPost(String url, NameValuePai r[] data) {

HttpClient client = new HttpClient();

PostMethod method = new PostMethod(url);

// method.setRequestHeader("ContentType",

// "application/x-www-form-urlencoded;charset=UTF -8");

method.setRequestBody(data);

// client.getParams().setContentCharset("UTF-8");

client.getParams().setConnectionManagerTimeout(10 000);

try{

client.executeMethod(method);

return method.getResponseBodyAsString();

} catch(Exception e) {

e.printStackTrace();

}

return null;

}

}

相关主题
文本预览
相关文档 最新文档