50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
|
|
using Microsoft.AspNetCore.Authorization;
|
|||
|
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
using QYZH.InteractiveMagazine.IService;
|
|||
|
|
using QYZH.InteractiveMagazine.IService.Dto;
|
|||
|
|
using QYZH.InteractiveMagazine.Models.Common;
|
|||
|
|
using QYZH.InteractiveMagazine.Models.Dto;
|
|||
|
|
|
|||
|
|
namespace QYZH.InteractiveMagazine.WebApi.Controllers.WeChat;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 微信小程序认证控制器
|
|||
|
|
/// </summary>
|
|||
|
|
public class WeChatAuthController : WeChatBaseController
|
|||
|
|
{
|
|||
|
|
private readonly IWeChatAuthService _weChatAuthService;
|
|||
|
|
private readonly ILogger<WeChatAuthController> _logger;
|
|||
|
|
|
|||
|
|
public WeChatAuthController(IWeChatAuthService weChatAuthService, ILogger<WeChatAuthController> logger)
|
|||
|
|
{
|
|||
|
|
_weChatAuthService = weChatAuthService;
|
|||
|
|
_logger = logger;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 微信小程序一键登录
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="input">登录输入(含微信 code)</param>
|
|||
|
|
/// <returns>登录结果(含 Token 和用户信息)</returns>
|
|||
|
|
[AllowAnonymous]
|
|||
|
|
[HttpPost("login")]
|
|||
|
|
public async Task<BaseResponse<WeChatLoginOutput>> LoginAsync([FromBody] WeChatLoginInput input)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var result = await _weChatAuthService.LoginAsync(input);
|
|||
|
|
return Success(result);
|
|||
|
|
}
|
|||
|
|
catch (BusinessException ex)
|
|||
|
|
{
|
|||
|
|
_logger.LogWarning(ex, "微信登录业务异常: {Message}", ex.Message);
|
|||
|
|
return BaseResponse<WeChatLoginOutput>.Fail(ex.Message);
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
_logger.LogError(ex, "微信登录系统异常");
|
|||
|
|
return BaseResponse<WeChatLoginOutput>.Fail("微信登录失败,请稍后重试");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|