凌凯短信接口对接(java)
提交短信BatchSend2
CorpID 账号 String
Pwd 密码 String
Mobile 发送手机号码 String
群发(号码之间用英文逗号隔开,建议500个号码)例如:13812345678,13519876543,15812349876
Content 发送内容 (RULencoder的GBK或GB2312编码) String
Cell 扩展号(必须为数字或为空) String
SendTime 定时发送时间(可为空) String(14)
返回值参数
大于0的数字 提交成功
–1 账号未注册
–2 其他错误
–3 帐号或密码错误
–5 余额不足,请充值
–6 定时发送时间不是有效的时间格式
-7 提交信息末尾未签名,请添加中文的企业签名【 】
–8 发送内容需在1到300字之间
-9 发送号码为空
-10 定时时间不能小于系统当前时间
-100 IP黑名单
-102 账号黑名单
-103 IP未导白
需要的jar包
commons-codec-1.10.jar
commons-logging-4.0.6.jar
httpclient-4.5.2.jar
httpcore-4.4.4.jar
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
public class LinkSMS {
private String CorpID = "账号";// 接口账户名
private String Pwd = "密码";// 接口密码
public static String HttpClientTest(String mobile,String content) {
String result="";
try {
CloseableHttpClient httpclient = HttpClients.createDefault();
AuthCache authCache = new BasicAuthCache();
HttpClientContext context = HttpClientContext.create();
context.setAuthCache (authCache);
//2.封装短信接口参数
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("CorpID", CorpID));
params.add(new BasicNameValuePair("Pwd",Pwd));
params.add(new BasicNameValuePair("Mobile", mobile));
params.add(new BasicNameValuePair("Content", content));
params.add(new BasicNameValuePair("Cell", ""));
params.add(new BasicNameValuePair("SendTime", ""));
HttpEntity entity = new UrlEncodedFormEntity(params,"GBK");
//3.提交访问地址
HttpPost request = new HttpPost ("https://sdk2.028lk.com/sdk2/BatchSend2.aspx");
request.setEntity(entity);
//4.提交访问短信接口
CloseableHttpResponse response = httpclient.execute(request);
//5.获取返回值并解析
HttpEntity entity2 = response.getEntity();
BufferedReader br = new BufferedReader(new InputStreamReader(entity2.getContent(), "GBK"));
String line="";
while ((line = br.readLine()) != null) {
result+= line+"\n";
}
//4.关闭链接
br.close();
response.close ();
httpclient.close ();
} catch (Exception e) {
e.getLocalizedMessage();
}
return result;
}
/**
*main测试
*/
public static void main(String[] args) {
String message="您的验证码为:233112,有效时间5分钟。【凌凯通信】";
String phone="15881014695";
String result=LinkSMS.HttpClientTest(phone,message);
System.out.println("----------------接口提交返回值-------------------");
System.out.print(result);
System.out.println("----------------------------------------------");
//对返回值的判断。。。此处省略
}
}
代码仅供参考,学习阶段,大神们多多指正,虚心学习