| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace backend\controllers;
- use backend\helpers\MailHelper;
- use common\helpers\Utils;
- use Yii;
- class SmsController extends BaseController
- {
- /**
- * 发送短信验证码
- * @return \yii\web\Response
- */
- public function actionSendCode()
- {
- $mobile = Yii::$app->getRequest()->get('mobile');
- if (Utils::checkPhoneNumber($mobile) == false) {
- return $this->outJson(0, [], '手机号码格式不正确');
- }
- $code = MailHelper::sendCodeSms($mobile);
- if ($code == null) {
- return $this->outJson(0, [], '短信发送失败,请稍后重试');
- }
- return $this->outJson(1, ['code' => $code], 'OK');
- }
- /**
- * 获取短信验证码
- * @return \yii\web\Response
- */
- public function actionGetCode()
- {
- $mobile = trim(Yii::$app->getRequest()->get('mobile'));
- if ($mobile == '') {
- return $this->outJson(0, [], '手机号码不能为空');
- }
- $result = MailHelper::getCodeSms($mobile);
- return $this->outJson(1, $result, 'OK');
- }
- }
|