java短信发送代码_java 短信发送 的 代码

发送短息的时候需要注册一个网关 。。。 需要有用户名和 密码  :: import java.util.*; import java.io.*; import java.net.*; public class TXHttpJava {     public static void main(String[] args)     {         Scanner scanner=new Scanner(System.in);         System.out.print("请输入操作:S(发送短信),Q(查询余额),C(修改密码),X(退出).");         System.out.print("提示:输入后按“回车键”响应事件.");         String cmd=scanner.next();         if(cmd.trim().toUpperCase().equals("S"))         {             SendSmsDemo();         }         else if(cmd.trim().toUpperCase().equals("Q"))         {             QueryDemo();         }         else if(cmd.trim().toUpperCase().equals("C"))         {             ChgPwdDemo();         }         else if(cmd.trim().toUpperCase().equals("X"))         {             System.exit(0);         }     }         /*      * 发送短信的演示代码      */     static void SendSmsDemo()     {         Scanner scanner=new Scanner(System.in);         System.out.print("请输入您的用户名:");         String UserName=scanner.next();         System.out.print("请输入您的密码:");         String Password=scanner.next();         System.out.print("请输入接收短信的手机号码:");         String Mobiles=scanner.next();         System.out.print("请输入短信内容:");         String Content=scanner.next();         URL url = null;         try         {           String strUrl = "http://www.sms1086.com/plan/api/Send.aspx?username="+URLEncoder.encode(UserName,"GB2312")+"&password="+java.net.URLEncoder.encode(Password,"GB2312")+"&mobiles="+java.net.URLEncoder.encode(Mobiles,"GB2312")+"&content="+java.net.URLEncoder.encode(Content,"gbk");           url = new URL(strUrl);           URLConnection UConn = url.openConnection();            BufferedReader breader = new BufferedReader(new InputStreamReader(UConn.getInputStream()));           String str=breader.readLine();           while(str != null){              str = URLDecoder.decode(str,"GB2312");            String[] strs=str.split("&");            if(strs[0].replace("result=","").trim().equals("0"))            {                str = "恭喜,密码修改成功。";            }            else            {            str = "密码修改失败。失败原因:"+strs[1].replace("description=","");            }            System.out.print(str);            str=breader.readLine();             }                  }         catch(Exception e)         {             e.printStackTrace();         }     }         /*      * 查询余额的演示代码      */     static void QueryDemo()     {         Scanner scanner=new Scanner(System.in);         System.out.print("请输入您的用户名:");         String UserName=scanner.next();         System.out.print("请输入您的密码:");         String Password=scanner.next();         URL url = null;         try         {           String strUrl = "http://www.sms1086.com/plan/api/Query.aspx?username="+URLEncoder.encode(UserName,"GB2312")+"&password="+java.net.URLEncoder.encode(Password,"GB2312");           url = new URL(strUrl);           URLConnection UConn = url.openConnection();            BufferedReader breader = new BufferedReader(new InputStreamReader(UConn.getInputStream()));           String str=breader.readLine();           while(str != null){              str = URLDecoder.decode(str,"GB2312");            String[] strs=str.split("&");            if(strs[0].replace("result=","").trim().equals("0"))            {                    str = "您的余额为:"+strs[1].replace("balance=","")+"条。";            }            else            {                str = "查询失败。失败原因:"+strs[1].replace("description=","");            }            System.out.print(str);            str=breader.readLine();             }                  }         catch(Exception e)         {             e.printStackTrace();         }     }         /*      * 查询余额的演示代码      */     static void ChgPwdDemo()     {         Scanner scanner=new Scanner(System.in);         System.out.print("请输入您的用户名:");         String UserName=scanner.next();         System.out.print("请输入您的原密码:");         String OldPassword=scanner.next();         System.out.print("请输入您的新密码:");         String NewPassword=scanner.next();         URL url = null;         try         {           String strUrl = "http://www.sms1086.com/plan/api/ChgPwd.aspx?username="+URLEncoder.encode(UserName,"GB2312")+"&password="+java.net.URLEncoder.encode(OldPassword,"GB2312")+"&newpwd="+java.net.URLEncoder.encode(NewPassword,"GB2312");           url = new URL(strUrl);           URLConnection UConn = url.openConnection();            BufferedReader breader = new BufferedReader(new InputStreamReader(UConn.getInputStream()));           String str=breader.readLine();           while(str != null){              str = URLDecoder.decode(str,"GB2312");            String[] strs=str.split("&");            if(strs[0].replace("result=","").trim().equals("0"))            {                    str = "恭喜,密码修改成功。";            }            else            {                str = "密码修改失败。失败原因:"+strs[1].replace("description=","");            }            System.out.print(str);            str=breader.readLine();             }                  }         catch(Exception e)         {             e.printStackTrace();         }     }         }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值