• 阿里云短信业务 登入功能 Gitee源码分享 vue3+springboot


    目录

    🚒登入功能展示🚒

    🛺项目代码介绍🛺

    🚗前端目录🚗

    🚓后端目录🚓

    🚔部分核心代码演示🚔

    🚘前端:登入页面🚘

    🚖后端 🚖

    🧰项目功能介绍🧰


    🚒登入功能展示🚒

    🛺项目代码介绍🛺

    🚗前端目录🚗

    🚓后端目录🚓

    🚔部分核心代码演示🚔

    🚘前端:登入页面🚘

    1. <script setup lang="ts">
    2. import { reactive } from 'vue';
    3. import { toSendMessage ,toCheckLogin} from './request/api';
    4. //数据定义
    5. const data=reactive({
    6. //提示框信息
    7. content:"发送验证码",
    8. //倒计时秒数
    9. totalTime:60,
    10. //输入电话号码
    11. phoneNumber:"",
    12. //输入验证码
    13. code:"",
    14. })
    15. //请求发送验证码
    16. const toCountdown=()=>{
    17. //发送验证码接口
    18. toSendMessage(data.phoneNumber).then((res)=>{
    19. console.log(res.data);
    20. })
    21. //点击倒计时
    22. let clock = window.setInterval(() => {
    23. data.content = data.totalTime + 's';
    24. data.totalTime --;
    25. if( data.totalTime < 0){
    26. data.totalTime = 60;
    27. data.content = "发送验证码";
    28. window.clearInterval(clock);
    29. }
    30. }, 1000);
    31. }
    32. //用户登入
    33. const toLogin=()=>{
    34. toCheckLogin(data.phoneNumber,data.code).then(res=>{
    35. console.log(res.data);
    36. })
    37. }
    38. script>
    39. <template>
    40. <div class="login-bg">
    41. <div class="content">
    42. <div class="title">
    43. <h2>LOGINh2>
    44. div>
    45. <div class="form-box">
    46. <div class="login-center">
    47. <span class="t-name">手机号:
    48. ><input
    49. type="text"
    50. name=""
    51. id="tel_num"
    52. class="inp phone-inp"
    53. placeholder="请输入您的手机号"
    54. v-model="data.phoneNumber"
    55. />
    56. div>
    57. <div class="login-center">
    58. <span class="t-name">验证码:
    59. ><input
    60. type="text"
    61. name=""
    62. id="code_num"
    63. class="inp code-inp"
    64. v-model="data.code"
    65. placeholder="请输入您的验证码"
    66. />
    67. <div class="get-code ">
    68. <span class="code-btn" :class="{ 'code-stop' : data.totalTime!=60}" @click="toCountdown">{{data.content}}span>
    69. div>
    70. div>
    71. <div class="login-button" @click="toLogin">登陆div>
    72. div>
    73. div>
    74. div>
    75. template>
    76. <style lang="scss" scoped>
    77. .content {
    78. position: absolute;
    79. width: 500px;
    80. height: 450px;
    81. background-color: #00000060;
    82. border-radius: 10px;
    83. top: 50%;
    84. left: 50%;
    85. margin-left: -240px;
    86. margin-top: -240px;
    87. padding: 10px 20px;
    88. box-sizing: border-box;
    89. text-align: center;
    90. }
    91. .title h2 {
    92. font-size: 45px;
    93. line-height: 60px;
    94. color: #ffffff90;
    95. font-weight: bold;
    96. text-align: center;
    97. }
    98. .login-center {
    99. height: 50px;
    100. border-radius: 5px;
    101. border: 1px solid #00aced;
    102. margin-bottom: 30px;
    103. line-height: 50px;
    104. padding: 0 10px;
    105. box-sizing: border-box;
    106. color: #fff;
    107. input {
    108. color: #fff;
    109. }
    110. }
    111. .login-center .t-name {
    112. font-size: 20px;
    113. float: left;
    114. height: 100%;
    115. width: 85px;
    116. }
    117. .login-center .inp {
    118. font-size: 24px;
    119. float: left;
    120. border: none;
    121. background: transparent;
    122. height: 100%;
    123. outline: none;
    124. }
    125. .login-center .inp.code-inp {
    126. width: 220px;
    127. }
    128. .login-center .get-code {
    129. float: right;
    130. width: 100px;
    131. height: 100%;
    132. }
    133. .login-center .get-code .code-btn {
    134. color: gold;
    135. font-size: 16px;
    136. width: 100%;
    137. border: 1px solid gold;
    138. border-radius: 5px;
    139. padding: 5px;
    140. box-sizing: border-box;
    141. cursor: pointer;
    142. }
    143. .code-stop{
    144. //禁止点击
    145. pointer-events: none;
    146. }
    147. .login-button {
    148. background-image: linear-gradient(to right, #30cfd0, #330867);
    149. height: 50px;
    150. border-radius: 5px;
    151. font-size: 18px;
    152. color: #fff;
    153. text-align: center;
    154. line-height: 50px;
    155. cursor: pointer;
    156. }
    157. style>

    🚖后端 🚖

    1. /**
    2. * @Description 用户接口实现
    3. * @Author 小乌龟
    4. * @Date 2022/9/14 9:50
    5. */
    6. @Service
    7. public class UserServiceImpl implements UserService {
    8. @Resource
    9. private RedisTemplate redisTemplate;
    10. @Override
    11. public String toSendMessage(String phoneNumber) {
    12. //扩展 可以验证该电话号码是否注册
    13. //1.判定验证码是否过期
    14. String code = redisTemplate.opsForValue().get(phoneNumber);
    15. if (!StringUtils.isEmpty(code)){
    16. return phoneNumber+":"+"验证码未过期";
    17. }
    18. //2.已过期/无验证码 生成验证码
    19. //随机生成字符串 做验证码
    20. int toCode = (int) (Math.random() * (50000 - 40000) + 40000);
    21. code=Integer.toString(toCode);
    22. String toSendMes = SmsUtil.toSendMes(phoneNumber, code);
    23. if (Constant.OK.equals(toSendMes)){
    24. //redis 中存放 5分钟过期
    25. redisTemplate.opsForValue().set(phoneNumber,code,Constant.NUM_FIVE, TimeUnit.MINUTES);
    26. //3.发送短信
    27. return "短信发送成功";
    28. }
    29. return "短信发送异常";
    30. }
    31. @Override
    32. public String checkLogin(String phoneNumber, String code) {
    33. //1.redis 验证码校验
    34. String redisCode = redisTemplate.opsForValue().get(phoneNumber);
    35. if (code.equals(redisCode)){
    36. return "登入成功";
    37. }
    38. return "登入失败";
    39. }
    40. }

    🏀项目jar包🏀

    1. org.springframework.boot
    2. spring-boot-starter-web
    3. com.aliyun
    4. aliyun-java-sdk-core
    5. 4.6.0
    6. com.aliyun
    7. aliyun-java-sdk-dysmsapi
    8. 1.1.0
    9. com.alibaba
    10. fastjson
    11. 1.2.76
    12. org.springframework.boot
    13. spring-boot-starter-data-redis
    14. org.projectlombok
    15. lombok
    16. true
    17. org.springframework.boot
    18. spring-boot-starter-test
    19. test

    🏐redis配置🏐

    1. /**
    2. * @author 小乌龟 redis配置
    3. */
    4. @Configuration
    5. public class RedisConfig extends CachingConfigurerSupport {
    6. //操纵缓存的模板
    7. @Bean
    8. @SuppressWarnings("all")
    9. @ConditionalOnMissingBean(name = "redisTemplate")
    10. public RedisTemplate redisTemplate(RedisConnectionFactory factory) {
    11. RedisTemplate template = new RedisTemplate();
    12. template.setConnectionFactory(factory);
    13. // Json序列化配置
    14. Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
    15. ObjectMapper om = new ObjectMapper();
    16. //日期格式化
    17. om.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
    18. // 日期序列化处理
    19. om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    20. om.registerModule(new Jdk8Module())
    21. .registerModule(new JavaTimeModule())
    22. .registerModule(new ParameterNamesModule());
    23. om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    24. om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_ARRAY);
    25. jackson2JsonRedisSerializer.setObjectMapper(om);
    26. // String 的序列化
    27. StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
    28. // key采用String的序列化方式
    29. template.setKeySerializer(stringRedisSerializer);
    30. // hash的key也采用String的序列化方式
    31. template.setHashKeySerializer(stringRedisSerializer);
    32. // value序列化方式采用jackson
    33. template.setValueSerializer(jackson2JsonRedisSerializer);
    34. // hash的value序列化方式采用jackson
    35. template.setHashValueSerializer(jackson2JsonRedisSerializer);
    36. //将默认的序列化方式改成StringRedisSerializer
    37. template.setDefaultSerializer(stringRedisSerializer);
    38. template.afterPropertiesSet();
    39. return template;
    40. }
    41. }

    🧰项目功能介绍🧰

    🥰短信登入功能实现🥰

         🍳前端 vue3+axios🍳      

    🥨 后端 springboot+redis🥨

    🥐项目精简 不引入过多框架🥐

    🌯登入功能实现🌯

    🥙具体功能演示🥙

    🍵B站视频🍵

    🐎源码的分享🐎

    🦌视频简介中🦌

    🦬前后端gitee🦬

    🫖感谢大家的三连支持🫖

     

  • 相关阅读:
    9步打造个人ip
    picoctf_2018_got_shell
    分享下我的tmux配置
    Python武器库开发-flask篇之URL重定向(二十三)
    keepalived+nginx高可用 脑裂监控
    ABAP SLG1/SLG0 应用日志 自己封装类 记录
    【UE】刀光粒子效果——part1
    XML外部实体漏洞 (XXE)简介
    软信天成:如何做好数据治理?这三点必不可少
    在Ubuntu系统上实现免费电脑IP更改
  • 原文地址:https://blog.csdn.net/Little___Turtle/article/details/126896823