$request['account']])->findOrEmpty(); if ($student->isEmpty()) { throw new Exception('账号不存在'); } if (empty($request['password'])) { throw new Exception('请填写密码'); } if (md5($request['password'] . $student->salt) != $student->password) { throw new Exception('密码错误,请填写正确的密码'); } $token_data = [ 'id' => $student->id, 'role' => 'student' ]; $token = JwtToken::generateToken($token_data); return [ 'code' => ResponseCode::SUCCESS, 'data' => $token, 'msg' => 'success' ]; } catch (Exception $e) { return [ 'code' => ResponseCode::FAIL, 'msg' => $e->getMessage() ]; } } /** * @desc 登录 * @param $request * @return array */ public function userInfo($request) { try { if (empty($request->student)) { throw new Exception('请学生登陆后再查看'); } $student = Student::where(['id' => $request->student->id])->field('id,student_name,account,openid')->findOrEmpty(); if ($student->isEmpty()) { throw new Exception('未找到学生信息'); } return [ 'code' => ResponseCode::SUCCESS, 'data' => $student, 'msg' => 'success' ]; } catch (Exception $e) { return [ 'code' => ResponseCode::FAIL, 'msg' => $e->getMessage() ]; } } /** * @desc 更新code * @param $request * @return array|void * @throws \GuzzleHttp\Exception\GuzzleException */ public function updateOpenid($request) { try { if(empty($request->student)){ throw new Exception('请先教师登陆'); } $teacher = Student::where(['id' => $request->student->id])->findOrEmpty(); if($teacher->isEmpty()){ throw new Exception('未找到教师信息'); } $code = $request->post('code'); print '
'; print_r($code); die; $user_info = WechatSubscriptController::getCodeAccessToken($code); print ''; print_r($user_info); die; if (isset($result['code'])) { throw new Exception('获取信息失败'); } $openid = $user_info['openid']; $student = Student::where(['id'=>$request->student->id])->findOrEmpty(); if($student->openid && $student->openid != $openid){ throw new Exception('当前账号已绑定其它学生,不能重复绑定'); }else{ $student->save([ 'openid' => $openid, ]); } return [ 'code' => ResponseCode::SUCCESS, 'msg' => 'success' ]; }catch (Exception $e){ return [ 'code' => ResponseCode::FAIL, 'msg' => $e->getMessage() ]; } } }