public function smsLogin() { $phone = $this->getParam('phone', ''); $code = $this->getParam('code', ''); if (Check::isPhone($phone)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '您输入的手机号无效'); return; } if (Check::isVerifyCode($code)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '验证码无效'); return; } $nk = Nosql::NK_REG_SMS_CODE . $phone; $ret = Nosql::get($nk); if (empty($ret) || $ret != $code) { $this->ajaxReturn(ERR_PARAMS_ERROR, '验证码错误,请重新输入'); return; } Nosql::del($nk); $userInfo = UserModel::findUserByPhone($phone); if (empty($userInfo)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '该手机号码未注册,请先注册~'); return; } $this->onLoginOk($userInfo); $this->ajaxReturn(0, '登陆成功', '/TODO'); }
public function send() { $nk = Nosql::NK_ASYNC_EMAIL_QUEUE; $beginTime = time(); do { do { $rawMsg = Nosql::lPop($nk); if ($rawMsg === false || !isset($rawMsg[0])) { break; } $data = json_decode($rawMsg, true); $ret = SendMail::sendmail($data['toList'], $data['title'], $data['desc']); if ($ret === false) { if (isset($data['retry'])) { continue; // drop it } else { $data['retry'] = 1; Nosql::lPush($nk, json_encode($data)); } } } while (true); if (time() - $beginTime > 30) { // 30秒脚本重新执行一次 break; } usleep(200000); } while (true); }
protected function run($idx) { $nk = Nosql::NK_ASYNC_SEND_WX_MSG_QUEUE; $beginTime = time(); do { do { $rawMsg = Nosql::lPop($nk); if ($rawMsg === false || !isset($rawMsg[0])) { break; } $data = json_decode($rawMsg, true); $ret = $this->processMsg($data); if ($ret === false) { if (isset($data['retry'])) { continue; // drop it } else { $data['retry'] = 1; Nosql::lPush($nk, json_encode($data)); } } } while (true); if (time() - $beginTime > 30) { // 30秒脚本重新执行一次 break; } usleep(200000); } while (true); }
public function cancel() { $nk = Nosql::NK_ASYNC_CANCEL_ORDER_QUEUE; $beginTime = time(); do { $now = time(); do { $rawMsg = Nosql::lPop($nk); if ($rawMsg === false || !isset($rawMsg[0])) { break; } $data = json_decode($rawMsg, true); if ($now - $data['ctime'] > (int) $data['duration']) { $this->doCancel($data); } else { Nosql::lPush($nk, $rawMsg); } } while (true); if ($now - $beginTime > 30) { // 30秒脚本重新执行一次 break; } sleep(1); } while (true); }
public function remind() { $nk = Nosql::NK_ASYNC_ORDER_PAY_REMIND_QUEUE; $beginTime = time(); do { $now = time(); do { $rawMsg = Nosql::lPop($nk); if ($rawMsg === false || !isset($rawMsg[0])) { break; } $data = json_decode($rawMsg, true); if ($now - $data['ctime'] > 600) { $this->doRemind($data); } else { Nosql::lPush($nk, $rawMsg); } } while (true); if ($now - $beginTime > 30) { // 30秒脚本重新执行一次 break; } sleep(1); } while (true); }
protected function wxPayReturn() { $orderId = $this->getParam('orderId', ''); if (empty($orderId)) { // ; } // 微信支付,看该用户是否关注过 $nk = Nosql::NK_WX_UNIFIED_PAY_UNSUBSCRIBE . $orderId; $ret = Nosql::get($nk); $this->display('wxpay_return'); }
public function getOrderState() { $token = $this->getParam('token', ''); if (empty($token)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '参数错误'); return; } $ret = Nosql::get($nk); if (empty($ret)) { $this->ajaxReturn(ERR_OPT_FAIL, ''); return; } $ret = json_decode($ret, true); $this->ajaxReturn($ret['code'], $ret['desc'], '', $ret['result']); }
public function register() { $phone = $this->postParam('phone', ''); $code = $this->postParam('code', ''); if (Check::isPhone($phone)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '您输入的手机号无效'); return; } if (Check::isVerifyCode($code)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '验证码无效'); return; } $nk = Nosql::NK_REG_SMS_CODE . $phone; $ret = Nosql::get($nk); if (empty($ret) || $ret != $code) { $this->ajaxReturn(ERR_PARAMS_ERROR, '验证码错误,请重新输入'); return; } Nosql::del($nk); $userInfo = UserModel::findUserByPhone($phone); if (empty($userInfo)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '该手机号码未注册,请先注册~'); return; } $nickname = UserModel::getRandomNickname('wx'); $passwd = ''; $sex = 0; $headimgurl = ''; $ret = UserModel::newOne($phone, $passwd, $nickname, $sex, $headimgurl, UserModel::USER_ST_DEFAULT); if (!$ret) { $this->ajaxReturn(ERR_PARAMS_ERROR, '注册失败-系统出现异常,请稍后重试'); return; } $userInfo = UserModel::findUserByPhone($phone); if (empty($userInfo)) { $this->ajaxReturn(ERR_PARAMS_ERROR, '注册失败-系统出现异常,请稍后重试'); return; } UserModel::onLoginOk($userInfo['id'], ''); // TODO 是不是会自动绑定微信? $this->ajaxReturn(0, '登录成功', '/TODO'); }
protected function run($idx) { $nk = Nosql::NK_ASYNC_WX_EVENT_QUEUE; $beginTime = time(); do { do { $rawMsg = Nosql::lPop($nk); if ($rawMsg === false || !isset($rawMsg[0])) { break; } $data = json_decode($rawMsg, true); $this->processEvent($data); } while (true); if (time() - $beginTime > 30) { // 30秒脚本重新执行一次 break; } usleep(200000); } while (true); }
public function doLogin() { $key = Session::getSid('user'); $userInfo = Nosql::get(Nosql::NK_USER_SESSOIN . $key); if (!empty($userInfo)) { $userAgent = ''; if (isset($_SERVER['HTTP_USER_AGENT'])) { $userAgent = $_SERVER['HTTP_USER_AGENT']; } $userInfo = json_decode($userInfo, true); if ($userInfo['userAgent'] == $userAgent) { if (Util::inWeixin()) { return $this->doLoginInWx($userInfo['openid']); } else { return $this->doLoginDefault($userInfo['userId']); } } return false; } return -1; }
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); }
public function wxPayReturn() { echo 'xxxxx'; $orderId = $this->getParam('orderId', ''); if (empty($orderId)) { // ; } // 微信支付,看该用户是否关注过 $nk = Nosql::NK_WX_UNIFIED_PAY_UNSUBSCRIBE . $orderId; $ret = Nosql::get($nk); }
private function onWxPayOkUnSubscribe($openid, $outTradeNo) { $nk = Nosql::NK_WX_UNIFIED_PAY_UNSUBSCRIBE . $outTradeNo; Nosql::setex($nk, Nosql::NK_WX_UNIFIED_PAY_UNSUBSCRIBE_EXPIRE, 'x'); }