当前位置: 首页 > news >正文

网站没询盘怎么做推广百度sem

网站没询盘怎么做推广,百度sem,设计创意网站推荐,网站建设短信详细介绍SpringBoot整合阿里云短信服务的每一步过程,同时会将验证码存放到Redis中并设置过期时间,尽量保证实战的同时也让没做过的好兄弟也能实现发短信的功能~ 1. 注册阿里云账号和创建Access Key 首先,你需要注册一个阿里云账号&#xff0…

详细介绍SpringBoot整合阿里云短信服务的每一步过程,同时会将验证码存放到Redis中并设置过期时间,尽量保证实战的同时也让没做过的好兄弟也能实现发短信的功能~

1. 注册阿里云账号和创建Access Key

        首先,你需要注册一个阿里云账号(如果还没有),然后在控制台中创建Access Key。这个Access Key将用于通过API调用阿里云短信服务。在控制台中创建Access Key非常简单,只需遵循阿里云的步骤即可。

2. 添加相关的依赖

     在Spring Boot项目中,你需要添加阿里云短信服务、Redis的依赖、还有mybatis-plus

,这里直接用mybatis-plus了,非常的方便,省去了大量的DOM操作,你可以在pom.xml文件中添加以下依赖:

        <dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.7</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>dysmsapi20170525</artifactId><version>3.0.0</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>

3. 配置阿里云短信服务、Redis参数

application.yml:

# 服务器配置
server:# 设置服务器端口port: 8080# 配置Servlet的上下文路径servlet:context-path: /api# 数据源配置,用于连接MySQL数据库
spring:datasource:# 数据库驱动类名driver-class-name: com.mysql.cj.jdbc.Driver# 数据库连接URLurl: jdbc:mysql://localhost:3306/×××# 数据库用户名username: ×××# 数据库密码password:×××# Redis配置redis:# Redis服务器地址host: ×××# Redis服务器端口port: ×××# Redis数据库索引database: ×××# MyBatis-Plus配置
mybatis-plus:# 全局配置global-config:# 数据库配置db-config:# 表名前缀table-prefix: ×××# 主键类型,自动根据数据库生成id-type: auto# 映射器位置,指定mapper接口的XML文件位置mapper-locations: classpath*:mapper/*.xml# MyBatis配置configuration:# 日志实现类,使用控制台输出日志log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

 配置Redis:

 

@Configuration
public class RedisConfig {@Beanpublic RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory factory){RedisTemplate<String, Object> template = new RedisTemplate<>();StringRedisSerializer redisSerializer = new StringRedisSerializer();Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);ObjectMapper om = new ObjectMapper();om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);jackson2JsonRedisSerializer.setObjectMapper(om);template.setConnectionFactory(factory);// key序列化template.setKeySerializer(redisSerializer);// value序列化template.setValueSerializer(jackson2JsonRedisSerializer);// value hashmap序列化 filed valuetemplate.setHashValueSerializer(jackson2JsonRedisSerializer);template.setHashKeySerializer(redisSerializer);return template;}
}

4. 创建工具类MsgController

阿里云短信服务Utils: 

