125 lines
3.7 KiB
PHP
125 lines
3.7 KiB
PHP
<?php
|
||
|
||
/**
|
||
* @author Any
|
||
* @description KISS
|
||
* @date 2020-11-5
|
||
* @version 1.0.0
|
||
*
|
||
* _____LOG_____
|
||
*
|
||
*/
|
||
namespace app\modules\admin\models\sms;
|
||
|
||
|
||
use app\models\sms\SmsSetting;
|
||
use app\models\sms\SmsTpl;
|
||
use app\models\Model;
|
||
use app\modules\admin\models\AdminModel;
|
||
|
||
|
||
class SmsConfigEditForm extends AdminModel
|
||
{
|
||
public $cx_mch_id;
|
||
|
||
public $type;
|
||
public $access_key_id;
|
||
public $access_secret;
|
||
public $secret_id;
|
||
public $secret_key;
|
||
public $sdk_app_id;
|
||
public $sign_name;
|
||
public $expire_time;
|
||
public $time_delay;
|
||
public $day_limit;
|
||
public $is_prod;
|
||
public $code_len;
|
||
public $super_code;
|
||
|
||
public $tpl;
|
||
|
||
public $model;
|
||
|
||
public function rules()
|
||
{
|
||
return [
|
||
[['access_key_id', 'access_secret', 'secret_id', 'secret_key', 'sdk_app_id', 'sign_name', 'super_code'], 'trim'],
|
||
[['access_key_id', 'access_secret', 'secret_id', 'secret_key', 'sdk_app_id', 'sign_name', 'super_code'], 'string'],
|
||
[['cx_mch_id', 'expire_time', 'time_delay', 'day_limit', 'is_prod', 'code_len'], 'integer'],
|
||
[['model', 'tpl'], 'safe'],
|
||
[['model', 'type', 'sign_name', 'expire_time', 'time_delay', 'day_limit', 'is_prod', 'code_len', 'super_code'], 'required'],
|
||
[['access_key_id', 'access_secret',], 'required', 'on' => 'aliyun'],
|
||
[['secret_id', 'secret_key', 'sdk_app_id'], 'required', 'on' => 'txy']
|
||
];
|
||
}
|
||
|
||
public function attributeLabels()
|
||
{
|
||
return [
|
||
'cx_mch_id' => '平台商户ID',
|
||
'type' => '类型,0=阿里云,1=腾讯云',
|
||
'access_key_id' => '阿里云AccessKeyId',
|
||
'access_secret' => '阿里云AccessSecret',
|
||
'secret_id' => '腾讯短信SecretId',
|
||
'secret_key' => '腾讯短信SecretKey',
|
||
'sdk_app_id' => '腾讯短信应用ID',
|
||
'sign_name' => '签名',
|
||
'expire_time' => '有效时长',
|
||
'time_delay' => '获取时间间隔',
|
||
'day_limit' => '每日获取验证码次数',
|
||
'is_prod' => '环境,0=非正式,1=正式环境',
|
||
'code_len' => '验证码长度',
|
||
'super_code' => '超级验证码,默认6666',
|
||
];
|
||
}
|
||
|
||
public function save()
|
||
{
|
||
if(!$this->validate()){
|
||
return $this->getModelError();
|
||
}
|
||
if($this->model->isNewRecord){
|
||
$this->model->cx_mch_id = $this->cx_mch_id;
|
||
}
|
||
$this->model->attributes = $this->attributes;
|
||
if(!$this->model->save()){
|
||
return $this->getModelError($this->model);
|
||
}
|
||
//消息模板
|
||
$res = $this->save_sms_tpl();
|
||
if($res['code'] !=0){
|
||
return $res;
|
||
}
|
||
return [
|
||
'code' => 0,
|
||
'msg' => '保存成功'
|
||
];
|
||
}
|
||
|
||
private function save_sms_tpl()
|
||
{
|
||
foreach ($this->tpl as $key => $val){
|
||
$val = trim($val);
|
||
$model = SmsTpl::findOne([
|
||
'type' => $this->type,
|
||
'cx_mch_id' => $this->cx_mch_id,
|
||
'key' => $key,
|
||
]);
|
||
if($model == null){
|
||
$model = new SmsTpl();
|
||
$model->cx_mch_id = $this->cx_mch_id;
|
||
$model->type = $this->type;
|
||
$model->key = $key;
|
||
}
|
||
$model->tpl_code = $val;
|
||
$model->is_delete = 0;
|
||
if(!$model->save()){
|
||
return $this->getModelError($model);
|
||
}
|
||
}
|
||
return [
|
||
'code' => 0,
|
||
'msg' => 'ok'
|
||
];
|
||
}
|
||
} |