没有合适的资源?快使用搜索试试~ 我知道了~
使用HttpURLConnection发送短信
需积分: 14 0 下载量 99 浏览量
2017-02-23
16:52:18
上传
评论
收藏 2KB TXT 举报
温馨提示
试读
2页
使用HttpURLConnection发送短信
资源推荐
资源详情
资源评论
public int sendMobile(String receiveMobile, String content) {
/**设置短信参数**/
String msg_ip = "";
String msg_user_id = "";
String msg_company_id = "";
String msg_pwd = "";
String msg_key = "";
// msg_ip = "http://www.ztsms.cn:8800/sendXSms.do?";//Config.MSG_IP;
msg_ip = Config.MSG_IP;
msg_user_id = Config.MSG_USER_ID;
msg_company_id = Config.MSG_COMPANY_ID;
msg_pwd = Config.MSG_PWD;
msg_key = Config.MSG_KEY;
/**发动短信动作**/
try {
content = URLEncoder.encode(content+msg_key, "utf-8");
System.out.println(content);
String url = msg_ip+"corporateid="+msg_company_id+"&userid="+msg_user_id+"&password="+msg_pwd+"&mobile="+receiveMobile+"&content="+content+"&schtime=&subcode=";
URL urls = new URL(url);
HttpURLConnection connection = (HttpURLConnection) urls.openConnection();
//connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=gbk");
connection.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"utf-8"));//
String lines;
while ((lines = reader.readLine()) != null){
//lines = new String(lines.getBytes(), "utf-8");
System.out.println(lines);
/**设置短信参数**/
String msg_ip = "";
String msg_user_id = "";
String msg_company_id = "";
String msg_pwd = "";
String msg_key = "";
// msg_ip = "http://www.ztsms.cn:8800/sendXSms.do?";//Config.MSG_IP;
msg_ip = Config.MSG_IP;
msg_user_id = Config.MSG_USER_ID;
msg_company_id = Config.MSG_COMPANY_ID;
msg_pwd = Config.MSG_PWD;
msg_key = Config.MSG_KEY;
/**发动短信动作**/
try {
content = URLEncoder.encode(content+msg_key, "utf-8");
System.out.println(content);
String url = msg_ip+"corporateid="+msg_company_id+"&userid="+msg_user_id+"&password="+msg_pwd+"&mobile="+receiveMobile+"&content="+content+"&schtime=&subcode=";
URL urls = new URL(url);
HttpURLConnection connection = (HttpURLConnection) urls.openConnection();
//connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=gbk");
connection.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"utf-8"));//
String lines;
while ((lines = reader.readLine()) != null){
//lines = new String(lines.getBytes(), "utf-8");
System.out.println(lines);
资源评论
青雨淅沥
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功