public function regSmsCode() { $phone = $this->getParam('phone', ''); if (!Check::isPhone($phone)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '请输入有效的手机号码!'); return; } $nk = Nosql::NK_REG_SMS_CODE . $phone; $ret = Nosql::get($nk); if (!empty($reg) && CURRENT_TIME - (int) $ret < 60) { $this->ajaxReturn(ERR_OPT_FREQ_LIMIT, '请不要频繁获取验证码'); return; } Nosql::setex($nk, Nosql::NK_REG_SMS_CODE_EXPIRE, (string) CURRENT_TIME); $code = SMS::genVerifyCode(); SMS::verifyCode($phone, $code); $this->ajaxReturn(0, ''); }
protected function run($idx) { $nk = Nosql::NK_ASYNC_SMS_QUEUE; $beginTime = time(); do { do { $rawMsg = Nosql::lPop($nk); if ($rawMsg === false || !isset($rawMsg[0])) { break; } $data = json_decode($rawMsg, true); $ret = SMS::firstSend($data['phone'], $data['content']); if ($ret === false) { SMS::secondSend($data['phone'], $data['content']); // 换成不同的运营商 } } while (true); if (time() - $beginTime > 30) { // 30秒脚本重新执行一次 break; } usleep(200000); } while (true); }