feat: 公共表更名 common/member 前缀 + 插件命令自动加载 + 版本 1.1.1
- 18 张公共表更名(addon/attachment/configure/links/spider_log/spider_stat/sms/notice/ad/task/prop/medal/help/card -> common_*,member_wallets->member_wallet,score_rule/score_log -> member_*,addon_config->common_addonconf),模型全部对齐新表名,Db 直引用清零 - Attachment 模型补 表名绑定,修复富文本上传查 wxapp_attachment 1146 隐患 - install.sql + 迁移 SQL:backend_admin/backend_role delete_at 默认 0,修复软删除(NULL != 0)误过滤导致后台菜单为空 - AppService::boot() 支持插件 info.php 声明 commands 自动注册插件命令(psr-4 自动加载,坏类名自动跳过) - 各插件(haonav/mqttbroker/wxchat/articles/blog/forum 等)字段与配置同步调整 - 框架版本 1.1.0 -> 1.1.1
This commit is contained in:
@@ -8,42 +8,70 @@
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\Api\Controller\V1;
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use think\facade\Event;
|
||||
use think\exception\ValidateException;
|
||||
use ywxapp\controller\ApiController;
|
||||
use ywxapp\controller\ApiBase;
|
||||
use ywxapp\library\Sms as Smslib;
|
||||
use ywxapp\model\Sms as SmsModel;
|
||||
use ywxapp\model\CommonSms as SmsModel;
|
||||
use ywxapp\model\MemberUser as UserModel;
|
||||
use ywxapp\utils\Random;
|
||||
|
||||
/**
|
||||
* Sms 类
|
||||
* 短信验证码接口(公开,无需登录)
|
||||
*
|
||||
* @author ywxapp <admin@ywxapp.cn>
|
||||
* 路由前缀:/api/v1/sms/<action>
|
||||
* 业务事件(event)由调用方约定,如 register / resetpwd / changepwd / mobilelogin 等。
|
||||
*
|
||||
* @package app\api\controller\v1
|
||||
*/
|
||||
class Sms extends ApiController
|
||||
class Sms extends ApiBase
|
||||
{
|
||||
|
||||
/**
|
||||
* 免登录(公开)接口白名单。
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $noNeedLogin = ['*'];
|
||||
|
||||
|
||||
/**
|
||||
* 接口存活探测。
|
||||
*
|
||||
* @return \think\Response JSON 响应,演示用
|
||||
*
|
||||
* @route GET /api/v1/sms/index
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return json(['message' => 'SMS API']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
* 发送短信验证码(公开)。
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="mobile", type="string", required=true, description="手机号")
|
||||
* @ApiParams (name="event", type="string", required=true, description="事件名称")
|
||||
* @ApiParams (name="type", type="string", required=false, description="验证类型,auto为自动验证,system为系统验证码")
|
||||
* @ApiParams (name="source_id", type="string", required=false, description="来源ID")
|
||||
* 校验手机号与事件后,受发送频率(同号 60 秒、同 IP 每小时 5 条)限制;
|
||||
* 按 event 校验账号是否已注册 / 占用 / 未注册,最后触发 SmsSend 事件下发短信。
|
||||
*
|
||||
* @param string $mobile 手机号(必填)
|
||||
* @param string $event 事件名称(必填,小写字母,默认 register)
|
||||
* @param string $type 验证类型(可选,auto 自动 / system 系统验证码)
|
||||
* @param string $source_id 来源 ID(可选)
|
||||
*
|
||||
* @return \think\Response JSON 响应,成功提示
|
||||
*
|
||||
* @throws ValidateException 当参数校验失败时
|
||||
*
|
||||
* @route POST /api/v1/sms/send
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
{
|
||||
$cfg = config('smsbao');
|
||||
|
||||
dump($cfg);die;
|
||||
$mobile = $this->request->post("mobile");
|
||||
$event = $this->request->post("event", 'register');
|
||||
$event = $this->request->param("event", 'register');
|
||||
$type = $this->request->post("type", 'auto');
|
||||
$source_id = $this->request->post("source_id", '');
|
||||
try {
|
||||
@@ -62,46 +90,52 @@ class Sms extends ApiController
|
||||
]);
|
||||
$last = Smslib::get($mobile, $event);
|
||||
if ($last && time() - (int) $last['create_at'] < 60) {
|
||||
$this->result->error('发送频繁');
|
||||
$this->apiError('发送频繁');
|
||||
}
|
||||
$ipSendTotal = SmsModel::where(['ip' => $this->request->ip()])->whereTime('create_at', '-1 hours')->count();
|
||||
if ($ipSendTotal >= 5) {
|
||||
$this->result->error('发送频繁');
|
||||
$this->apiError('发送频繁');
|
||||
}
|
||||
if ($event) {
|
||||
$userinfo = UserModel::getByMobile($mobile);
|
||||
if ($event == 'register' && $userinfo) {
|
||||
//已被注册
|
||||
$this->result->error('已被注册');
|
||||
$this->apiError('已被注册');
|
||||
} elseif (in_array($event, ['changemobile']) && $userinfo) {
|
||||
//被占用
|
||||
$this->result->error('已被占用');
|
||||
$this->apiError('已被占用');
|
||||
} elseif (in_array($event, ['changepwd', 'resetpwd']) && ! $userinfo) {
|
||||
//未注册
|
||||
$this->result->error('未注册');
|
||||
$this->apiError('未注册');
|
||||
}
|
||||
}
|
||||
if (! Event::hasListener('SmsSend')) {
|
||||
$this->result->error('请在后台插件管理安装短信验证插件');
|
||||
$this->apiError('请在后台插件管理安装短信验证插件');
|
||||
}
|
||||
$ret = Smslib::send($mobile, null, $event);
|
||||
if ($ret) {
|
||||
$this->result->success('发送成功');
|
||||
$this->apiSuccess([], '发送成功');
|
||||
} else {
|
||||
$this->result->error('发送失败,请检查短信配置是否正确');
|
||||
$this->apiError('发送失败,请检查短信配置是否正确');
|
||||
}
|
||||
} catch (ValidateException $e) {
|
||||
$this->result->error($e->getError());
|
||||
$this->apiError($e->getError());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测验证码
|
||||
* 校验短信验证码(公开)。
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="mobile", type="string", required=true, description="手机号")
|
||||
* @ApiParams (name="event", type="string", required=true, description="事件名称")
|
||||
* @ApiParams (name="captcha", type="string", required=true, description="验证码")
|
||||
* 校验手机号、事件名称、验证码格式,并依 event 校验账号注册状态,
|
||||
* 最后调用 SmsLib::check 比对验证码(默认有效期 5 分钟)。
|
||||
*
|
||||
* @param string $mobile 手机号(必填)
|
||||
* @param string $event 事件名称(必填,默认 register)
|
||||
* @param string $captcha 验证码(必填)
|
||||
*
|
||||
* @return \think\Response JSON 响应,成功提示
|
||||
*
|
||||
* @route POST /api/v1/sms/check
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
@@ -109,33 +143,33 @@ class Sms extends ApiController
|
||||
$event = $this->request->post("event", 'register');
|
||||
$captcha = $this->request->post("captcha");
|
||||
if (! $mobile || ! \think\Validate::regex($mobile, "^1\d{10}$")) {
|
||||
$this->result->error('手机号不正确');
|
||||
$this->apiError('手机号不正确');
|
||||
}
|
||||
if (! preg_match("/^[a-z0-9_\-]{3,30}\$/i", $event)) {
|
||||
$this->result->error('事件名称错误');
|
||||
$this->apiError('事件名称错误');
|
||||
}
|
||||
if (! preg_match("/^[a-z0-9]{4,6}\$/i", $captcha)) {
|
||||
$this->result->error('验证码格式错误');
|
||||
$this->apiError('验证码格式错误');
|
||||
}
|
||||
|
||||
if ($event) {
|
||||
$userinfo = UserModel::getByMobile($mobile);
|
||||
if ($event == 'register' && $userinfo) {
|
||||
//已被注册
|
||||
$this->result->error('已被注册');
|
||||
$this->apiError('已被注册');
|
||||
} elseif (in_array($event, ['changemobile']) && $userinfo) {
|
||||
//被占用
|
||||
$this->result->error('已被占用');
|
||||
$this->apiError('已被占用');
|
||||
} elseif (in_array($event, ['changepwd', 'resetpwd']) && ! $userinfo) {
|
||||
//未注册
|
||||
$this->result->error('未注册');
|
||||
$this->apiError('未注册');
|
||||
}
|
||||
}
|
||||
$ret = Smslib::check($mobile, $captcha, $event);
|
||||
if ($ret) {
|
||||
$this->result->success('成功');
|
||||
$this->apiSuccess([], '成功');
|
||||
} else {
|
||||
$this->result->error('验证码不正确');
|
||||
$this->apiError('验证码不正确');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user