0
0

AuthController.php 845 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace backend\controllers;
  3. use backend\forms\AuthForm;
  4. use yii\helpers\ArrayHelper;
  5. use Yii;
  6. class AuthController extends BaseController
  7. {
  8. /**
  9. * behaviors
  10. * @return array
  11. */
  12. public function behaviors()
  13. {
  14. return ArrayHelper::merge(parent::behaviors(), [
  15. 'verbs' => [
  16. 'class' => \yii\filters\VerbFilter::className(),
  17. 'actions' => [
  18. 'token' => ['POST'],
  19. ],
  20. ],
  21. ]);
  22. }
  23. /**
  24. * 获取accessToken
  25. * @author: libingke
  26. */
  27. public function actionToken()
  28. {
  29. $model = new AuthForm();
  30. $model->setScenario('access_token');
  31. $model->load(['AuthForm' => Yii::$app->request->post()]);
  32. $data = [];
  33. if ($model->validate()) {
  34. $data = $model->getAccessToken();
  35. } else {
  36. $model->handleError();
  37. }
  38. return [
  39. 'code' => 200,
  40. 'message' => Yii::t('error', 200),
  41. 'data' => $data
  42. ];
  43. }
  44. }