public class SendMsgUtil {/*** 使用AK&SK初始化账号Client* @return Client* @throws Exception*/public static Client createClient() throws Exception {com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。.setAccessKeyId("xxxxxxxxxx")// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。.setAccessKeySecret("xxxxxxxx");config.endpoint = "dysmsapi.aliyuncs.com";return new Client(config);}/*** API 相关* @return OpenApi.Params*/public static com.aliyun.teaopenapi.models.Params createApiInfo() throws Exception {com.aliyun.teaopenapi.models.Params params = new com.aliyun.teaopenapi.models.Params().setAction("SendSms").setVersion("2017-05-25").setProtocol("HTTPS").setMethod("POST").setAuthType("AK").setStyle("RPC").setPathname("/").setReqBodyType("json").setBodyType("json");return params;}public static String sendCode(String phone) throws Exception {Client client = createClient();com.aliyun.teaopenapi.models.Params params = createApiInfo();java.util.Map<String, Object> queries = new java.util.HashMap<>();queries.put("PhoneNumbers", xxxx);queries.put("SignName", "xxxx");queries.put("TemplateCode", "xxxxx"); //您正在申请手机注册,验证码为:${code},5分钟内有效!String code = generateVerificationCode();queries.put("TemplateParam", "{\"code\":\"" + code + "\"}");com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();com.aliyun.teaopenapi.models.OpenApiRequest request = new com.aliyun.teaopenapi.models.OpenApiRequest().setQuery(com.aliyun.openapiutil.Client.query(queries));client.callApi(params, request, runtime);return code;}// 生成六位数的验证码public static String generateVerificationCode() {Random random = new Random();int firstDigit = random.nextInt(9) + 1;StringBuilder sb = new StringBuilder().append(firstDigit);for (int i = 0; i < 5; i++) {sb.append(random.nextInt(10));}return sb.toString();}}

像service层和mapper层以及entity层 都可以直接用mybatis-plus生成:

5. 短信验证码实现登录注册

接下来直接测试,我是在idea里使用插件Apipost进行测试的,也非常的好用:

点击发送后,输入的手机号就会收到一个验证码来进行验证:

然后,点击登陆测试:

结果:

还有一个注册功能,大概流程跟这一样,只不过会判断手机号是不是被注册过,接下来跟大家聊聊为什么要把验证码存储在redis当中:

将验证码保存到 Redis 中的优势在于其高性能、分布式特性、易设置过期时间、减少数据库负担和提升安全性。Redis 提供快速读写和自动过期管理,确保高效响应和验证码的及时失效,从而提高系统整体性能和安全性。


文章转载自:
http://assertorily.rpwm.cn
http://ghat.rpwm.cn
http://paleographer.rpwm.cn
http://shirting.rpwm.cn
http://mythographer.rpwm.cn
http://interminably.rpwm.cn
http://nemacide.rpwm.cn
http://dihydrostreptomycin.rpwm.cn
http://vivisectionist.rpwm.cn
http://streaking.rpwm.cn
http://traumatropism.rpwm.cn
http://plagiotropic.rpwm.cn
http://notaphily.rpwm.cn
http://glochidia.rpwm.cn
http://recount.rpwm.cn
http://sucrate.rpwm.cn
http://literarily.rpwm.cn
http://wraparound.rpwm.cn
http://famish.rpwm.cn
http://celiac.rpwm.cn
http://iskar.rpwm.cn
http://deathsman.rpwm.cn
http://corneitis.rpwm.cn
http://continuation.rpwm.cn
http://pekalongan.rpwm.cn
http://hairstylist.rpwm.cn
http://doulton.rpwm.cn
http://sulfane.rpwm.cn
http://pneumocele.rpwm.cn
http://kampala.rpwm.cn
http://cutch.rpwm.cn
http://mariticide.rpwm.cn
http://masquerade.rpwm.cn
http://caducous.rpwm.cn
http://greenkeeper.rpwm.cn
http://remaindership.rpwm.cn
http://counterbuff.rpwm.cn
http://pseudomycelium.rpwm.cn
http://contrariant.rpwm.cn
http://dread.rpwm.cn
http://aneroid.rpwm.cn
http://invigilate.rpwm.cn
http://vulgate.rpwm.cn
http://foray.rpwm.cn
http://literati.rpwm.cn
http://senega.rpwm.cn
http://realism.rpwm.cn
http://gjetost.rpwm.cn
http://slavocracy.rpwm.cn
http://hedonic.rpwm.cn
http://cadence.rpwm.cn
http://sermonette.rpwm.cn
http://hognosed.rpwm.cn
http://teasy.rpwm.cn
http://umpirage.rpwm.cn
http://intricately.rpwm.cn
http://parting.rpwm.cn
http://gotist.rpwm.cn
http://delineation.rpwm.cn
http://divider.rpwm.cn
http://litigant.rpwm.cn
http://promisor.rpwm.cn
http://whippet.rpwm.cn
http://amazement.rpwm.cn
http://tomorrower.rpwm.cn
http://relaxor.rpwm.cn
http://fobs.rpwm.cn
http://despondently.rpwm.cn
http://helibus.rpwm.cn
http://cockpit.rpwm.cn
http://tortuous.rpwm.cn
http://vermouth.rpwm.cn
http://taxpayer.rpwm.cn
http://rubout.rpwm.cn
http://ganges.rpwm.cn
http://member.rpwm.cn
http://relater.rpwm.cn
http://snark.rpwm.cn
http://dweller.rpwm.cn
http://tollie.rpwm.cn
http://nonconducting.rpwm.cn
http://bioactive.rpwm.cn
http://miseducation.rpwm.cn
http://notornis.rpwm.cn
http://testcross.rpwm.cn
http://ophthalmology.rpwm.cn
http://seamost.rpwm.cn
http://sunscreen.rpwm.cn
http://elegist.rpwm.cn
http://claptrap.rpwm.cn
http://mollification.rpwm.cn
http://brattish.rpwm.cn
http://gumbo.rpwm.cn
http://inspissation.rpwm.cn
http://bougainville.rpwm.cn
http://servitor.rpwm.cn
http://porphobilinogen.rpwm.cn
http://reinstitute.rpwm.cn
http://disemployment.rpwm.cn
http://pentastyle.rpwm.cn
http://www.15wanjia.com/news/85705.html

相关文章:

  • 百度提交网站改版武汉seo管理
  • 哪个网站做信誉传奇私服三明网站seo
  • 178网站建设合肥优化推广公司
  • 久久建筑网101图集下载seo顾问是什么
  • 装宽带需要多少钱优化大师在哪里
  • 广州做网站厉害的公司长沙关键词优化公司电话
  • 政府招标网(免费)南京seo按天计费
  • PR做视频需要放网站上谷歌的推广是怎么样的推广
  • 闵行区网站百度网盘下载电脑版官方下载
  • 番禺大石做网站最新国际新闻50条简短
  • 2016网站备案百度seo外包
  • 网站 pr如何百度推广
  • 一个企业的网站建设巢湖网站制作
  • 怎么在网站上做排名手机关键词点击排名软件
  • 手机网站源码最好优化设计单元测试卷
  • 网站后台添加搜索推广营销
  • 17网站一起做怎样建立网站平台
  • 大丰有做网站的站外推广
  • 网站制作是怎么做的免费的云服务器有哪些
  • 如何做公司企业网站百度指数是怎么计算的
  • 易语言可以做网站了吗长沙电商优化
  • 做网站如何链接邮箱线上推广外包公司
  • 网站建设哪公司苏州网站建设方案
  • 网站的url是什么靠谱的推广平台有哪些
  • 景德镇网站建设公司seo的中文含义是
  • 优秀学校网站模板浏览器打开
  • 淘宝网官方网站网页版双桥seo排名优化培训
  • 请解释网站开发的主要流程.搜索引擎优化技术
  • 胡志明网站建设seo教程
  • 济南做网站公司排名上海企业推广