request->params(['phone']); $sms_num_key = 'api.auth.num.' . $data['phone']; $sms_key = 'api.auth.sms.' . $data['phone']; $num = Cache::get($sms_num_key) ? Cache::get($sms_num_key) : 0; try { $sms_code = str_pad(random_int(1, 9999), 4, 0, STR_PAD_LEFT); $sms_time = systemConfig('sms_time') ? systemConfig('sms_time') : 30 ; (YunxinSmsService::create())->send($data['phone'], 'VERIFICATION_CODE', ['code' => $sms_code,'time' => $sms_time]); } catch (\Exception $e) { return app('json')->fail($e->getMessage()); } Cache::set($sms_key, $sms_code,$sms_time * 60); Cache::set($sms_num_key, $num + 1, 300); //'短信发送成功' return app('json')->success('短信发送成功'); } public function lp(){ echo 'lplplplp'; } public function Auth(UserRepository $repository){ $data = $this->request->params(['phone', 'sms_code', 'source']); $phone_number_pattern = '/^1[3-9]\d{9}$/'; if (! preg_match($phone_number_pattern, $data['phone'])){ return app('json')->make(self::PHONE_ERROR, '用户手机号码有误'); } if ($data['source'] != "yijia"){ throw new AuthException('非法请求'); } $find = Db::name('user')->where("account",$data['phone'])->find(); if ($find){ if ($find['external'] == 3){ return app('json')->make(self::USER_BOUND, '用户关系已绑定'); } return app('json')->make(self::USER_EXIST, '无效绑定。用户已存在'); } $user = $repository->registr($data['phone'],123456,'APP','','用户' . substr($data['phone'], 7, 4),3); if ($user){ return app('json')->success('绑定成功'); } return app('json')->error('绑定失败'); } public function pension(){ $data = $this->request->params(['phone']); [$page, $limit] = $this->getPage(); $pension = Db::name('User') -> where("external",3) ->when(!empty($data['phone']),function($query) use($data){ $query->where('account',$data['phone']); }) -> field('account as phone,annuity as pension')->page($page, $limit)->select(); return app('json')->success($pension); } }