hyperf-gateway/app/Controller/PunchCard/Wechat/AuthController.php

41 lines
941 B
PHP

<?php
declare(strict_types=1);
namespace App\Controller\PunchCard\Wechat;
use App\Controller\BaseController;
use App\Exception\BusinessException;
use app\Constants\Wechat\AuthErrorCode;
use App\Service\Wechat\AuthService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
/**
* 微信授权处理控制器
*/
#[Controller(prefix: "kq")]
class AuthController extends BaseController
{
#[Inject]
protected AuthService $service;
/**
* 通过微信授权新建用户
*
* @return array
*/
#[RequestMapping(path: "auth/code2OpenID", methods: "get,post")]
public function code2OpenID() : array
{
$code = $this->request->input('code', '');
if (empty($code)) {
throw new BusinessException(AuthErrorCode::CODE_EMPTY_ERROR);
}
return $this->service->codeToOpenID($code);
}
}