导入上面jar包

<dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-core</artifactId><version>4.5.3</version>
</dependency>

service类:

package com.bing.jedis_test1;import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;import java.util.Map;public class SmsBing {public boolean sendSms(String phoneName, Map<String,Object> code){DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4FzoxT6Zxxxxx", "WyGf440RLZl9jW0Nrexxxxx");IAcsClient client = new DefaultAcsClient(profile);CommonRequest request = new CommonRequest();request.setSysMethod(MethodType.POST);request.setSysDomain("dysmsapi.aliyuncs.xxx");request.setSysVersion("2017-05-25");request.setSysAction("SendSms");//模板编号和签名可以做成变量 ------SignName-------TemplateCoderequest.putQueryParameter("PhoneNumbers", phoneName);request.putQueryParameter("SignName", "短信注册功能"); // 去阿里云短信验证request.putQueryParameter("TemplateCode", "SMS_205xxxxx");request.putQueryParameter("TemplateParam", JSONObject.toJSONString(code));try {CommonResponse response = client.getCommonResponse(request);System.out.println(response.getData());return  true;} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {e.printStackTrace();}return false;}
}

controller层调用:

package com.bing.jedis_test1;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;public class SmsAction {@AutowiredSmsBing smsBing;@AutowiredRedisTemplate redisTemplate;@RequestMapping("/sms")public String Sms(@RequestParam(required = true) String phone){String code = (String) redisTemplate.opsForValue().get("phone");if(!StringUtils.isEmpty(code)){return phone+"此号码存在,验证码为"+code;}String substring = UUID.randomUUID().toString().substring(0, 4);Map<String,Object> map = new HashMap<>();map.put(code,substring);boolean isSend = smsBing.sendSms(phone, map);if(isSend){redisTemplate.opsForValue().set(phone, code, 30, TimeUnit.SECONDS);return "号码发送成功,请注意查收,号码在30秒后过期";}else{return "发送失败";}}
}

调用action执行方法测试。

springboot整合阿里云短信验证服务相关推荐

  1. springboot整合阿里云短信验证(无需签名和模板,通过阿里云api测试实现短信验证)

    一.开通阿里云短信服务 开通步骤如下图所示 开通完成后,进入阿里云短信验证首页,点击国内消息 一般来说,在短信验证时需要签名管理和模板管理,但是签名管理需要备案或者上线服务,所以对于没有备案和上线应用 ...

  2. SpringBoot整合阿里云短信服务详细过程(保证初学者也能实现)

    前言 网上关于实操性的文章普遍大部分都记录不全,要么只记录重点部分,对于刚学习的小伙伴来说看起来是比较困难的 所以,基于这一点. 该文章会详细介绍使用SpringBoot整合阿里云短信服务的每一步过程 ...

  3. Springboot+redis+榛子云短信验证服务进行登录

    Springboot+redis+榛子云短信验证服务进行登录 前言 最近在做尚医通的医院预约挂号管理系统时,做到了使用阿里云的短信验证服务,但是现在阿里云的短信验证服务审核听说非常严格,主要是我没有专 ...

  4. 阿里云短信验证服务详细基础教程

    阿里云短信验证服务 1. 注册一个阿里云的帐号 2. 在搜索栏搜索短信服务 3. 点击免费开通 4.开通之后点击管理控制台 5. 获取AccessKey 6. 创建AccessKey并保存,后面会用到 ...

  5. Springboot整合阿里云短信服务

    目录 一.阿里云短信配置 1.开通短信服务​ 2. 申请模板 3.申请签名 二.springboot中集成阿里云短信服务 0.pom中引入依赖 1.配置application.properties 2 ...

  6. node开通阿里云短信验证服务,代码演示 超级详细

    阿里云官网步骤:Node.js SDK (aliyun.com) 首先先搭建一个node项目:app.js const express = require('express'); // 引入 Expr ...

  7. SpringBoot集成阿里云短信服务

    SpringBoot集成阿里云短信服务 1.准备工作 2.项目集成 2.1 添加依赖 2.2 配置文件 2.3 业务逻辑实现 在实际项目中经常有发送短信的功能,今天进说一下对接阿里云短信服务实现短信发 ...

  8. springboot集成阿里云短信服务,实现发送短信功能

    springboot集成阿里云短信服务,实现发送短信功能 准备工作: 1.登陆阿里云->进入控制台->开通短信服务(进入后根据提示开通) 2.充值(借人家平台发短信你以为不要钱的?我充了3 ...

  9. 阿里云短信验证-PHP

    阿里云短信验证-PHP 场景:平台注册,登陆短信验证 参考阿里官方教程 阿里云短信验证-快速入门 前提条件: 产品->云计算产品->短信服务 开通短信服务 创建AccessKey 申请短信 ...

最新文章

  1. Logback也爆漏洞了,总结下最近log相关的几个漏洞
  2. python使用笔记:if __name__ == ‘__main__‘ 如何理解
  3. 浅谈移动端中的视口(viewport)
  4. linux下git分支管理,git远程分支管理
  5. ecplise ee下载安装教程+SpringMVC的helloword
  6. 浅谈 MySQL 中优化 SQL 语句查询常用的 30 种方法
  7. protobuf 数据解析的2种方法
  8. ELK套件FileBeat部署
  9. OJ1159: 最大的两个数(指针专题)(C语言)
  10. 小林菌2020总结,我差点没毕业~
  11. sort it 树状数组+逆序对
  12. Quartz简答介绍
  13. GitHub 学习和使用
  14. 苹果电脑删除下载的更新文件_解决电脑管家病毒库更新误删除T6文件方法
  15. 05_家谱管理系统(小钱版)[数据结构][2012-02-03]
  16. 软件测试面试宝典【测试流程、数据库、Linux、测试工具、自动化、性能测试】
  17. 我的世界java怎么自制皮肤_我的世界手机版皮肤怎么做 自己做皮肤教程
  18. 2020PAT甲级秋季7-4 Professional Ability Test (30分)
  19. Android零基础开发到项目实战
  20. 高中数学补习:集合与常用逻辑用语

热门文章

  1. 省赛题第六届到第十二届单独分析
  2. 四级真题之2011年6月份
  3. C/C++零基础开发,实现五指棋游戏!小白也能学会
  4. WPF中检测U盘插入、拔出 实例
  5. 火线魔盒服务器不稳定,火线魔盒怎么使用?火线魔盒使用教程
  6. 华为离职副总裁徐家骏的工作感悟
  7. Java正则表达式功能及应用(上)
  8. ROS之mocap_optitrack
  9. 苦小帕帕:教你们一个快速让电脑关机重启的C++小病毒:
  10. 男士健康不可缺的11种食物