java利用http请求实现短信发送的简单实例

本文提供了一个使用Java实现的短信发送示例代码,通过HTTP请求调用短信接口完成短信发送功能。示例中包含了MD5加密、日期格式化、URL编码等关键技术点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public class sms_send {

   public static void main(String[] avgs) throws UnsupportedEncodingException
   {
       String CorpID="125988"; //登录ID号
       String LoginName="****";//登录名
       String passwd="*****";//登录密码
       Date now = new Date(); 
       SimpleDateFormat dateFormat = new SimpleDateFormat("MMddHHmmss");//日期格式化
       String timeStamp = dateFormat.format(now);

       String strPwsd = MD5.md5(CorpID+passwd+timeStamp);//MD5加密方式

       String urls="",mobile="******",txt="";//mobile手机号码
       String contexts=URLEncoder.encode("收到请回复", "GBK");//转码
       String baseUrl = "sms.mobset.com";//广州首易短信接口地址,CorpID开头数字是3,对应地址是sm3.mobset.com
        urls="http://"+baseUrl+"/SDK2/Sms_Send.asp?CorpID="+CorpID+"&LoginName="+LoginName+"&TimeStamp="+timeStamp+"&passwd="+strPwsd+"&send_no="+mobile+"&Timer=&msg="+contexts+"";
       txt=SMSsend(urls);
       System.out.println(urls);
       System.out.print(txt);

   }


static public String SMSsend(String url)
  {
   String result = "";
   try{

    URL U = new URL(url);
    URLConnection connection = U.openConnection();
    connection.connect();
    BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    String line;
    while ((line = in.readLine())!= null)
    {
     result += line;
    }
    in.close();   
   }catch(Exception e){
    System.out.println("没有结果!"+e);
    result="产生异常";
   }
   return result;
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值