优化ctms-api语法、修复已知BUG;
主要修复ctms-api、dacms对PHP新版本的支持问题
This commit is contained in:
@@ -4,10 +4,10 @@
|
||||
# @Date: 2022-05-22T07:38:52+08:00
|
||||
# @Email: fm453@lukegzs.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2022-05-22T07:38:52+08:00
|
||||
# @Last modified time: 2024-08-09T08:53:58+08:00
|
||||
# @Copyright: www.hiluker.cn
|
||||
|
||||
namespace backend\controllers\client\v1;
|
||||
|
||||
namespace api\controllers\client\v1;
|
||||
|
||||
use Yii;
|
||||
use vendor\aliyun\dysms\Sms;
|
||||
@@ -20,7 +20,7 @@ class SmsController extends Common
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
@@ -32,7 +32,7 @@ class SmsController extends Common
|
||||
];
|
||||
$this->result('您正使用CMTS-CLIENT系统短信管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
|
||||
public function actionSend()
|
||||
{
|
||||
global $START_TIME;
|
||||
@@ -144,19 +144,19 @@ class SmsController extends Common
|
||||
//数据取出方法
|
||||
$dataPost = $this->postdata; //YII应用内的真实或模拟POST数据
|
||||
$phone = $dataPost['phone'] ?? 0;
|
||||
//验证手机号
|
||||
$isPhone = false;
|
||||
if($phone){
|
||||
$isPhone = preg_match('/^1\d{10}$/', $phone) ? true : false;
|
||||
}
|
||||
if(!$isPhone){
|
||||
$this->result('手机号不正确,请确认');
|
||||
}
|
||||
// 手机号掩码
|
||||
$phoneMask = substr($phone, 0, 3) . str_repeat('*', strlen($phone) - 7) . substr($phone, -4);
|
||||
|
||||
//验证手机号
|
||||
$isPhone = FALSE;
|
||||
if ($phone) {
|
||||
$isPhone = preg_match('/^1\d{10}$/', $phone) ? TRUE : FALSE;
|
||||
}
|
||||
if (!$isPhone) {
|
||||
$this->result('手机号不正确,请确认');
|
||||
}
|
||||
// 手机号掩码
|
||||
$phoneMask = substr($phone, 0, 3) . str_repeat('*', strlen($phone) - 7) . substr($phone, -4);
|
||||
|
||||
$params = Yii::$app->params;
|
||||
$codetype = $dataPost['scence'] ?? 'vcode'; //验证码使用场景
|
||||
$codetype = $dataPost['scence'] ?? 'vcode'; //验证码使用场景
|
||||
|
||||
$config = array();
|
||||
$config['accessKeyId'] = isset($dataPost['accessKeyId']) ? $dataPost['accessKeyId'] : $params['aliDySms']['accessKeyId'];
|
||||
@@ -165,35 +165,35 @@ class SmsController extends Common
|
||||
|
||||
$option = array();
|
||||
$sms = new Sms($option, $config);
|
||||
$_time = time();
|
||||
$vcodeModel = new CVcode();
|
||||
$_time = time();
|
||||
$vcodeModel = new CVcode();
|
||||
//查询上次发送记录
|
||||
$where=[];
|
||||
$where['mobile'] = $phone;
|
||||
$where['deleted'] = 0;
|
||||
$where['type'] = $codetype;
|
||||
$res = $vcodeModel->find()->where($where)->one();
|
||||
if ($res) {
|
||||
if ($res) {
|
||||
if (($_time-$res->create_at)<300) {
|
||||
//设置5分钟内,验证码仍然可用
|
||||
//设置5分钟内,验证码仍然可用
|
||||
$code = $res->code;
|
||||
$msg = '上次发送的验证码仍然可用;请注意查看手机 '.$phoneMask;
|
||||
$data = ['errorcode'=>2];
|
||||
if(YII_DEBUG){
|
||||
$data['code'] = $code;
|
||||
}
|
||||
$msg = '上次发送的验证码仍然可用;请注意查看手机 ' . $phoneMask;
|
||||
$data = ['errorcode' => 2];
|
||||
if (YII_DEBUG) {
|
||||
$data['code'] = $code;
|
||||
}
|
||||
$this->result($msg, $data, 200);
|
||||
} else {
|
||||
$res->deleted = 1;
|
||||
$res->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$content=[];
|
||||
$code = mt_rand(1000, 9999);
|
||||
$code = mt_rand(1000, 9999);
|
||||
$content['code'] = $code;
|
||||
|
||||
//验证码准备入库
|
||||
|
||||
//验证码准备入库
|
||||
$vcode = [];
|
||||
$vcode['code'] = $code;
|
||||
$vcode['type'] = $codetype;
|
||||
@@ -202,46 +202,46 @@ class SmsController extends Common
|
||||
foreach ($vcode as $key=>$val) {
|
||||
$vcodeModel->$key = $val;
|
||||
}
|
||||
$tmpls = $params['aliDySms']['tmpl'];
|
||||
$tmpls = $params['aliDySms']['tmpl'];
|
||||
switch ($codetype) {
|
||||
case 'reg':
|
||||
$tmpl = $tmpls['regVerify'];
|
||||
break;
|
||||
case 'login':
|
||||
$tmpl = $tmpls['loginVcode'];
|
||||
break;
|
||||
case 'info':
|
||||
$tmpl = $tmpls['infoChange'];
|
||||
break;
|
||||
case 'passwd':
|
||||
$tmpl = $tmpls['passwdChange'];
|
||||
break;
|
||||
case 'reg':
|
||||
$tmpl = $tmpls['regVerify'];
|
||||
break;
|
||||
case 'login':
|
||||
$tmpl = $tmpls['loginVcode'];
|
||||
break;
|
||||
case 'info':
|
||||
$tmpl = $tmpls['infoChange'];
|
||||
break;
|
||||
case 'passwd':
|
||||
$tmpl = $tmpls['passwdChange'];
|
||||
break;
|
||||
case 'vcode':
|
||||
default:
|
||||
default:
|
||||
$tmpl = $tmpls['vcode'];
|
||||
break;
|
||||
}
|
||||
|
||||
// 发送前控制
|
||||
$host = yii::$app->request->hostName;
|
||||
$debug = $params['aliDySms']['debug'] ?? false;
|
||||
$domains = $params['aliDySms']['domains'] ?? [];
|
||||
$sendable = false;
|
||||
if(in_array($host,$domains) || $debug){
|
||||
$sendable = true;
|
||||
}
|
||||
$result = true;
|
||||
if($sendable){
|
||||
$result = $sms->send($phone, $tmpl, $content);
|
||||
}
|
||||
|
||||
|
||||
// 发送前控制
|
||||
$host = yii::$app->request->hostName;
|
||||
$debug = $params['aliDySms']['debug'] ?? FALSE;
|
||||
$domains = $params['aliDySms']['domains'] ?? [];
|
||||
$sendable = FALSE;
|
||||
if (in_array($host, $domains) || $debug) {
|
||||
$sendable = TRUE;
|
||||
}
|
||||
$result = TRUE;
|
||||
if ($sendable) {
|
||||
$result = $sms->send($phone, $tmpl, $content);
|
||||
}
|
||||
|
||||
//保存发送记录
|
||||
$smsModel = new CSms();
|
||||
$smsdata = [];
|
||||
$sid = $params['siteId'];
|
||||
$smsdata['sid'] = (int)$sid;
|
||||
$smsdata['pid'] = $pid;
|
||||
$smsdata['uid'] = 0;
|
||||
$smsdata['uid'] = 0;
|
||||
$smsdata['mid'] = $this->user_id;
|
||||
$smsdata['mobile'] = $phone;
|
||||
$smsdata['content'] = json_encode($content, JSON_UNESCAPED_UNICODE);
|
||||
@@ -263,10 +263,10 @@ class SmsController extends Common
|
||||
$vcodeModel->save();
|
||||
$msg .= "发送成功";
|
||||
}
|
||||
$data = ['errorcode'=>$errorcode];
|
||||
if(!$debug || YII_DEBUG){
|
||||
$data['data'] = $content;
|
||||
}
|
||||
$data = ['errorcode' => $errorcode];
|
||||
if (!$debug || YII_DEBUG) {
|
||||
$data['data'] = $content;
|
||||
}
|
||||
$this->result($msg, $data, 200);
|
||||
}
|
||||
|
||||
@@ -276,14 +276,14 @@ class SmsController extends Common
|
||||
$pid = $this->pid;
|
||||
$plat = AcPlat::findOne($pid);
|
||||
$platExt = json_decode($plat->remark, true);
|
||||
|
||||
|
||||
$phone = $platExt['cw_phone'];
|
||||
if (!$phone) {
|
||||
$this->result('还没有配置财务手机号,请联系站长管理员进行设置!', ['errorcode'=>1], 200);
|
||||
}
|
||||
|
||||
|
||||
$vcodeModel = new CVcode();
|
||||
$codetype = 'caiwu';
|
||||
$codetype = 'caiwu';
|
||||
//查询上次发送记录
|
||||
$_time = time();
|
||||
$where=[];
|
||||
@@ -293,7 +293,7 @@ class SmsController extends Common
|
||||
$res = $vcodeModel->find()->where($where)->one();
|
||||
if ($res) {
|
||||
if (($_time-$res->create_at)<7200) {
|
||||
//设置2小时内,验证码仍然可用
|
||||
//设置2小时内,验证码仍然可用
|
||||
$code = $res->code;
|
||||
$this->result('上次发送的验证码仍然可用;请注意查看财务手机!', ['errorcode'=>2], 200);
|
||||
} else {
|
||||
@@ -301,17 +301,17 @@ class SmsController extends Common
|
||||
$res->save();
|
||||
}
|
||||
}
|
||||
|
||||
//数据取出方法
|
||||
|
||||
//数据取出方法
|
||||
$dataPost = $this->postdata; //YII应用内的真实或模拟POST数据
|
||||
$params = Yii::$app->params;
|
||||
|
||||
$content = [];
|
||||
|
||||
$content = [];
|
||||
$code = mt_rand(1000, 9999);
|
||||
$content['code'] = $code;
|
||||
$tmpl = $params['aliDySms']['tmpl']['cwVcode'];
|
||||
|
||||
//验证码准备入库
|
||||
|
||||
//验证码准备入库
|
||||
$vcode = [];
|
||||
$vcode['code'] = $code;
|
||||
$vcode['type'] = $codetype;
|
||||
@@ -320,14 +320,14 @@ class SmsController extends Common
|
||||
foreach ($vcode as $key=>$val) {
|
||||
$vcodeModel->$key = $val;
|
||||
}
|
||||
|
||||
$config = array();
|
||||
|
||||
$config = array();
|
||||
$config['accessKeyId'] = isset($dataPost['accessKeyId']) ? $dataPost['accessKeyId'] : $params['aliDySms']['accessKeyId'];
|
||||
$config['accessKeySecret'] = isset($dataPost['accessKeySecret']) ? $dataPost['accessKeySecret'] : $params['aliDySms']['accessKeySecret'];
|
||||
$config['sign'] = isset($dataPost['sign']) ? $dataPost['sign'] : $params['aliDySms']['sign'];
|
||||
|
||||
$option = array();
|
||||
$sms = new Sms($option, $config);
|
||||
$sms = new Sms($option, $config);
|
||||
$result = $sms->send($phone, $tmpl, $content); //编排发送短信
|
||||
//保存发送记录
|
||||
$smsModel = new CSms();
|
||||
|
||||
Reference in New Issue
Block a user