data_center/app/api/controller/IndexController.php

56 lines
1.6 KiB
PHP
Raw Normal View History

2023-09-18 09:11:13 +08:00
<?php
namespace app\api\controller;
use app\common\enum\notice\NoticeEnum;
2023-11-22 09:54:27 +08:00
use app\common\model\systems\System;
2023-09-18 17:04:42 +08:00
use think\facade\Log;
2023-09-18 09:11:13 +08:00
use think\response\Json;
/**
* index
* Class IndexController
* @package app\api\controller
*/
class IndexController extends BaseApiController
{
2023-11-22 09:54:27 +08:00
public array $notNeedLogin = ['code', 'miniapp'];
2023-09-18 09:11:13 +08:00
// 获取短信验证码
public function code(): Json
{
//验证请求方式
if(!$this->request->isPost()){
return $this->fail('请求方式错误');
}
//获取参数
$params = $this->request->post(['phone','scene']);
if(empty($params['phone']) || empty($params['scene'])){
return $this->fail('缺少必要参数');
}
2023-10-10 16:08:19 +08:00
if(!in_array($params['scene'],[NoticeEnum::LOGIN_CAPTCHA,NoticeEnum::BIND_MOBILE_CAPTCHA,NoticeEnum::CHANGE_MOBILE_CAPTCHA,NoticeEnum::FIND_LOGIN_PASSWORD_CAPTCHA,NoticeEnum::REGISTER_CAPTCHA])){
2023-09-18 09:11:13 +08:00
return $this->fail('短信场景错误');
}
//发送短信
try {
$result = event('Notice', [
'scene_id' => $params['scene'],
'params' => [
'mobile' => $params['phone'],
'code' => mt_rand(1000, 9999),
]
]);
return $this->success($result[0]);
}catch(\Exception $e){
2023-09-18 17:04:42 +08:00
//记录日志
Log::error($e->getMessage());
2023-09-18 09:11:13 +08:00
return $this->fail($e->getMessage());
}
}
2023-11-22 09:54:27 +08:00
public function miniapp(): Json
{
2023-11-22 10:03:46 +08:00
return $this->success('获取成功', System::where('status', 0)->order('sort asc')->select()->toArray());
2023-11-22 09:54:27 +08:00
}
2023-09-18 09:11:13 +08:00
}