cxfoot/modules/api/controllers/VerifyCodeController.php
2023-10-27 14:25:12 +08:00

107 lines
3.3 KiB
PHP

<?php
/**
* @author Any
* @description KISS
* @date 2020-12-2
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\modules\api\controllers;
use app\modules\api\behaviors\LoginBehavior;
use app\models\sms\SmsMsgHelper;
use app\models\sms\SmsCountry;
use app\models\sms\SmsTpl;
use app\modules\api\models\SmsForm;
class VerifyCodeController extends Controller
{
public function behaviors() {
return array_merge(parent::behaviors(),[
'login' => [
'class' => LoginBehavior::className(),
'ignore' =>[
'api/verify-code/country-code',
'api/verify-code/sms-type',
'api/verify-code/sms',
]
]
]);
}
/**
* showdoc
* @catalog 验证码
* @title 手机号国家代码
* @description 本接口提供手机号国家代码
* @method get
* @url /api/verify-code/country-code
* @return {"code":0,"msg":"ok","data":[{"id":"1","iso":"AF","iso3":"AFG","name":"AFGHANISTAN","name_cn":"阿富汗","nicename":"Afghanistan","num_code":"4","country_code":"93"}]}
* @return_param country_code 手机号国家代码
* @remark
*/
public function actionCountryCode()
{
$list = SmsCountry::find()
->select('id,iso,iso3,name,name_cn,nicename,num_code,country_code')
->asArray()->all();
$data = [
'code' => 0,
'msg' => 'ok',
'data' => $list
];
return $this->responseHandler($data);
}
/**
* showdoc
* @catalog 验证码
* @title 短信类型
* @description 本接口提供短信类型
* @method get
* @url /api/verify-code/sms-type
* @return {"code":0,"msg":"ok","data":[{"type":0,"label":"身份验证验证码"},{"type":1,"label":"登录确认验证码"},{"type":2,"label":"登录异常验证码"},{"type":3,"label":"用户注册验证码"},{"type":4,"label":"修改密码验证码"},{"type":5,"label":"信息变更验证码"}]}
* @remark
*/
public function actionSmsType()
{
$list = SmsTpl::typeLabels();
$data = [
'code' => 0,
'msg' => 'ok',
'data' => $list
];
return $this->responseHandler($data);
}
/**
* showdoc
* @catalog 验证码
* @title 短信验证码
* @description 本接口提供发送短信验证码
* @method post
* @url /api/verify-code/sms
* @param mobile 必选 string 手机号
* @param type 必选 int 类型,详见短信类型接口
* @param mobile_prefix 必选 string 手机号国家代码
* @return {"code":0,"msg":"ok","data":{}}
* @remark
*/
public function actionSms()
{
if(!\Yii::$app->request->isPost){
$data = $this->invaildRequest();
return $this->responseHandler($data);
}
$form = new SmsForm();
$form->attributes = \Yii::$app->request->post();
$form->cx_mch_id = $this->cx_mch_id;
$form->user_id = \Yii::$app->user->isGuest ? 0 : \Yii::$app->user->identity->id;
$data = $form->sender();
return $this->responseHandler($data);
}
}