如何使用阿里云短信服务实现登录页面,手机验证码登录?

article/2025/10/13 0:48:28

1:个人如何使用阿里云短信服务?

2022如何使用个人阿里云短信服务?_linxiMY的博客-CSDN博客添加完成之后,等待审核!一般2个小时就会出来审核结果了,这里我因为注册申请时填写规则有误,足足审核了7次才通过!点击进来以后,按照要求填写:因为一个账号只能选购一种,所以我这里就没法仔细演示了。然后点击添加即可,一把2-3个小时就可以申请出结果了。ConstantPropertiesUtils 工具类。点击登录阿里云短信服务控制台--->点击。3:创建一个SpringBoot 启动类。将下面的服务地址改为自己对应的地址。AccessKey 保存下来!4:添加一个配置工具类类。开启启动类调接口测试。https://blog.csdn.net/XikYu/article/details/127617049?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168232320316800192242795%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=168232320316800192242795&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-1-127617049-null-null.blog_rank_default&utm_term=%E9%98%BF%E9%87%8C%E4%BA%91&spm=1018.2226.3001.4450

2:直接上代码

2.1:建表SQL

CREATE TABLE `sys_user`
(`id`          varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'id',`username`    varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '用户名',`password`    varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '密码',`nickname`    varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '昵称',`email`       varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '邮箱',`phone`       varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '电话',`address`     varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '地址',`create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',`avatarUrl`   varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '头像',PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

2.2:后端代码

引入pom.xml 依 赖:

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

yml 文件:

server:port: 9999
spring:application:name: demo-enddatasource:druid:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3306/数据库?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=trueusername: rootpassword: rootredis:host: ip地址port: 6379lettuce:pool:max-active: 8 # ????max-idle: 8 # ??????min-idle: 0 # ??????max-wait: 100ms # ??????
mybatis:configuration:map-underscore-to-camel-case: truelog-impl: org.apache.ibatis.logging.stdout.StdOutImplmapper-locations: classpath:mapper/*.xmltype-aliases-package: com.xi.demoend.entity

application.properties:


aliyun.sms.regionId=default
aliyun.sms.accessKeyId=LTAI5tBP98NtTK3gC5mgRQBz
aliyun.sms.secret=gH1w8F0jEWVXSiClmAAnowRw93YTFg

common公共包下的类:

 全局统一返回结果:

package com.xialj.demoend.common;import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/*** @Author * @Date Created in  2023/2/23 17:25* @DESCRIPTION:  全局统一返回结果* @Version V1.0*/
@Data
@ApiModel(value = "全局统一返回结果")
@SuppressWarnings("all")
public class Result<T> {@ApiModelProperty(value = "返回码")private Integer code;@ApiModelProperty(value = "返回消息")private String message;@ApiModelProperty(value = "返回数据")private T data;private Long total;public Result(){}protected static <T> Result<T> build(T data) {Result<T> result = new Result<T>();if (data != null)result.setData(data);return result;}public static <T> Result<T> build(T body, ResultCodeEnum resultCodeEnum) {Result<T> result = build(body);result.setCode(resultCodeEnum.getCode());result.setMessage(resultCodeEnum.getMessage());return result;}public static <T> Result<T> build(Integer code, String message) {Result<T> result = build(null);result.setCode(code);result.setMessage(message);return result;}public static<T> Result<T> ok(){return Result.ok(null);}/*** 操作成功* @param data* @param <T>* @return*/public static<T> Result<T> ok(T data){Result<T> result = build(data);return build(data, ResultCodeEnum.SUCCESS);}public static<T> Result<T> fail(){return Result.fail(null);}/*** 操作失败* @param data* @param <T>* @return*/public static<T> Result<T> fail(T data){Result<T> result = build(data);return build(data, ResultCodeEnum.FAIL);}public Result<T> message(String msg){this.setMessage(msg);return this;}public Result<T> code(Integer code){this.setCode(code);return this;}public boolean isOk() {if(this.getCode().intValue() == ResultCodeEnum.SUCCESS.getCode().intValue()) {return true;}return false;}
}

 统一返回结果状态信息类:

package com.xialj.demoend.common;import lombok.Getter;/*** @Author * @Date Created in  2023/2/23 17:25* @DESCRIPTION:  统一返回结果状态信息类* @Version V1.0*/
@Getter
@SuppressWarnings("all")
public enum ResultCodeEnum {SUCCESS(200,"成功"),FAIL(201, "失败"),PARAM_ERROR( 202, "参数不正确"),SERVICE_ERROR(203, "服务异常"),DATA_ERROR(204, "数据异常"),DATA_UPDATE_ERROR(205, "数据版本异常"),LOGIN_AUTH(208, "未登陆"),PERMISSION(209, "没有权限"),CODE_ERROR(210, "验证码错误"),
//    LOGIN_MOBLE_ERROR(211, "账号不正确"),LOGIN_DISABLED_ERROR(212, "改用户已被禁用"),REGISTER_MOBLE_ERROR(213, "手机号码格式不正确"),REGISTER_MOBLE_ERROR_NULL(214, "手机号码为空"),LOGIN_AURH(214, "需要登录"),LOGIN_ACL(215, "没有权限"),URL_ENCODE_ERROR( 216, "URL编码失败"),ILLEGAL_CALLBACK_REQUEST_ERROR( 217, "非法回调请求"),FETCH_ACCESSTOKEN_FAILD( 218, "获取accessToken失败"),FETCH_USERINFO_ERROR( 219, "获取用户信息失败"),//LOGIN_ERROR( 23005, "登录失败"),PAY_RUN(220, "支付中"),CANCEL_ORDER_FAIL(225, "取消订单失败"),CANCEL_ORDER_NO(225, "不能取消预约"),HOSCODE_EXIST(230, "医院编号已经存在"),NUMBER_NO(240, "可预约号不足"),TIME_NO(250, "当前时间不可以预约"),SIGN_ERROR(300, "签名错误"),HOSPITAL_OPEN(310, "医院未开通,暂时不能访问"),HOSPITAL_LOCK(320, "医院被锁定,暂时不能访问"),HOSPITAL_LOCKKEY(330,"医院对应key不一致");private Integer code;private String message;private ResultCodeEnum(Integer code, String message) {this.code = code;this.message = message;}
}

untils包下的工具类:

ConstantPropertiesUtils 用来读取 application.properties文件中的配置

package com.xialj.demoend.utils;import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/*** @Author * @Date Created in  2023/2/23 17:25* @DESCRIPTION:* @Version V1.0*/
@Component
public class ConstantPropertiesUtils implements InitializingBean {//InitializingBean  初始化bean  让spring 容器一初始化就加载@Value("${aliyun.sms.regionId}")private String regionId;@Value("${aliyun.sms.accessKeyId}")private String accessKeyId;@Value("${aliyun.sms.secret}")private String secret;public static String REGION_Id;public static String ACCESS_KEY_ID;public static String SECRECT;@Overridepublic void afterPropertiesSet() throws Exception {REGION_Id=regionId;ACCESS_KEY_ID=accessKeyId;SECRECT=secret;}
}

 RandomUtil 工具类用来生成6位验证码:

package com.xialj.demoend.utils;import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
/*** @Author * @Date Created in  2023/2/23 17:25* @DESCRIPTION:* @Version V1.0*/
@SuppressWarnings("ALL")
public class RandomUtil {private static final Random random = new Random();private static final DecimalFormat fourdf = new DecimalFormat("0000");private static final DecimalFormat sixdf = new DecimalFormat("000000");public static String getFourBitRandom() {return fourdf.format(random.nextInt(10000));}public static String getSixBitRandom() {return sixdf.format(random.nextInt(1000000));}/*** 给定数组,抽取n个数据* @param list* @param n* @return*/public static ArrayList getRandom(List list, int n) {Random random = new Random();HashMap<Object, Object> hashMap = new HashMap<Object, Object>();// 生成随机数字并存入HashMapfor (int i = 0; i < list.size(); i++) {int number = random.nextInt(100) + 1;hashMap.put(number, i);}// 从HashMap导入数组Object[] robjs = hashMap.values().toArray();ArrayList r = new ArrayList();// 遍历数组并打印数据for (int i = 0; i < n; i++) {r.add(list.get((int) robjs[i]));System.out.print(list.get((int) robjs[i]) + "\t");}System.out.print("\n");return r;}
}

User实体类:(实现了简单的手机验证码登录+email邮箱登录)

package com.xialj.demoend.entity;import com.alibaba.druid.sql.visitor.functions.Insert;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;/*** @Author * @Date Created in  2023/2/24 13:07* @DESCRIPTION:   User 实体类* @Version V1.0*/@Data
public class User extends PageQuery implements Serializable {private static final long serialVersionUID = 1L;/*** id*/private String id;/*** 用户名*/private String username;/*** 密码*/private String password;/*** 昵称*/private String nickname;/*** 邮箱*/@ApiModelProperty(value = "联系人邮箱")@NotBlank(message = "邮箱不能为空", groups = {Insert.class})@NotNull(message = "邮箱不能为空", groups = {Insert.class})@Pattern(regexp = ".+@.+\\.com$", message = "Email格式不正确")private String email;/*** 电话*/@ApiModelProperty(value = "联系人电话")@NotBlank(message = "手机号码不能为空", groups = {Insert.class})@NotNull(message = "手机号不能为空", groups = {Insert.class})@Length(min = 11, max = 11, message = "手机号只能为11位")@Pattern(regexp = "^[1][3,4,5,6,7,8,9][0-9]{9}$", message = "手机号格式有误")private String phone;/*** 地址*/private String address;/*** 验证码*/private Integer code;/*** 创建时间*/@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")private Date createTime;/*** 头像*/private String avatarUrl;
}

MsmApiController:用来实现发送验证码的接口

package com.xialj.demoend.controller;import cn.hutool.extra.mail.MailUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xialj.demoend.common.Result;
import com.xialj.demoend.common.ResultCodeEnum;
import com.xialj.demoend.common.paramCommon;
import com.xialj.demoend.entity.User;
import com.xialj.demoend.service.MsmService;
import com.xialj.demoend.utils.JsonSerializer;
import com.xialj.demoend.utils.RandomUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;import javax.mail.MessagingException;
import javax.validation.constraints.Email;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/*** @Author xlj* @Date Created in  2023/2/23 17:25* @DESCRIPTION:  主要是为了实现邮箱发送验证码,以及手机发送验证码登录* @Version V1.0*/
@RestController
@RequestMapping("/api/msm")
@SuppressWarnings("ALL")
@Slf4j
@CrossOrigin
public class MsmApiController {@Autowiredprivate MsmService msmService;@Autowiredprivate RedisTemplate<String,String> redisTemplate;//将手机验证码存放到redis  中,并设置过期时间@ApiOperation(value = "发送手机验证码")@PostMapping("sendPhoneCode")public Result sendCode(@RequestBody(required = true) @Validated User user){String phoneNum = user.getPhone();// phone  作为redis  中的key,  code  作为redis  中的value值String code = redisTemplate.opsForValue().get(phoneNum);if (!StringUtils.isEmpty(code)) {//这里为什么从redis 拿取 验证码  我理解的是 ,因为redis 验证码我们给他设置了时间限制,所以在规定时间内,验证码//可以多次使用,一旦时间到期之后,我们就需要从新生成6位数的验证码了。return Result.ok(code);}//生成六位验证码code = RandomUtil.getSixBitRandom();//调用service 方法,整合阿里云短信服务进行发送Boolean isSend = msmService.send(phoneNum,code);//返回的Boolean 值进行判断 ,如果发送信息成功,即存入到redis 中,如果没有则提示验证码发送失败if (isSend) {//放到redis中规定时间内有效redisTemplate.opsForValue().set(phoneNum,code,1, TimeUnit.MINUTES);redisTemplate.setDefaultSerializer(new JsonSerializer<>());
//            redisTemplate.opsForValue().set(phoneNum,code);String codeMessage = redisTemplate.opsForValue().get(phoneNum);Set<String> allKeys = redisTemplate.keys("*");for (String key : allKeys) {System.out.println(key);System.out.println(key.getClass().getName());}log.info("当前存储的验证码为:{}",codeMessage);return Result.ok(code);} else {return Result.fail().message(paramCommon.FAIL_MESSAGE);}}
}

MsmServiceImpl实现类:

package com.hospital.service.impl;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 com.hospital.service.MsmService;
import com.hospital.utils.ConstantPropertiesUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;import java.util.HashMap;
import java.util.Map;@Service
public class MsmServiceImpl implements MsmService {//根据手机号,存入验证码@Overridepublic Boolean send(String phone, String code) {//判断手机号是否为空if (StringUtils.isEmpty(phone)) {return false;}//整合阿里云的短信服务DefaultProfile profile = DefaultProfile.getProfile(ConstantPropertiesUtils.REGION_Id,ConstantPropertiesUtils.ACCESS_KEY_ID,ConstantPropertiesUtils.SECRECT);IAcsClient client = new DefaultAcsClient(profile);CommonRequest request = new CommonRequest();//request.setProtocol(ProtocolType.HTTPS);request.setMethod(MethodType.POST);request.setDomain("dysmsapi.aliyuncs.com");request.setVersion("2017-05-25");request.setAction("SendSms");
//        request.setSysAction();//手机号request.putQueryParameter("PhoneNumbers", phone);//签名名称request.putQueryParameter("SignName", "自己申请的短信签名");//模板coderequest.putQueryParameter("TemplateCode", "短信模板CODE");//验证码  使用json格式   {"code":"123456"}Map<String,Object> param = new HashMap();param.put("code",code);request.putQueryParameter("TemplateParam", JSONObject.toJSONString(param));//调用方法进行短信发送try {CommonResponse response = client.getCommonResponse(request);System.out.println(response.getData());return response.getHttpResponse().isSuccess();} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {e.printStackTrace();}return false;}
}

LoginController登录接口:(通过@Validated  对手机号,邮箱等参数进行校验)

package com.xialj.demoend.controller;import cn.hutool.core.util.StrUtil;
import com.xialj.demoend.common.Result;
import com.xialj.demoend.entity.User;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.Optional;
import java.util.function.Supplier;/*** @Author * @Date Created in  2023/3/18 14:30* @DESCRIPTION:* @Version V1.0*/
@RestController
@RequestMapping("/user/login")
@Slf4j
@CrossOrigin
public class LoginController {@Autowiredprivate RedisTemplate<String,String> redisTemplate;@ApiOperation("手机验证码登录接口")@PostMapping("/phoneCode")@SuppressWarnings("all")public Result phoneCodeLogin(@RequestBody @Validated User user) throws Throwable {Optional.ofNullable(user.getPhone()).orElseThrow((Supplier<Throwable>) () -> new RuntimeException("手机号码为null"));String phone = user.getPhone();log.info("当前获取的手机号为:{}",phone);//从redis中获取手机验证码String userPhoneKey = redisTemplate.opsForValue().get(phone);if (StringUtils.isEmpty(userPhoneKey)) {return Result.fail("手机验证码有误");}if (!userPhoneKey.equals(String.valueOf(user.getCode()))) {return Result.fail("手机验证码有误");}return Result.ok("登录成功");}
}

前端vue代码:

<template><div class="cont1" id="mainContainer" v-title data-title="若梦管理系统"><p class="tip">Click on button in image container</p><div class="cont" style="border-radius: 15px"><div class="form sign-in" style="line-height: 50px;"><h2 style="margin-top: 1px">后台管理系统</h2><el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px"><el-form-item label="手机号" prop="phone" style="width: 50%;margin-left: 110px;margin-top: 80px"><el-input v-model.number="formData.phone" placeholder="请输入手机号" :maxlength="11" show-word-limitclearableprefix-icon='el-icon-mobile-phone' :style="{width: '200px'}"></el-input></el-form-item><el-form-item label="验证码" prop="yzm" style="width: 50%;margin-left: 110px;margin-top: 50px"><el-input v-model.number="formData.yzm" :maxlength="6" :minlength="6"clearable show-word-limitprefix-icon='el-icon-chat-round'oninput="value=value.replace(/[^0-9.]/g,'')":style="{width: '200px'}"><template #append ><el-button class="test" style="width: 5px;margin-right: 10px;text-align: center;background-color: inherit;"type="danger":disabled="remainingTime > 0"@click="startTimer">{{ remainingTime > 0 ? '('+remainingTime+'s)' : '获取' }}</el-button></template></el-input></el-form-item><el-form-item><el-button type="primary" :loading="loading" @click="submitForm('/manage/home')"class="submit">登录</el-button></el-form-item></el-form></div><div class="sub-cont"><div class="img"><div class="img__text m--up"><h2>第一次来?</h2><p>注册并发现大量的新机会!</p></div><div class="img__text m--in"><h2>加入我们 ?</h2><p>如果你已经有一个账户,只需登录即可 </p><span>We've missed you!</span></div><div class="img__btn"><span class="m--up">邮箱登录</span><span class="m--in">手机登录</span></div></div><div class="form sign-up" style="line-height: 50px"><h2>Time to feel like home</h2><el-form ref="elForm2" :model="formData" :rules="rules2" size="medium" label-width="100px"><el-form-item label="电子邮箱" prop="email" style="width: 50%;margin-left: 110px;margin-top: 80px"><el-input v-model="formData.email" placeholder="请输入邮箱" show-word-limit clearableprefix-icon='el-icon-message' :style="{width: '200px'}"></el-input></el-form-item><el-form-item label="验证码" prop="yzm2" style="width: 50%;margin-left: 110px;margin-top: 50px"><el-input v-model.number="formData.yzm2" :maxlength="6" :minlength="6"clearable show-word-limitprefix-icon='el-icon-chat-round'oninput="value=value.replace(/[^0-9.]/g,'')":style="{width: '200px'}"><template #append ><el-button class="test" style="width: 5px;margin-right: 10px;text-align: center;background-color: inherit;"type="danger":disabled="remainingTime > 0"@click="startTimer2">{{ remainingTime > 0 ? '('+remainingTime+'s)' : '获取' }}</el-button></template></el-input></el-form-item><el-form-item><el-button type="primary"  :loading="loading2" @click="submitForm2('/manage/home')"class="submit">登录</el-button></el-form-item></el-form></div></div></div></div>
</template><script>
import {sendPhoneCode, sendEmailCode,phoneLogin,emailLogin} from "@/api/login.js";
export default {name: 'login',props: {msg: String},data() {return {remainingTime: 0,loading: false,loading2:false,timer: null,formData: {pwd: '',phone: '',email: '',yzm: '',yzm2: ''},rules: {phone: [{required: true,message: '请输入手机号',trigger: 'change'}, {pattern: /^1(3|4|5|7|8|9)\d{9}$/,message: '手机号格式错误',trigger: 'blur'}],yzm: [{required: true, message: '验证码不能为空', trigger: 'change'},// {type: 'number', message: '验证码必须为数字', trigger: ['blur', 'change']}],},rules2: {email: [{required: true, message: '请输入邮箱地址', trigger: 'change'},{type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change']}],yzm2: [{required: true, message: '验证码不能为空', trigger: 'change'},// {type: 'number', message: '验证码必须为数字', trigger: ['blur', 'change']}]},}},methods: {//手机号登录submitForm(path) {this.$refs['elForm'].validate(valid => {if (!valid) return// 显示loading 加载效果this.loading = true;const user = {phone:this.formData.phone,code: this.formData.yzm}this.timer = setTimeout(() => {phoneLogin(user).then( res=>{if (res.code == 200){this.$message({type: 'success',message: '登录成功!'})// 处理业务逻辑 以及发送请求this.$router.push(path)}else {this.$message({type: 'error',message: '登录失败!'});}}).finally((this.loading = false));}, 1000);})},//邮箱登录submitForm2(path) {this.$refs['elForm2'].validate(valid => {if (!valid) return// TODO 提交表单// 显示loading 加载效果this.loading2 = true;const user = {email:this.formData.email,code: this.formData.yzm2}this.timer = setTimeout(() => {// 处理业务逻辑 以及发送请求emailLogin(user).then(res=>{console.log(res)if (res.code == 200){this.$message({type: 'success',message: '登录成功!'})// 处理业务逻辑 以及发送请求this.$router.push(path)}else {this.$message({type:'error',message: '登录失败!'})}}).finally((this.loading2 = false));}, 1000);})},//发送手机验证码sendCode() {// TODO 提交表单let user ={phone:this.formData.phone}console.log(user)sendPhoneCode(user).then(res => {if (res.code == 200) {this.$message({type: 'success',message: '验证码发送成功!'})} else {this.$message({type: 'warning',message: '验证码发送失败!'});}})},startTimer() {this.$refs['elForm'].validateField('phone', valid => {if (valid) return// TODO 提交表单this.remainingTime = 60;this.sendCode()const timer = setInterval(() => {this.remainingTime--;if (this.remainingTime === 0) {clearInterval(timer);}}, 1000);})},startTimer2() {this.$refs['elForm2'].validateField('email', valid => {if (valid) return// TODO 提交表单this.remainingTime = 60;this.sendCodeTwo()const timer = setInterval(() => {this.remainingTime--;if (this.remainingTime === 0) {clearInterval(timer);}}, 1000);})},//发送邮箱验证码sendCodeTwo() {// TODO 提交表单let user ={email:this.formData.email}console.log(user)sendEmailCode(user).then(res => {if (res.code == 200) {this.$message({type: 'success',message: '验证码发送成功!'})} else {this.$message({type: 'warning',message: '验证码发送失败!'});}})},},mounted() {document.querySelector('.img__btn').addEventListener('click', function () {const contEl = document.querySelector('.cont');contEl.classList.toggle('s--signup');contEl.addEventListener('transitionend', function () {if (contEl.classList.contains('s--signup')) {contEl.querySelectorAll('input').forEach(inputEl => inputEl.value = '');}}, {once: true});});},beforeDestroy() {// eslint-disable-next-line no-irregular-whitespaceclearInterval(this.timer); // 清除定时器this.timer = null;},}</script><!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
*, *:before, *:after {box-sizing: border-box;margin: 0;padding: 0;
}input, button {border: none;outline: none;background: none;font-family: "Open Sans", Helvetica, Arial, sans-serif;
}.tip {font-size: 20px;margin: 40px auto 50px;text-align: center;
}.cont1::before {content: '';position: fixed;background-color: #ededed;width: 100%;height: 100%;left: 0;top: 0;background-image: linear-gradient(to bottom right ,#d3dae9,#14c2c2)
}.cont {overflow: hidden;position: relative;width: 900px;height: 550px;margin: 0 auto 100px;background: #fff;
}.form {position: relative;width: 640px;height: 100%;transition: transform 1.2s ease-in-out;padding: 50px 30px 0;
}.sub-cont {overflow: hidden;position: absolute;left: 640px;top: 0;width: 900px;height: 100%;padding-left: 260px;background: #fff;transition: transform 1.2s ease-in-out;
}.cont.s--signup .sub-cont {transform: translate3d(-640px, 0, 0);
}button {display: block;margin: 0 auto;width: 260px;height: 36px;border-radius: 30px;color: #fff;font-size: 15px;cursor: pointer;
}.img {overflow: hidden;z-index: 2;position: absolute;left: 0;top: 0;width: 260px;height: 100%;padding-top: 360px;
}.img:before {content: "";position: absolute;right: 0;top: 0;width: 900px;height: 100%;background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/142996/sections-3.jpg");background-size: cover;transition: transform 1.2s ease-in-out;
}.img:after {content: "";position: absolute;left: 0;top: 0;width: 100%;height: 100%;background: rgba(0, 0, 0, 0.6);
}.cont.s--signup .img:before {transform: translate3d(640px, 0, 0);
}.img__text {z-index: 2;position: absolute;left: 0;top: 50px;width: 100%;padding: 0 20px;text-align: center;color: #fff;transition: transform 1.2s ease-in-out;
}.img__text h2 {margin-bottom: 10px;font-weight: normal;
}.img__text p {font-size: 14px;line-height: 1.5;
}.cont.s--signup .img__text.m--up {transform: translateX(520px);
}.img__text.m--in {transform: translateX(-520px);
}.cont.s--signup .img__text.m--in {transform: translateX(0);
}.img__btn {overflow: hidden;z-index: 2;position: relative;width: 100px;height: 36px;margin: 0 auto;background: transparent;color: #fff;text-transform: uppercase;font-size: 15px;cursor: pointer;
}.img__btn:after {content: "";z-index: 2;position: absolute;left: 0;top: 0;width: 100%;height: 100%;border: 2px solid #fff;border-radius: 30px;
}.img__btn span {position: absolute;left: 0;top: 0;display: flex;justify-content: center;align-items: center;width: 100%;height: 100%;transition: transform 1.2s;
}.img__btn span.m--in {transform: translateY(-72px);
}.cont.s--signup .img__btn span.m--in {transform: translateY(0);
}.cont.s--signup .img__btn span.m--up {transform: translateY(72px);
}h2 {width: 100%;font-size: 26px;text-align: center;
}label {display: block;width: 260px;margin: 25px auto 0;text-align: center;
}label span {font-size: 12px;color: #cfcfcf;text-transform: uppercase;
}input {display: block;width: 100%;margin-top: 5px;padding-bottom: 5px;font-size: 16px;border-bottom: 1px solid rgba(0, 0, 0, 0.4);text-align: center;
}.forgot-pass {margin-top: 15px;text-align: center;font-size: 12px;color: #cfcfcf;
}.submit {margin-top: 30px;margin-left: 50px;margin-bottom: 10px;background: #d4af7a;/*text-transform: uppercase;*/
}.style2 {margin-top: 10px;margin-right: 100px;margin-bottom: 10px;background: darkgrey;text-transform: uppercase;
}.fb-btn {border: 2px solid #d3dae9;color: #8fa1c7;
}.fb-btn span {font-weight: bold;color: #455a81;
}.sign-in {transition-timing-function: ease-out;
}.cont.s--signup .sign-in {transition-timing-function: ease-in-out;transition-duration: 1.2s;transform: translate3d(640px, 0, 0);
}.sign-up {transform: translate3d(-900px, 0, 0);
}.cont.s--signup .sign-up {transform: translate3d(0, 0, 0);
}.icon-link {position: absolute;left: 5px;bottom: 5px;width: 32px;
}.icon-link img {width: 100%;vertical-align: top;
}.icon-link--twitter {left: auto;right: 5px;
}
.test[disabled]:not(.is-loading) {opacity: 0.5;cursor: not-allowed;width: 5px;margin-right: 10px;text-align: center;
}</style>

 页面效果图:

手机登录

 邮箱登录

 短信:

 


http://chatgpt.dhexx.cn/article/YcAA18Zr.shtml

相关文章

手机验证码登录,账号登录结合

本项目基于腾讯外包框架&#xff08;wei框架&#xff09; 地址&#xff1a;https://github.com/twinh/wei/tree/master/docs/zh-CN#wei HTML页面&#xff1a; 【基于bootstrap前端框架】 头部&#xff1a;<ul id"js-reset-tabs" class"nav tab-underline…

【手机号验证/前端】Vue2+elementUI编写一个手机号验证码登录页面,路由式开发(附完整代码)

目录 效果图&#xff1a; 一、template部分 二、style样式 三、script部分 1.先对手机号的格式进行一个判断 2.接下来就是表单验证规则rules 3.最后就是methods了 &#xff08;1&#xff09;首先我们给获取验证码绑定一个方法 &#xff08;2&#xff09;然后封装一个a…

浅谈手机验证码登录

注册和登录&#xff0c;是互联网产品的最基本功能&#xff0c;这里涉及到很多安全问题和用户便捷问题。今天&#xff0c;我们来简要聊一下手机验证码登录。 在之前的文章中&#xff0c;我们聊了注册登录原理及密码安全问题&#xff0c;这种方式是基于账号密码登录的。 然而&…

2022.9.13 手机验证码登录功能

总结一下今天在项目中完成的功能 手机验证码登录功能 用到的前端技术&#xff1a;vue、vuex、axios&#xff0c;element-ui组件库 功能实现总体思路&#xff1a; 一. 用户在登录界面输入手机号&#xff0c;通过表单验证后&#xff0c;点击按钮获取验证码 二. 用户输入手机验证…

【从零开始分析项目实战】12-阿里云手机验证码登录功能的实现

注&#xff1a;本文章基于黑马程序员相关视频及资料进行编写&#xff0c;代码简单&#xff0c;较容易理解&#xff0c;若有问题或者源码资料获取可以在评论区留言或者联系作者&#xff01; 文章目录 开篇一、短信发送&#xff08;1&#xff09;短信服务介绍&#xff08;2&#…

手机验证码登录

手机验证码登录 符号说明&#xff1a; []&#xff1a;表示可选或某些条件下流程。 需求说明&#xff1a; 用户可在登录页面使用手机验证码登录&#xff0c;若该手机号未绑定则输入验证码后还需输入用户账号密码进行绑定&#xff0c;绑定后则成功使用验证码登录。 用户可在…

登录模块(手机验证码)

本人为实习生,第一次写博客,写的不好的大家多多谅解 应公司近期需求,需要单独开发一个后台管理系统。 自己按实际业务写了一个登录接口已经实现,时序图如下 源码牵扯业务量太大,这里只放出部分关键实现源码,整合思路可以配合时序图去理解。 Controller层 package com…

java十大排序算法

十大排序算法在面试java过程中想必或多或少都会有。尤其是在笔试题上&#xff0c;有些大厂就让你现场写个十大排序。是不是一下子整懵了。。。 目录 一、首先先介绍下十大排序算法&#xff1a; 1、算法分类 2 、算法复杂度 3、 相关概念 二、详细分析各个算法 1、冒泡排…

Go语言十大排序算法

文章目录 Go语言十大排序算法0x01 冒泡排序0x02 选择排序0x03 插入排序0x04 希尔排序0x05 归并排序0x06 快速排序0x07 堆排序0x08 计数排序0x09 桶排序0x10 基数排序总结按时间复杂度分类&#xff1a;按稳定性分类按排序方式 Go语言十大排序算法 稳定&#xff1a;如果a原本在b前…

排序算法——十大排序算法总结与对比

一、十大排序算法复杂度对比 二、关于排序算法的总结 1、基数排序仅仅适用于整型数的排序&#xff0c;一般不与另外的排序方法一起比较。 2、关于算法的稳定性&#xff1a;不稳定的算法有 “快希选堆”——快速排序&#xff0c;希尔排序&#xff0c;选择排序和堆排序。 3、关…

十大排序算法(面试必备)

目录 简单排序 1、冒泡排序 2、选择排序 3、插入排序 高级排序 4、希尔排序&#xff08;缩小增量排序&#xff09; 5、归并排序 6、快速排序 7、计数排序 8、堆排序 9、桶排序 10、基数排序 总结&#xff1a; 1、十大排序算法对比 2、基数排序、计数排序、桶排序…

十大排序算法学习

Sort 排序类算法是非常常见的算法&#xff0c;包括了比较类排序与非比较类排序 排序能够解决很多问题&#xff0c;有的编程语言也提供了一些排序算法函数&#xff08;比如C的sort&#xff09;但是掌握基本的排序算法原理以及写法仍然是很重要的&#xff0c;并且排序也是面试常…

十大排序算法(Java)

目录 1.冒泡排序 2.快速排序 3.插入排序 4.希尔排序 5.选择排序 6.堆排序 7.归并排序 8.计数排序&#xff1a;速度快&#xff0c;一般用于整数排序 9.桶排序 10.基数排序 1.冒泡排序 冒泡排序思路&#xff1a;&#xff08;两层for循环&#xff09; 比较相邻的元素。…

十大排序算法(C++)

十大排序算法Sorting algorithm(C) 百度百科&#xff1a; 所谓排序&#xff0c;就是使一串记录&#xff0c;按照其中的某个或某些关键字的大小&#xff0c;递增或递减的排列起来的操作。排序算法&#xff0c;就是如何使得记录按照要求排列的方法。排序算法在很多领域得到相当地…

十大排序算法——C语言实现

1.冒泡排序 ​ 冒泡排序&#xff08;Bubble Sort&#xff09;也是一种简单直观的排序算法。它重复地走访过要排序的数列&#xff0c;一次比较两个元素&#xff0c;如果他们的顺序错误就把他们交换过来。走访数列的工作是重复地进行直到没有再需要交换&#xff0c;也就是说该数…

Python实现十大排序算法

1.排序算法概述 非线性时间比较类排序&#xff1a;通过比较来决定元素间的相对次序&#xff0c;由于其时间复杂度不能突破O(nlogn)&#xff0c;因此称为非线性时间比较类排序。 线性时间非比较类排序&#xff1a;不通过比较来决定元素间的相对次序&#xff0c;它可以突破基于比…

Java实现十大排序算法

Java实现十大排序算法 十大排序算法分别为&#xff1a;选择排序、冒泡排序、插入排序、快速排序、归并排序、堆排序、希尔排序、桶排序、计数排序、基数排序。 本篇只是为了方便我在代码中直接复制调用&#xff0c;因此原理和思想解释的并不清楚&#xff0c;想看原理的朋友可…

十大排序算法(C++版)

十大排序算法 前言一、插入排序二、希尔排序三、冒泡排序四、快速排序五、选择排序六、归并排序七、堆排序八、计数排序九、桶排序十、基数排序总结 前言 什么是排序&#xff1f; 排序&#xff1a;将一组杂乱无章的数据按一定规律顺次排列起来。即&#xff0c;将无序序列排成一…

十大排序算法详解

十大排序算法详解 参考程序员必知必会的十大排序算法详解 引言 对于排序的分类&#xff0c;可以将排序算法分为两大类&#xff1a;基于比较和非比较的算法。 基于比较的排序算法可以细分为&#xff1a; 基于交换类&#xff1a;冒泡排序、快速排序基于插入类&#xff1a;直接插入…

JS 实现十大排序算法

文章目录 前言零、十大排序一、冒泡排序&#xff08;bubbleSort&#xff09;二、选择排序&#xff08;selectionSort&#xff09;三、插入排序&#xff08;insertSort&#xff09;四、希尔排序&#xff08;shellSort&#xff09;五、归并排序&#xff08;mergeSort&#xff09;…