发布推送
This commit is contained in:
86
app/Http/Controllers/Sms/SmsController.php
Normal file
86
app/Http/Controllers/Sms/SmsController.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Sms;
|
||||
|
||||
use App\Const\VrCode;
|
||||
use App\Exceptions\AppException;
|
||||
use App\Http\Controllers\Base\CustomerBaseController;
|
||||
use App\Models\Customer\CustomerUserModel;
|
||||
use App\Service\AuthService;
|
||||
use App\Service\VrCodeService;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class SmsController extends CustomerBaseController
|
||||
{
|
||||
public array $validateMethodParams = [
|
||||
'sendRegCode' => [
|
||||
'phone_area' => 'alpha_dash:ascii|max:5',
|
||||
'phone' => 'numeric|max:15',
|
||||
],
|
||||
'sendVrcodeCode' => [
|
||||
'topic' => 'required|numeric',
|
||||
'phone_area' => 'alpha_dash:ascii|max:5',
|
||||
'phone' => 'numeric|max:15',
|
||||
],
|
||||
];
|
||||
|
||||
// no need login
|
||||
function sendRegCode(): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
//发送短信验证码
|
||||
$request = request();
|
||||
$aReqData = $request->only([
|
||||
'phone_area',
|
||||
'phone',
|
||||
]);
|
||||
|
||||
$oVrCodeService = new VrCodeService();
|
||||
$oVrCodeService->setIType(VrCode::TOPIC_REGISTER);
|
||||
|
||||
$validator = Validator::make($aReqData, [
|
||||
'phone_area' => 'required|alpha_dash:ascii|max:5',
|
||||
'phone' => 'required|numeric|max:15',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
$oCustomerUser = new CustomerUserModel();
|
||||
$oUser = $oCustomerUser->findItemByPhone($aReqData['phone_area'],$aReqData['phone'],['id']);
|
||||
if ($oUser) {
|
||||
return $this->error('vrcode error');
|
||||
}
|
||||
$oVrCodeService->setSPhoneArea($aReqData['phone_area']);
|
||||
$oVrCodeService->setSPhone($aReqData['phone']);
|
||||
$oVrCodeService->sendCode();
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
//must login
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws AppException
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
function sendVrcodeCode(): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
//发送短信验证码
|
||||
$request = request();
|
||||
$aReqData = $request->only([
|
||||
'topic',
|
||||
'phone_area',
|
||||
'phone',
|
||||
]);
|
||||
if(!in_array($aReqData['topic'],VrCode::TOPIC)) return $this->error('invalid vrcode type');
|
||||
$oVrCodeService = new VrCodeService();
|
||||
$oVrCodeService->setIType($aReqData['topic']);
|
||||
|
||||
$oAuthService = new AuthService();
|
||||
$aUser = $oAuthService->getCurrentUser();
|
||||
if($aUser == null) return $this->error('user not login');
|
||||
$oVrCodeService->setIUid($aUser['id']);
|
||||
$oVrCodeService->sendCode();
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user