Files
spacestation/agent/admin/controllers/auto/Sms.php
T
2025-11-20 14:57:48 +08:00

64 lines
2.0 KiB
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
require_once APPPATH . 'controllers/auto/BaseController.php';
class Sms extends BaseController
{
public function __construct()
{
parent::__construct();
}
/**
* 获取短信验证码
* @return void
* @throws Exception
*/
public function index_post()
{
$mobile = $this->post('mobile');
$type = $this->input_param('type');//验证码类型
if (!mobile_valid($mobile)) {
$this->return_json('请输入正确手机号');
}
!$type && $type = self::CODE_BM;
$cacheKey = '';
switch ($type) {
case self::CODE_BM:
$cacheKey = $this->getCodeCacheKey(self::CODE_BM, $mobile);
break;
case self::CODE_BANK:
$cacheKey = $this->getCodeCacheKey(self::CODE_BANK, $mobile);
break;
case self::CODE_LOGIN:
$cacheKey = $this->getCodeCacheKey(self::CODE_LOGIN, $mobile);
break;
default:
$this->return_json('验证码类型错误');
}
$redis = &load_cache();
$code = $this->get($cacheKey);
if (!$redis->get($cacheKey)) {
$this->load->helper('string');
$code = random_string('numeric', 4);
// $content = "【" . HDY_SMS_SIGN . "】" . "您的验证码为:{$code},请勿泄露于他人!";
// b2m_send_sms($mobile, $content);
//签名还未审核通过
$content = "您的验证码为:{$code},请勿泄露于他人!";
ems_sms($mobile, $content);
$redis->save($cacheKey, $code, 600);
}
$this->return_response([], '发送成功' . $code);
}
/**
* @return void
* @throws Exception
*/
public function login_post()
{
$this->index_post();
}
}