1:使用榛子云作为短信服务的提供者

榛子云官网:http://smsow.zhenzikj.com/
自己注册下就可以了
查看自己的appid

2:代码编写

1:pom.xml导入最新的依赖

  <dependency><groupId>com.zhenzikj</groupId><artifactId>zhenzisms</artifactId><version>1.0.2</version></dependency>

2:编写代码controller层

 //短信平台相关参数。在用户中心查看private String apiUrl = "https://sms_developer.zhenzikj.com";//调用的接口private String appId = "";private String appSecret = "";@ResponseBody@PostMapping("/sendcode")public Result getCode(@RequestBody Map<String, Object> params, HttpSession httpSession){String phonenumber = (String) params.get("phonenumber");//通过ajax传过来的手机号System.out.println(phonenumber);try {String code = String.valueOf(new Random().nextInt(999999));System.out.println("验证码是:"+code+".....................");ZhenziSmsClient client = new ZhenziSmsClient(apiUrl, appId, appSecret);String result = client.send(phonenumber, "您的验证码为:" + code + ",该码有效期为5分钟,该码只能使用一次!");System.out.println(result);System.out.println("发送成功");return Result.ok();} catch (Exception e) {e.printStackTrace();}return Result.error("账号已经存在请登入");}

3:Result.class

在这里插入代码片
```public class Result extends HashMap<String, Object> {private static final long serialVersionUID = 1L;public Result() {put("code", 0);}public static Result error() {return error(500, "未知异常,请联系管理员");}public static Result error(String msg) {return error(500, msg);}public static Result error(int code, String msg) {Result r = new Result();r.put("code", code);r.put("msg", msg);return r;}public static Result ok(Object msg) {Result r = new Result();r.put("msg", msg);return r;}public static Result ok(Map<String, Object> map) {Result r = new Result();r.putAll(map);return r;}public static Result ok() {return new Result();}@Overridepublic Result put(String key, Object value) {super.put(key, value);return this;}
}

3:前端以及ajax编写

     <input type="text" name="phonenumber" v-model="phonenumber"   id="phonenumber" placeholder="输入手机号"><button type="button" onclick="sign()"  class="am-btn am-btn-default">注册</button>function dosend() {var phonenumber= $("#phonenumber").val();alert("短信成功发送请注意查收!");$.ajax({url: "/sendcode", // 后台短信发送接口type: 'POST',dataType: 'json',contentType: "application/json",async: false, //false 同步data: JSON.stringify({"phonenumber":phonenumber}),xhrFields: {withCredentials: true},success: function (result) {if(result.code == 0) {}else {}},error: function () {}});}

4:控制台

code格式:

springboot整合手机验证码相关推荐

  1. Springboot整合kaptcha验证码

    Springboot整合kaptcha验证码 01.通过配置类来配置kaptcha 01-01.添加kaptcha的依赖: <!-- kaptcha验证码 --> <dependen ...

  2. SpringBoot整合手机短信验证码

    手机短信验证码技术 1.流程图 前端点击发送手机验证码 后端判断恶意请求拦截[手机号码限制次数 - redis设置过期时间,自增 - 大于10次直接抛异常 - 没有做] 验证图形验证码是否正确,不正确 ...

  3. 阿里云 java SpringBoot发送手机验证码

    准备工作:需要在阿里云注册,并且申请AK.自行百度 然后: 首先新建springboot文件,在此不做赘述 向pom.xml文件中添加依赖: <!--短信sdk--> <depend ...

  4. SpringBoot整合Captcha验证码(含代码)

    1. 基本结构 使用Captcha生成验证码, 利用Redis存储验证码 Redis中的结构为, Key是32位的UUID, Value为Captcha的4位随机字母以及数字的集合 设定Redis过期 ...

  5. Springboot 整合SpringSecurity实现账号密码+手机验证码登陆

    Springboot 整合SpringSecurity实现账号密码+手机验证码登陆 示例说明 版本 示例安装 Spring-security 介绍 为什么不用 shiro Spring-Securit ...

  6. SpringBoot整合Shiro实现权限控制,验证码

    本文介绍 SpringBoot 整合 shiro,相对于 Spring Security 而言,shiro 更加简单,没有那么复杂. 目前我的需求是一个博客系统,有用户和管理员两种角色.一个用户可能有 ...

  7. SpringBoot+vue 使用阿里云的短信功能发送手机验证码

    前言: 小编后端用的是Springboot 前端用的是vue ,小编主要是写后台,前端页面比较简陋,后期还要调优,写的不对处还望多多包涵. 环境: 需要先准备好阿里云的账号和一些必要的参数.详情见我的 ...

  8. springboot+vue实现手机验证码功能

    springboot+vue实现手机验证码功能 榛子云短信平台用户中心注册登录(有免费的一条消息,剩下的需要买)(阿里云个人得备案) 在springboot中加入依赖,用到了redis,阿里的fast ...

  9. Springboot手机验证码

    https://zhuanlan.zhihu.com/p/87147229 - Springboot手机验证码 https://blog.csdn.net/qq_15071263/article/de ...

  10. 腾讯云短信服务实现 Java 发送手机验证码(SpringBoot+Redis 实现)

    文章目录 腾讯云短信服务实现 Java 发送手机验证码(SpringBoot+Redis 实现) 1.打开腾讯云短信服务 2.创建短信签名 3.创建短信正文模板 4.等待全部审核完毕即可 5.发送短信 ...

最新文章

  1. React事件处理函数传参问题
  2. VS 2013 with update安装失败(kb2829760)解决方案
  3. Iocomp控件教程之Pie Chart——饼状图控件
  4. 拥有此神技,脚本调试从此与 echo、set、test 说分手
  5. java 获取请求客户端的真实IP地址
  6. CANN5.0黑科技解密 | 高并发图片视频处理,为出行保驾,为生活添彩
  7. 运行 lighttrack 遇到错误和解决方法
  8. 一个类中可以没有main方法_一个月可以暴瘦二十斤的减肥方法
  9. linux下查看当前shell方法。
  10. 在Linux(Ubuntu)下编写编译C语言
  11. 泰格至尊版软件加密锁注册机
  12. 从14连号概率题来看“做学问不知足”
  13. 孙宇晨真的有道歉吗?逐句解读孙宇晨避重就轻的“致歉信”
  14. 超详细的bat脚本常用命令及亲测示例
  15. 一周 Go World 新鲜事-2019W11
  16. Office2021官方镜像
  17. 2021手游排行前十名分享
  18. 使用SET修改组合SAS数据集
  19. HDU 3003 Pupu
  20. 《Spring实战》读书笔记2

热门文章

  1. 题解:艾米利亚的魔法
  2. Focal Loss简述
  3. emv中的 部分匹配_EMV指标策略
  4. 木子-前端-ajax传值与接收最简单的方式
  5. 集群搭建——SGE与PBS
  6. R语言学习笔记(二)——回归分析
  7. python文件加减法_python生成PDF文件20以内加减法,给上小学的宝宝
  8. 在一个线程中 sleep(1000) 方法,将使得该线程在多少时间后获得对 CPU 的控制(假设睡眠过程中不会有其他时间唤醒该线程)?
  9. 视频剪辑的工作前景是什么?
  10. mysql插入路径_Conventional-pathinsert(传统路径插入)