12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Admin\Http\Logics;
- use App\DataApi\Helper\TencentSmsHelper;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\Redis;
- use function App\Http\_header;
- use function App\Http\error;
- use function App\Http\success;
- class SmsLogic
- {
- /**
- * 发送验证码
- *
- * @param [type] $phone
- * @return array
- */
- public static function sendSms($phone)
- {
- if (Redis::exists('CODE_' . $phone)) return error("该手机号已发送短信,请稍后再试");
- $tencentMessage = new TencentSmsHelper();
- $code = (string)rand(1111, 9999);
- $res = $tencentMessage->send('86' . $phone, '1734411', [$code, '5']);
- if (!empty($res['code']) and $res['code'] == 1) {
- Redis::setex('CODE_' . $phone, 60 * 5, $code);
- return success([], "发送成功,验证码5分钟内有效");
- } else {
- return error($res['msg']);
- }
- }
- /**
- * 验证验证码
- *
- * @param [type] $phone
- * @return bool
- */
- public static function validSms($phone, $code)
- {
- return ($code == Redis::get('CODE_' . $phone));
- }
- }
|