public function sendSMSCheckNO() { $phone = $this->post('phone'); $code = randCode(); $redis_key = $_SESSION['uid'] . ':sms'; $code_key = $_SESSION['uid'] . ':sms_code'; if (strlen($code) != 4) { echo '短信发送异常'; exit; } if (mobileCheck($phone)) { echo '手机号码不对'; exit; } //限制发送时间 if ($this->cacheKV()->exists($redis_key)) { echo '请稍后再发送'; exit; } $this->cacheKV()->setex($redis_key, $this->kvExTime(), 1); //发送成功标识,用来重发 Doo::loadClassAt('SmsApi', 'default'); $clapi = new SmsApi(); $result = $clapi->sendSMS($phone, '您好,您的验证码是 ' . $code . ' <微微乐>', 'true'); $result = $clapi->execResult($result); if ($result[1] == 0) { echo '发送成功'; $this->cacheKV()->setex($code_key, $this->kvExTime() * 10, $code); //10分钟内有效 } else { echo "发送失败{$result[1]}"; } exit; }