小程序-laravel5.5发短信验证码找回密码功能

该博客介绍了如何在laravel5.5后台实现微信小程序的找回密码功能,通过发送短信验证码。前端涉及.wxml和.js文件,以及md5.js和api.js的使用。后端主要讲解sendMobileVerifyCode方法,利用阿里云短信服务扩展进行发送,详细步骤包括composer安装和配置参数。
摘要由CSDN通过智能技术生成

前端样式

在这里插入图片描述
.wxml文件

<view class="body">
<form bindsubmit="formSubmit">
  <view class="password">
    <view class="one">手机号码</view>
    <view class="two">{
   {
   mobile}}</view>
    <view class="send" bindtap="sendMsg" wx:if="{
   {send}}">发送</view>
    <view class="count_down" wx:else>{
   {
   second+'s'}}</view>
  </view>
  <view class="password">
    <view class="one">短信验证</view>
    <input type="number" name='code' class="two" placeholder="短信验证码" maxlength="6" value=""  />
  </view>
  <view class="password">
    <view class="one">新密码</view>
    <input type="number" name="newPassword"  class="two" password="{
   {true}}" placeholder="必须是6位数字" maxlength="6" value="{
   {password.newPassword}}" />
  </view>
  <view class="password">
    <view class="one">确认密码</view>
    <input type="number" name="cfmPassword" class="two" password="{
   {true}}" placeholder="必须是6位数字" maxlength="6" value="{
   {password.cfmPassword}}" />
  </view>
  <button class="submit" disabled="{
   {!send}}" form-type="submit">确定</button>
</form>
</view>

.js文件

const urlList = require('../../../utils/api.js');
const hash = require('../../../utils/md5.js');
const app = getApp();
Page({
   

  /**
   * 页面的初始数据
   */
  data: {
   
    mobile:'',
    send:true,//是否发送,还是显示倒计时。true:发送
    second:60,
    url:'',
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
   
    var that = this;
    if (e.path){
   
      that.setData({
   
        url: e.path
      })
    }
    that.setData({
   
      mobile: app.globalData.userInfoData.mobile
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   
    
  },
  //发送验证码
  sendMsg:function(){
   
    var that = this;
    wx.request({
   
      url: urlList.sendCode,
      method: "GET",
      header: {
   
        sign: app.globalData.authKey,
      },
      success: function (res) {
   
        if (res.data.code == 1) {
   
          wx.showToast({
   
            title: res.data.msg,
            icon: 'success',
            duration: 2000
          });
        }else{
   
          wx.showToast({
   
            title: res.data.msg,
            image: '/images/error.png',
            duration: 1000
          });

          wx.navigateBack({
   
            url: '/' + that.data.url,
          })

          return false;
        }
      }
    });
    that.setData({
   
      send: false,
    })
    that.timer();
  },
  formSubmit:function(e){
   
    var that = this;
    var code = e.detail.value.code;
    var newPassword = e.detail.value.newPassword;
    var cfmPassword = e.detail.value.cfmPassword;
    var patten = /^[0-9]{6}$/;
    
    if (newPassword != cfmPassword) {
   
      wx.showToast({
   
        title: '密码不一致!',
        image: '/images/error.png',
        duration: 1000
      });
      return false;
    }
    var patten = /^[0-9]{6}$/;
    if (!patten.test(newPassword)) {
   
      wx.showToast({
   
        title: '必须6位数字',
        image: '/images/error.png',
        duration: 1000
      });
      return;
    }
    if (!patten.test(code)) {
   
      wx.showToast({
   
        title: '验证码错误',
        image: '/images/error.png',
        duration: 1000
      });
      return;
    }
    var param = {
   
      code:code,
      payPassword: hash.hexMD5(newPassword),
    }
    wx.request({
   
      url: urlList.findPwd,
      data: param,
      method: "POST",
      header: {
   
        sign: app.globalData.authKey,
      },
      success: function (res) {
   
        if (res.data.code == 1) {
   
          wx.showToast({
   
            title: res.data.msg,
            icon: 'success',
            duration: 2000
          });
          setTimeout(function () {
   
            wx.navigateBack({
   
              url: '/' + that.data.url,
            })
          }, 1000);
        } else {
   
          wx.showToast({
   
            title: res.data.msg,
            image: '/images/error.png',
            duration: 1000
          });
          return false;
        }
      }
    });
    

  },
  //倒计时
  timer: function () {
   
    let promise = new Promise((resolve, reject) => {
   
      let setTimer = setInterval(
        () => {
   
          this.setData({
   
            second: this.data.second - 1
          })
          if (this.data.second <= 0) {
   
            this.setData({
   
              second: 60,
              send: true
            })
            resolve(setTimer)
          }
        }
        , 1000)
    })
    promise.then((setTimer) => {
   
      clearInterval(setTimer)
    })
  },
})

涉及到的md5.js文件(我已经压缩过了,直接复制粘贴就行)

function hex_md5(a
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值