cxgj/modules/api/models/SmsForm.php
2023-11-27 09:45:13 +08:00

71 lines
1.8 KiB
PHP

<?php
/**
* @author Any
* @description KISS
* @date 2020-12-2
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\modules\api\models;
use app\models\sms\SmsCountry;
use app\models\sms\SmsMsgHelper;
use app\models\sms\SmsTpl;
use app\components\Validation;
class SmsForm extends ApiModel
{
public $mobile;
public $mobile_prefix;
public $type;
public $user_id;
public $cx_mch_id;
public function rules()
{
return [
[['mobile', 'mobile_prefix'], 'trim'],
[['mobile', 'mobile_prefix'], 'string'],
[['mobile_prefix'], 'default', 'value' => 86],
[['type', 'cx_mch_id', 'user_id'], 'integer'],
[['mobile', 'type', 'cx_mch_id', 'user_id'], 'required'],
];
}
public function attributeLabels() {
return [
'mobile' => '手机号',
'mobile_prefix' => '手机号国家代码',
'type' => '短信验证码类型'
];
}
public function sender()
{
if(!$this->validate()){
return $this->getModelError();
}
//手机号格式验证码
if(!Validation::is_mobile($this->mobile, $this->mobile_prefix)){
return [
'code' => 1,
'msg' => '手机号格式错误'
];
}
try{
$sms_sender = new SmsMsgHelper($this->cx_mch_id);
$tpl_type = SmsTpl::getTplKey($this->type);
$data = $sms_sender->sender($this->mobile, $tpl_type, $this->mobile_prefix, $this->user_id);
return $data;
} catch (\Exception $ex){
return $this->apiReturnError($ex->getMessage());
}
}
}