java 调用鹏讯通短信平台api发送短信
2014-03-19 14:11
351 查看
鹏讯通短信平台发送短信实例代码如下:
依赖jar:httpcore-4.1.4.jar,httpclient-4.1.3.jar,httpclient-cache-4.1.3.jar,httpmime-4.1.3.jar
package com.test.yckj;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
public class SendMassageUtil {
String url = "http://www.sms8810086.com/jk.aspx";
//String url = "http://www.sms8810086.com";
//发送账号
String zh = "ceshi01";
//发送密码
String mm = "123";
//用户通道
String sms_type = "40";
/**
* @param nr 短信内容
* @param hm 全部被叫号码
* @return
*/
public String sendSms(String nr, String hm) {
String result = null;
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("zh", zh)); //用户名称
params.add(new BasicNameValuePair("mm", mm)); //密码
params.add(new BasicNameValuePair("sms_type", sms_type)); //用户通道
params.add(new BasicNameValuePair("hm", hm)); //接受人电话号码,如果有多个以逗号隔开
params.add(new BasicNameValuePair("nr", nr)); //短信内容
try {
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = null;
try {
instream = entity.getContent();
result = IOUtils.toString(instream, "utf-8");
} finally {
if (instream != null)
instream.close();
}
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
/**
* @param args
*/
public static void main(String[] args) {
SendMassageUtil api = new SendMassageUtil();
String nr = "鹏讯通短信平台";
String hm = "135……"; //电话号码
System.out.println("号码:" + hm + " 内容:" + nr);
System.out.println("结果:" + api.sendSms(nr, hm));
}
}
依赖jar:httpcore-4.1.4.jar,httpclient-4.1.3.jar,httpclient-cache-4.1.3.jar,httpmime-4.1.3.jar
package com.test.yckj;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
public class SendMassageUtil {
String url = "http://www.sms8810086.com/jk.aspx";
//String url = "http://www.sms8810086.com";
//发送账号
String zh = "ceshi01";
//发送密码
String mm = "123";
//用户通道
String sms_type = "40";
/**
* @param nr 短信内容
* @param hm 全部被叫号码
* @return
*/
public String sendSms(String nr, String hm) {
String result = null;
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("zh", zh)); //用户名称
params.add(new BasicNameValuePair("mm", mm)); //密码
params.add(new BasicNameValuePair("sms_type", sms_type)); //用户通道
params.add(new BasicNameValuePair("hm", hm)); //接受人电话号码,如果有多个以逗号隔开
params.add(new BasicNameValuePair("nr", nr)); //短信内容
try {
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = null;
try {
instream = entity.getContent();
result = IOUtils.toString(instream, "utf-8");
} finally {
if (instream != null)
instream.close();
}
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
/**
* @param args
*/
public static void main(String[] args) {
SendMassageUtil api = new SendMassageUtil();
String nr = "鹏讯通短信平台";
String hm = "135……"; //电话号码
System.out.println("号码:" + hm + " 内容:" + nr);
System.out.println("结果:" + api.sendSms(nr, hm));
}
}
相关文章推荐
- JAVA利用短信平台API免费发送短信的程序
- Linux平台,使用JavaComm3 API及SMSLib项目实现在Web Application中发送手机短信的功能
- 程序调用飞信API发送免费短信(JAVA例子,其他语言一样用)
- java项目中使用阿里大于平台进行短信发送
- 使用阿里大于平台发送短信验证码java代码实现
- java中用中国网建提供的SMS短信平台发送短信
- 使用云之讯API借口发送短信(Java,Json版)
- JAVA实现利用第三方平台发送短信验证码
- 阿里大于 短信发送API开发介绍(JAVA)
- 用Java调用中国网建提供的SMS短信平台接口实现向移动端发送短信
- 调用阿里云短信服务平台API实现ERP系统短信发送功能
- SMS短信通API——(1)Java应用发送手机短信
- Java 连接SMS短信平台发送短信
- java 调用云通信的api发送短信
- Java通过SMS平台实现短信发送功能
- Java短信发送平台代码
- java实现SMS短信平台发送验证码功能
- java 调用 短信API服务 (聚合数据平台)
- Java接入阿里大于短信平台在项目中发送短信
- JAVA利用第三方平台发送短信验证码。