50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Endpoint\Api\Http\Controllers;
|
|
|
|
use App\Endpoint\Api\Http\Requests\StoreSmsCodeRequest;
|
|
use App\Exceptions\BizException;
|
|
use App\Services\CaptchaService;
|
|
use App\Services\SmsCodeService;
|
|
use Throwable;
|
|
|
|
class SmsCodeController extends Controller
|
|
{
|
|
/**
|
|
* 发送短信验证码
|
|
*
|
|
* @param \App\Endpoint\Api\Http\Requests\StoreSmsCodeRequest $request
|
|
* @param \App\Services\CaptchaService $captchaService
|
|
* @param \App\Services\SmsCodeService $smsCodeService
|
|
* @return \Illuminate\Http\Response
|
|
*
|
|
* @throws \App\Exceptions\BizException
|
|
*/
|
|
public function store(
|
|
StoreSmsCodeRequest $request,
|
|
CaptchaService $captchaService,
|
|
SmsCodeService $smsCodeService,
|
|
) {
|
|
if (! app()->isLocal()) {
|
|
$captchaService->validatePhrase(
|
|
(string) $request->input('captcha_key'),
|
|
(string) $request->input('captcha_phrase')
|
|
);
|
|
}
|
|
|
|
try {
|
|
$smsCodeService->send(
|
|
$request->input('phone'),
|
|
$request->input('type'),
|
|
app()->isProduction() ? mt_rand(100000, 999999) : '666666',
|
|
);
|
|
} catch (BizException $e) {
|
|
throw $e;
|
|
} catch (Throwable $e) {
|
|
report($e);
|
|
}
|
|
|
|
return response()->noContent();
|
|
}
|
|
}
|