smsCode.js 319 B

123456789101112131415161718
  1. import notp from 'notp'
  2. const opt = {
  3. window: 0
  4. }
  5. export default {
  6. encode (key) { // 生成短信验证码
  7. return notp.totp.gen(key, opt)
  8. },
  9. decode (key, token) { // 解码短信验证码
  10. const login = notp.totp.verify(token, key, opt)
  11. if (!login) {
  12. return false
  13. }
  14. return true
  15. }
  16. }