Sms.php
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\controller\admin\system;
use think\facade\Db;
use Ramsey\Uuid\Uuid;
use think\facade\Session;
use app\base\model\admin\system\SmsModel;
use app\base\controller\BaseAdmin;
/**
* 短信
**/
class Sms extends BaseAdmin
{
/**
* 短信配置
* @return \think\Response
*/
public function index()
{
$res = SmsModel::SmsInfo();
return success('短信配置',$res);
}
/**
* 短信配置保存
* @return \think\Response
*/
public function save()
{
$data = [];
$data = $this->req->post();
$res = SmsModel::smsUpdate($data);
if($res != 'ok') return error($res);
return success('更新成功');
}
/**
* 短信验证码模板配置
* @return \think\Response
*/
public function codeTemplateSave()
{
$data = [];
$data = $this->req->post();
$data['bh'] = '001';
$res = SmsModel::templateSave($data);
if($res != 'ok') return error($res);
return success('更新成功');
}
/**
* 获取短信验证码模板配置
* @return \think\Response
*/
public function getCodeTemplate()
{
$where = [];
$where['bh'] = '001';
$where['uid'] = Session::get('uid');
$res = SmsModel::getTemplate($where);
return success('短信模板配置',$res);
}
/**
* 发送短信验证码
* @return \think\Response
*/
public function sendCode()
{
$phone = $this->req->post('phone');
if(!preg_match("/^1[3456789]\d{9}$/", $phone)) return error('手机号格式不正确');
$data = [
'phone' => $phone,
'bh' => '001', //验证码模板
'param' => ['code'=>SmsModel::getCode()]
];
$res = SmsModel::sendSms($data);
if($res != 'ok') return error('发送失败');
return success('发送成功');
}
}