AuthController.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace backend\controllers;
  3. use biz\merchant\services\AdminService;
  4. use biz\platform\services\WxOpenService;
  5. use common\components\jwt;
  6. use common\services\xhAdminService;
  7. use common\components\util;
  8. use Yii;
  9. use common\components\stringUtil;
  10. /**
  11. * 登陆验证 shish 2019.11.23
  12. */
  13. class AuthController extends PublicController
  14. {
  15. //登陆并拿到token shish 2019.11.23
  16. public function actionLogin()
  17. {
  18. $get = Yii::$app->request->get();
  19. $mobile = isset($get['mobile']) ? $get['mobile'] : 0;
  20. if (stringUtil::isMobieNumber($mobile) == false) {
  21. util::fail('请填写正常的手机号');
  22. }
  23. $password = isset($get['password']) && !empty($get['password']) ? $get['password'] : '';
  24. if (empty($password)) {
  25. util::fail('请输入密码');
  26. }
  27. $admin = AdminService::getByCondition(['mobile' => $mobile]);
  28. if ($admin['password'] != md5($password)) {
  29. util::fail('密码错误');
  30. }
  31. $adminId = $admin['id'];
  32. //来源
  33. $sourceId = WxOpenService::getSourceId();
  34. //获取token
  35. $token = jwt::get($sourceId, $adminId);
  36. util::success(['token' => $token]);
  37. }
  38. public function actionLogout()
  39. {
  40. xhAdminService::logout();
  41. echo 'ok';
  42. }
  43. }