还是第三方的小平台的demo简单,基本没有任何封装的东西,简单易懂好实现,基本就是填上账号就能用.

package com.test;import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;public class SendMessage {@SuppressWarnings({ "static-access", "static-access" })public static void main(String[] args) {try {SendMessage sm = new SendMessage();// Http Get请求//test.sendSMSGet("13439117920",//"Java Http GET 方式短信调试已经成功!!!!!【成都凌凯】", "");String code=random.getThree();// Http post 请求sm.sendSMSPost("手机号","短信内容:"+code+ "有效时间为五分钟", "");String CorpID = "";// 账户名String Pwd = "";// 密码//回复信息查询// test.getReplyMsg(CorpID, Pwd);//余额查询sm.getSelSum(CorpID, Pwd);//获取禁止号码//    test.getNotSend(CorpID, Pwd);} catch (MalformedURLException e) {e.printStackTrace();} catch (UnsupportedEncodingException e) {e.printStackTrace();}}/*** http get请求 发送方法 其他方法同理 返回值>0 提交成功* * @param Mobile*            手机号码* @param Content*            发送内容* @param send_time*            定时发送的时间;可以为空,为空时为及时发送* @return 返回值* @throws MalformedURLException* @throws UnsupportedEncodingException*/public static int sendSMSGet(String Mobile, String Content, String send_time)throws MalformedURLException, UnsupportedEncodingException {URL url = null;String CorpID = "";// 账户名String Pwd = "";// 密码String send_content = URLEncoder.encode(Content.replaceAll("<br/>", " "), "GBK");// 发送内容url = new URL("https://sdk2.028lk.com/sdk2/BatchSend2.aspx?CorpID="+ CorpID + "&Pwd=" + Pwd + "&Mobile=" + Mobile + "&Content="+ send_content + "&Cell=&SendTime=" + send_time);BufferedReader in = null;int inputLine = 0;try {System.out.println("开始发送短信手机号码为 :" + Mobile);in = new BufferedReader(new InputStreamReader(url.openStream()));inputLine = new Integer(in.readLine()).intValue();} catch (Exception e) {System.out.println("网络异常,发送短信失败!");inputLine = -2;}System.out.println("结束发送短信返回值:  " + inputLine);return inputLine;}/*** Hppt POST请求发送方法 返回值>0 为 提交成功* * @param Mobile*            电话号码* @param Content*            发送内容* @param send_time*            定时发送时间,为空时,为及时发送* @return* @throws MalformedURLException* @throws UnsupportedEncodingException*/public static int sendSMSPost(String Mobile, String Content,String send_time) throws MalformedURLException,UnsupportedEncodingException {String inputLine = "";int value = -2;DataOutputStream out = null;InputStream in = null;String CorpID = "";// 账户名String Pwd = "";// 密码String send_content = URLEncoder.encode(Content.replaceAll("<br/>", " "), "GBK");// 发送内容String strUrl = "https://sdk2.028lk.com/sdk2/BatchSend2.aspx";String param = "CorpID=" + CorpID + "&Pwd=" + Pwd + "&Mobile=" + Mobile+ "&Content=" + send_content + "&Cell=&SendTime=" + send_time;try {inputLine = sendPost(strUrl, param);System.out.println("开始发送短信手机号码为 :" + Mobile);value = new Integer(inputLine).intValue();} catch (Exception e) {System.out.println("网络异常,发送短信失败!");value = -2;}System.out.println(String.format("返回值:%d", value));return value;}/*** 获取回复消息* @param corpId 账号* @param pwd 密码* @return 回复消息结果*/public static String getReplyMsg(String corpId,String pwd){String result="";String msg = "";String strUrl = "https://sdk2.028lk.com/sdk2/Get.aspx";String param = "CorpID=" + corpId + "&Pwd=" + pwd;try {result = sendPost(strUrl,param);
//          result ="||15281008413#123#2017-01-04||15281008412#123#2017-01-04||15281008413#121#2017-01-04||15281008410#123#2017-01-04||";if(result==null||result.equals("")||result.length()==0){msg ="没有上行信息";}if(result.equals("-1")){msg = "账号未注册";}else if(result.equals("-2")){msg = "其他错误";}else if(result.equals("-3")){msg = "密码错误";}else if(result.equals("-101")){msg = "调用接口频率过快(大于30s调用一次)";}else if(result.equals("-100")){msg = "IP黑名单";}else if(result.equals("-102")){msg = "账号黑名单";}else if(result.equals("-103")){msg = "IP未导白";}else {msg = String.format("获取成功!%s",result);result = result.replace("||", "|");String [] strArray = result.split("\\|");String outContent = "";int i = 0;for(String str : strArray){if(str.equals(""))continue;String [] strConArr = str.split("#");if(strConArr ==null||strConArr.length<=0)continue;i = i+1;outContent = String.format("第%d条回复,手机号码:%s,回复内容:%s,回复时间:%s",i,strConArr[0],strConArr[1],strConArr[2]);System.out.println(outContent);}}System.out.println(msg);} catch (Exception e) {System.out.println("网络异常,回复消息获取失败!");}return result;}/*** 账号余额查询* @param corpId 账号* @param pwd 密码* @return*/public static String getSelSum(String corpId,String pwd){String result="";String msg = "";String strUrl = "https://sdk2.028lk.com/sdk2/SelSum.aspx";String param = "CorpID=" + corpId + "&Pwd=" + pwd;try {result = sendPost(strUrl,param);if(result.equals("-1")){msg = "账号未注册";}else if(result.equals("-2")){msg = "其他错误";}else if(result.equals("-3")){msg = "密码错误";}else if(result.equals("-101")){msg = "调用接口频率过快(大于30s调用一次)";}else if(result.equals("-100")){msg = "IP黑名单";}else if(result.equals("-102")){msg = "账号黑名单";}else if(result.equals("-103")){msg = "IP未导白";}else {msg = String.format("获取成功!%s",result);}System.out.println(msg);} catch (Exception e) {System.out.println("网络异常,回复消息获取失败!");}return result;}/*** 获取禁止发送的号码* @param corpId 账号* @param pwd 密码* @return*/public static String getNotSend(String corpId, String pwd){String result="";String msg = "";String strUrl = "https://sdk2.028lk.com/sdk2/NotSend.aspx";String param = "CorpID=" + corpId + "&Pwd=" + pwd;try {result = sendPost(strUrl,param);if(result.equals("-1")){msg = "账号未注册";}else if(result.equals("-2")){msg = "其他错误";}else if(result.equals("-3")){msg = "密码错误";}else if(result.equals("-101")){msg = "调用接口频率过快(大于30s调用一次)";}else if(result.equals("-100")){msg = "IP黑名单";}else if(result.equals("-102")){msg = "账号黑名单";}else if(result.equals("-103")){msg = "IP未导白";}else {msg = result;}System.out.println(msg);} catch (Exception e) {System.out.println("网络异常,禁止号码获取失败!");}return result;}/*** 向指定 URL 发送POST方法的请求* * @param url*            发送请求的 URL* @param param*            请求参数,请求参数应该是 name1=value1&name2=value2 的形式。* @return 所代表远程资源的响应结果*/public static String sendPost(String url, String param) {PrintWriter out = null;BufferedReader in = null;String result = "";try {URL realUrl = new URL(url);// 打开和URL之间的连接URLConnection conn = realUrl.openConnection();// 设置通用的请求属性conn.setRequestProperty("accept", "*/*");conn.setRequestProperty("connection", "Keep-Alive");conn.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");// 发送POST请求必须设置如下两行conn.setDoOutput(true);conn.setDoInput(true);// 获取URLConnection对象对应的输出流out = new PrintWriter(conn.getOutputStream());// 发送请求参数out.print(param);// flush输出流的缓冲out.flush();// 定义BufferedReader输入流来读取URL的响应in = new BufferedReader(new InputStreamReader(conn.getInputStream()));String line;while ((line = in.readLine()) != null) {result += line;}} catch (Exception e) {System.out.println("发送 POST 请求出现异常!" + e);e.printStackTrace();}// 使用finally块来关闭输出流、输入流finally {try {if (out != null) {out.close();}if (in != null) {in.close();}} catch (IOException ex) {ex.printStackTrace();}}return result;}
}
生成六位数随机验证码.
/*** @author www.bjmxmj.com/* 生成六位随机数验证码*    */
public class random {public static String getThree(){  Random rad=new Random();  return rad.nextInt(1000000)+"";  }  public static void main(String[] args) {System.out.println("随机数为" + getThree());}}



使用第三方平台短信接口实现发送验证码相关推荐

  1. 调用短信接口,发送验证码

    //通过httpclient调用接口,传参给客户手机发过去 String jsonParams = "{\"secret\":\""+加密的参数+&q ...

  2. 对接阿里云平台短信接口

    现在做的小程序,需要给客户手机发送短信验证码,用的是阿里云的短信平台 首先要搞好短信模板,签名之类的,这个就相当于发送的短信主体内容,其中验证码部分是我们自己定义的,这个要审核通过了才行 然后在下图, ...

  3. java调用短信接口实现发送短信

    java调用短信接口实现发送短信 1.下载接口文件 2.打开java文件夹 2.1获取jar包依赖 2.2获取代码模板 3.创建项目 3.1打开eclipse软件,创建一个动态的web项目 3.2导入 ...

  4. TP5调用阿里云短信接口实现发送短信功能

    TP5调用阿里云短信接口实现发送短信功能 工作需要,对接阿里云的短信服务,借此记录一下(网站 www.lelee.top) 主要分为两个部分,一是下载官方的Demo事例,这个不需要多说,自己去下载就行 ...

  5. Java调用阿里云短信接口,发送短信

    Java调用阿里云短信接口,发送短信 1.短信服务这个很简单,只需要知道accessKeyId(AK).accessKeySecret(SK).短信签名.短信模板即可. 2.域名和产品名称是固定的,使 ...

  6. python --- 短信接口开发手机验证码发送

    现在网络环境下,基本上任何网站注册都会验证手机号,已达到防止机器人注册的目的.除此之外短信群发,查询回复,找回密码等相关功能也需要短信验证码功能.那么网站的验证码发送是如何实现的呢?现在我们学习一下( ...

  7. python发送短信接口_python发送短信和发送邮件

    先注册好 发短信脚本内容 #接口类型:互亿无线触发短信接口,支持发送验证码短信.订单通知短信等. #账户注册:请通过该地址开通账户http://sms.ihuyi.com/register.html ...

  8. c语言您的验证码代码,c国际短信接口_c国际验证码接口_c国际手机验证接口_国际短信代码示例_达信通...

    C C代码示例 //接口类型:达信通国际短信接口. //账户注册:请通过该地址开通账户http://sms.wx96.com/register.html //注意事项: //(1)调试期间,请仔细阅读 ...

  9. 如何通过阿里云短信服务来发送验证码短信(超详细)

    通过阿里云来创建自己产品的验证码 目录 通过阿里云来创建自己产品的验证码 前言: 一:注册阿里云账号 二:开通阿里云短信服务 三:测试类文件的编写 四:测试 后续:动态验证码的生成 前言: 短信验证码 ...

最新文章

  1. RubyGems 库发现了后门版本的网站开发工具 bootstrap-sass
  2. 数据中心的敏捷运维之路
  3. idea前进和后退快捷键_必备技能:IDEA一定要懂的32条快捷键
  4. SpringBoot2.1.9 Mybatis由于@Mapper注解多数据源配置不生效问题
  5. java乱码base64,解决 JAVA WebSocket 解析 base64 后中文字符串乱码
  6. 移动端web页面自适应和rem
  7. 主题背景_游戏背景音乐的种类—主题曲
  8. 求矩阵四叉树的四进制和十进制Morton码
  9. tomcat7插件的引入
  10. visio中使用连接线连接形状
  11. ::-moz-focus-inner
  12. 高斯平滑算法 c语言,高斯模糊算法(gaussian)
  13. 抽象基类与接口,共性与个性的选择!
  14. vue插槽的理解 slot slot-scop,三种插槽方式,默认插槽,具名插槽,作用域插槽
  15. 【ResNet残差网络解析】
  16. 小米手机开发者选项打开usb安装需要SIM卡解决办法
  17. 计算机通信与网络(一)
  18. ps切图的零散小知识
  19. MQTT Mosquitto安装和使用
  20. 12. linux系统管理(1)

热门文章

  1. Java实现.dat文件转txt可读文件
  2. 日志输出The last packet successfully received问题以及c3p0解决方案,max_statements
  3. 2022年(23届)电子信息/通信工程夏令营保研/考研复试经验贴(中南大学物理与电子学院篇)
  4. 属性重命名 @SerializedName
  5. 参加校招的应届生如何获取招聘信息
  6. 荔枝FM:异地多活IDC机房架构
  7. 带你快速实现购物车功能
  8. python绘制成绩直方图_python如何绘制直方图
  9. shineblink Core TF卡的读写操作
  10. K-means算法代码详解及Demo