'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' ]; } }