Files
spacestation/agent/admin/controllers/auto/Sms.php
T
2025-09-09 15:21:14 +08:00

51 lines
1.7 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;
default:
$this->return_json('验证码类型错误');
}
$redis = &load_cache();
// $key = $this->getCodeCacheKey(self::CODE_BM, $mobile);
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([], '发送成功');
}
}