trafik8787/sms-verification-laravel

提供向某些电话号码发送短信并验证的功能。

0.9.4 2017-09-19 17:39 UTC

This package is auto-updated.

Last update: 2024-09-29 05:08:34 UTC


README

alt text

此库包含一组用于通过短信进行电话号码验证的简单服务器端点。

短信通过phone.com API发送,实际上这段代码旨在演示使用phone.com API的实际应用案例。所有可用的Phone.com API定义在https://apidocs.phone.com

服务器使用Laravel框架用PHP编写。

##安装

安装此库后,您需要注册服务提供者。打开config/app.php并找到providers键。

'providers' => [
    ...
    \Phonedotcom\SmsVerification\SmsVerificationProvider::class,
    ...
]

运行以下命令

php artisan vendor:publish --provider="Phonedotcom\SmsVerification\SmsVerificationProvider" --tag=config

将短信验证端点添加到您的路由文件

\Phonedotcom\SmsVerification\SmsVerificationProvider::registerRoutes($router);

短信验证的过程如下

  1. 使用POST /sms-verification向移动设备发送验证码
  2. 使用GET /sms-verification/{code}/{mobilePhoneNumber}验证验证码

例如,如果一个应用程序想要向手机号码855-123-8765发送授权码

  1. 向URL https://api.example.com/sms-verification 发送POST /sms-verification API,JSON正文为{"phone_number" : "+18551238765"}
  2. 如果发送成功,API返回{"success":true,"description":"OK","expires_at": 1495120612}。其中expires_at是代码到期的实际时间。
  3. 手机将收到一个6位数的验证码(例如:782025)
  4. 要验证代码,向https://api.example.com/sms-verification/782025/+18551238765发送GET /sms-verification API
  5. API返回
    • 成功:{"success":true,"description":"OK","expires_at": 1495120612}
    • 失败:{"success":false,"description":"Wrong code"}

错误

如果在短信验证过程中抛出异常,输出将包含error字段。

  • 1XX - 代码验证错误
  • 2XX - 配置不正确
  • 3XX - 输入格式验证失败
  • 5XX - 代码生成错误
  • 4XX - 代码发送错误
  • 999 - 任何其他与短信验证库无关的服务器错误

注意

  1. 发送的授权码仅在10分钟内有效
  2. 代码只能验证一次。第一次成功后,它将被无效化