<?php
/**
 * Created by PhpStorm
 * User: 林志杰
 * Email: 598287049@qq.com
 * Time: 2020/1/11 17:54
 */

declare(strict_types=1);

namespace app\api\controller;

use app\common\business\Sms AS SmsBus;
use app\api\validate\User;
use app\BaseController;
use think\exception\ValidateException;

class Sms extends BaseController
{
    public function code(): object
    {
        $phoneNumber = input('param.phone_number', '', 'trim');
        halt($phoneNumber);
        $data = [
            'phoneNumber' => $phoneNumber
        ];
        try {
            validate(User::class)->scene('send_code')->check($data);
        } catch (ValidateException $e) {
            return show(config('status.error'), $e->getError());
        }

        // 调用business层
        if (SmsBus::sendCode($phoneNumber, 6)) {
            return show(config('status.success'), '发送验证码成功');
        }
        return show(config('status.success'), '发送验证码失败');
    }
}