| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace app\api\controller\user;
- use app\api\model\user\User as UserModel;
- use app\api\controller\Controller;
- use app\common\library\easywechat\AppWx;
- /**
- * 用户管理模型
- */
- class User extends Controller
- {
- /**
- * 用户自动登录,默认微信小程序
- */
- public function login()
- {
- $model = new UserModel;
- $user_id = $model->login($this->request->post());
- return $this->renderSuccess('', [
- 'user_id' => $user_id,
- 'token' => $model->getToken()
- ]);
- }
- /**
- * 当前用户详情
- */
- public function detail()
- {
- // 当前用户信息
- $userInfo = $this->getUser();
- return $this->renderSuccess('', compact('userInfo'));
- }
- public function getSession($code)
- {
- // 微信登录 获取session_key
- $app = AppWx::getApp();
- $session_key = AppWx::sessionKey($app, $code)['session_key'];
- return $this->renderSuccess('', compact('session_key'));
- }
- /**
- * 绑定手机号
- */
- public function bindMobile()
- {
- $model = $this->getUser();
- $mobile = $model->bindMobile($this->request->post());
- if ($mobile) {
- return $this->renderSuccess('', compact('mobile'));
- }
- return $this->renderError('绑定失败');
- }
- /**
- * 修改用户信息
- */
- public function updateInfo()
- {
- // 当前用户信息
- $model = $this->getUser();
- if ($model->edit($this->request->post())) {
- return $this->renderSuccess('修改成功');
- }
- return $this->renderError($model->getError() ?: '修改失败');
- }
- }
|