|
@@ -1,5 +1,6 @@
|
|
<?php namespace Msg\Lib\Type;
|
|
<?php namespace Msg\Lib\Type;
|
|
use Dever;
|
|
use Dever;
|
|
|
|
+use Api\Lib\Account;
|
|
class Code
|
|
class Code
|
|
{
|
|
{
|
|
private $config;
|
|
private $config;
|
|
@@ -9,7 +10,7 @@ class Code
|
|
$data['template_id'] = $template['id'];
|
|
$data['template_id'] = $template['id'];
|
|
$data['day'] = date('Ymd', DEVER_TIME);
|
|
$data['day'] = date('Ymd', DEVER_TIME);
|
|
if (empty($param['code'])) {
|
|
if (empty($param['code'])) {
|
|
- $this->config = Dever::db('template_code', 'msg')->find(['template_id' => $template['id']]);
|
|
|
|
|
|
+ $this->config = Dever::db('msg/template_code')->find(['template_id' => $template['id']]);
|
|
if (!$this->config) {
|
|
if (!$this->config) {
|
|
Dever::error('验证码未配置');
|
|
Dever::error('验证码未配置');
|
|
}
|
|
}
|
|
@@ -20,19 +21,19 @@ class Code
|
|
}
|
|
}
|
|
$test = 1;
|
|
$test = 1;
|
|
foreach ($template['method'] as $k => $v) {
|
|
foreach ($template['method'] as $k => $v) {
|
|
- $config = Dever::db('account', 'msg')->find(['method' => $v]);
|
|
|
|
|
|
+ $config = Dever::db('msg/account')->find(['method' => $v]);
|
|
if ($config) {
|
|
if ($config) {
|
|
- $handle = Dever::load('method/' . $config['method'], 'msg');
|
|
|
|
|
|
+ $handle = Dever::load('\\Msg\\Lib\\Method\\' . $config['method']);
|
|
$data['account'] = $handle->init($template['id'], $config['id'], $account, $project);
|
|
$data['account'] = $handle->init($template['id'], $config['id'], $account, $project);
|
|
$this->valid($data);
|
|
$this->valid($data);
|
|
if ($config['test'] == 2) {
|
|
if ($config['test'] == 2) {
|
|
$test = 2;
|
|
$test = 2;
|
|
- $api = Dever::load('account', 'api')->get($config['api_account_id'], $project);
|
|
|
|
|
|
+ $api = Dever::load(Account::class)->get($config['api_account_id'], $project);
|
|
$data['record'] = $handle->send($api, $template['content'], $param);
|
|
$data['record'] = $handle->send($api, $template['content'], $param);
|
|
}
|
|
}
|
|
$data['code'] = $param['code'];
|
|
$data['code'] = $param['code'];
|
|
$data['status'] = 1;
|
|
$data['status'] = 1;
|
|
- Dever::db('code', 'msg')->insert($data);
|
|
|
|
|
|
+ Dever::db('msg/code')->insert($data);
|
|
# 这里以后加入计费机制
|
|
# 这里以后加入计费机制
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -46,10 +47,10 @@ class Code
|
|
# 检测并使用验证码
|
|
# 检测并使用验证码
|
|
public function check($template_id, $account, $code, $update = 1)
|
|
public function check($template_id, $account, $code, $update = 1)
|
|
{
|
|
{
|
|
- $info = Dever::db('code', 'msg')->find(['template_id' => $template_id, 'account' => $account], ['order' => 'cdate desc']);
|
|
|
|
|
|
+ $info = Dever::db('msg/code')->find(['template_id' => $template_id, 'account' => $account], ['order' => 'cdate desc']);
|
|
if ($info && $info['status'] == 1 && $code == $info['code']) {
|
|
if ($info && $info['status'] == 1 && $code == $info['code']) {
|
|
if ($update == 1) {
|
|
if ($update == 1) {
|
|
- Dever::db('code', 'msg')->update($info['id'], ['status' => 2]);
|
|
|
|
|
|
+ Dever::db('msg/code')->update($info['id'], ['status' => 2]);
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -65,11 +66,11 @@ class Code
|
|
|
|
|
|
protected function valid($where)
|
|
protected function valid($where)
|
|
{
|
|
{
|
|
- $info = Dever::db('code', 'msg')->find($where);
|
|
|
|
|
|
+ $info = Dever::db('msg/code')->find($where);
|
|
if ($info) {
|
|
if ($info) {
|
|
if (DEVER_TIME - $this->config['cdate'] < $this->config['interval']) {
|
|
if (DEVER_TIME - $this->config['cdate'] < $this->config['interval']) {
|
|
Dever::error('请不要在'.$this->config['interval'].'秒之内申请多次验证码,请您稍后再试');
|
|
Dever::error('请不要在'.$this->config['interval'].'秒之内申请多次验证码,请您稍后再试');
|
|
- } elseif (Dever::db('code', 'msg')->count($where) >= $this->config['total']) {
|
|
|
|
|
|
+ } elseif (Dever::db('msg/code')->count($where) >= $this->config['total']) {
|
|
Dever::error('很抱歉,您已经申请获取验证码超过' . $this->config['total'] . '次,今天您已经无法获取验证码了,请您明天再来');
|
|
Dever::error('很抱歉,您已经申请获取验证码超过' . $this->config['total'] . '次,今天您已经无法获取验证码了,请您明天再来');
|
|
}
|
|
}
|
|
}
|
|
}
|